11// External imports
22import { fromLonLat } from "ol/proj" ;
3+ import { boundingExtent } from 'ol/extent' ;
34
45// Internal imports
56import { isRestStopClosed } from '../../data/restStops.js' ;
@@ -188,7 +189,7 @@ export const resetClickedStates = (
188189 updateClickedFeature ( null ) ;
189190 break ;
190191 }
191- if ( isCamDetail && targetFeature && targetFeature . get ( 'type' ) === 'camera' ) {
192+ if ( isCamDetail && targetFeature ? .get ( 'type' ) === 'camera' ) {
192193 if ( highlighted_camera_list . length > 0 ) {
193194 highlighted_camera_list [ 0 ] . setCameraStyle ( 'static' ) ;
194195 highlighted_camera_list [ 0 ] . set ( 'clicked' , false ) ;
@@ -232,8 +233,7 @@ const camClickHandler = (
232233 updateReferenceFeature ,
233234 mapContext
234235) => {
235- if ( ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' )
236- || ( clickedFeatureRef . current && ( clickedFeatureRef . current . values_ . type != feature . values_ . type ) ) ) {
236+ if ( clickedFeatureRef . current ?. values_ ?. type === 'camera' || clickedFeatureRef . current ?. values_ ?. type !== feature . values_ ?. type ) {
237237 resetClickedStates (
238238 feature ,
239239 clickedFeatureRef ,
@@ -257,6 +257,7 @@ const camClickHandler = (
257257 feature . setCameraStyle ( 'active' ) ;
258258 feature . set ( 'clicked' , true , true ) ;
259259 feature . set ( 'unread' , false ) ;
260+ feature . set ( 'hovered' , false ) ;
260261
261262 if ( isCamDetail ) {
262263 // Do not auto center on feature on cam details page
@@ -295,7 +296,7 @@ export const eventClickHandler = (
295296 isCamDetail ,
296297) => {
297298 // reset previous clicked feature
298- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
299+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
299300 resetClickedStates (
300301 feature ,
301302 clickedFeatureRef ,
@@ -330,7 +331,7 @@ export const ferryClickHandler = (
330331 isCamDetail ,
331332) => {
332333 // reset previous clicked feature
333- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
334+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
334335 resetClickedStates (
335336 feature ,
336337 clickedFeatureRef ,
@@ -356,7 +357,7 @@ const weatherClickHandler = (
356357 updateClickedFeature ,
357358 isCamDetail ,
358359) => {
359- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
360+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
360361 // reset previous clicked feature
361362 resetClickedStates (
362363 feature ,
@@ -382,7 +383,7 @@ const regionalClickHandler = (
382383 updateClickedFeature ,
383384 isCamDetail ,
384385) => {
385- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
386+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
386387 // reset previous clicked feature
387388 resetClickedStates (
388389 feature ,
@@ -411,7 +412,7 @@ const hefClickHandler = (
411412 isCamDetail ,
412413) => {
413414 // reset previous clicked feature
414- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
415+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
415416 resetClickedStates (
416417 feature ,
417418 clickedFeatureRef ,
@@ -438,7 +439,7 @@ const restStopClickHandler = (
438439 isCamDetail ,
439440) => {
440441 // reset previous clicked feature
441- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
442+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
442443 resetClickedStates (
443444 feature ,
444445 clickedFeatureRef ,
@@ -477,7 +478,7 @@ const routeClickHandler = (
477478 updateClickedFeature ,
478479) => {
479480 // reset previous clicked feature
480- if ( ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
481+ if ( clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
481482 resetClickedStates (
482483 feature ,
483484 clickedFeatureRef ,
@@ -501,7 +502,7 @@ const borderCrossingClickHandler = (
501502 isCamDetail ,
502503) => {
503504 // reset previous clicked feature
504- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
505+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
505506 resetClickedStates (
506507 feature ,
507508 clickedFeatureRef ,
@@ -543,7 +544,7 @@ export const wildfireClickHandler = (
543544 isCamDetail ,
544545) => {
545546 // reset previous clicked feature
546- if ( ! isCamDetail || ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
547+ if ( ! isCamDetail || clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
547548 resetClickedStates (
548549 feature ,
549550 clickedFeatureRef ,
@@ -580,8 +581,36 @@ export const pointerClickHandler = (
580581 mapContext
581582) => {
582583 if ( features . length ) {
583- const clickedFeature = features [ 0 ] ;
584- switch ( clickedFeature . getProperties ( ) [ 'type' ] ) {
584+ let clickedFeature = features [ 0 ] ;
585+
586+ const clusterFeatures = clickedFeature . get ( 'features' ) ;
587+
588+ if ( clusterFeatures ) {
589+ if ( clusterFeatures . length > 1 ) {
590+ clusterFeatures . forEach ( feature => {
591+ feature . set ( 'hovered' , false ) ;
592+ feature . set ( 'clicked' , false ) ;
593+ feature . setCameraStyle ( 'static' ) ;
594+ } ) ;
595+
596+ mapView . current . animate ( {
597+ center : clickedFeature . getGeometry ( ) . getCoordinates ( ) ,
598+ zoom : mapView . current . getZoom ( ) + 1 ,
599+ duration : 300 ,
600+ } ) ;
601+
602+ return ;
603+ }
604+
605+ clickedFeature = clusterFeatures [ 0 ] ;
606+ }
607+
608+ if ( ! clickedFeature . get ( 'type' ) ) {
609+ clickedFeature = features [ 0 ] . values_ ?. features [ 0 ] ;
610+ }
611+
612+
613+ switch ( clickedFeature ?. getProperties ( ) [ 'type' ] ) {
585614 case 'camera' :
586615 trackEvent (
587616 'click' ,
@@ -793,7 +822,7 @@ export const dmsClickHandler = (
793822 isCamDetail ,
794823) => {
795824 // reset previous clicked feature
796- if ( ! ( clickedFeatureRef . current && clickedFeatureRef . current . values_ . type == 'camera' ) ) {
825+ if ( clickedFeatureRef . current ?. values_ ? .type ! == 'camera' ) {
797826 resetClickedStates (
798827 feature ,
799828 clickedFeatureRef ,
0 commit comments