@@ -41,9 +41,10 @@ import { debounce, isEmpty } from "@utils";
4141import settings from "@settings" ;
4242import ZoomTooltip from "./zoomTooltip" ;
4343import {
44- DEFAULT_MIN_ZOOM ,
45- DEFAULT_MAX_ZOOM ,
46- } from "@components/common/CONSTANTS" ;
44+ DEFAULT_MIN_ZOOM ,
45+ DEFAULT_MAX_ZOOM ,
46+ } from '@components/common/CONSTANTS' ;
47+ import centroid from "@turf/centroid" ;
4748
4849const styles = ( theme ) => ( {
4950 root : {
@@ -166,13 +167,16 @@ class Map extends React.Component {
166167 "bottom-right"
167168 ) ;
168169
169- map . on ( "click" , this . debouncedOnClick ) ;
170- map . on ( "mouseenter" , "request-circles" , this . onMouseEnter ) ;
171- map . on ( "mouseleave" , "request-circles" , this . onMouseLeave ) ;
170+ map . on ( 'click' , this . debouncedOnClick ) ;
171+ map . on ( 'mouseenter' , 'request-circles' , this . onMouseEnter ) ;
172+ map . on ( 'mouseleave' , 'request-circles' , this . onMouseLeave ) ;
173+ map . on ( 'mouseenter' , 'nc-fills' , this . handleNcMouseEnter ) ;
174+ map . on ( 'mousemove' , 'nc-fills' , this . handleNcMouseEnter ) ;
175+ map . on ( 'mouseleave' , 'nc-fills' , this . handleNcMouseLeave ) ;
172176
173- map . once ( " idle" , ( e ) => {
174- this . setState ( { mapReady : true } ) ;
175- } ) ;
177+ map . once ( ' idle' , ( e ) => {
178+ this . setState ( { mapReady : true } ) ;
179+ } ) ;
176180
177181 // Check to see if councilId is present and updates the state
178182 const {
@@ -414,12 +418,17 @@ class Map extends React.Component {
414418 } ) ;
415419 } ;
416420
421+ //Service Request Details Popup
417422 addPopup = ( coordinates , requestId ) => {
418423 this . setState ( { selectedRequestId : requestId } ) ;
419424 this . popup = new mapboxgl . Popup ( { closeButton : false , anchor : "left" } )
420425 . setLngLat ( coordinates )
421426 . setDOMContent ( this . requestDetail )
422427 . addTo ( this . map ) ;
428+
429+ if ( this . popup . getElement ( ) ) {
430+ this . popup . getElement ( ) . style . zIndex = '2' ;
431+ }
423432 } ;
424433
425434 removePopup = ( ) => {
@@ -757,6 +766,50 @@ class Map extends React.Component {
757766 }
758767 } ;
759768
769+ handleNcMouseEnter = ( e ) => {
770+ if ( this . ncPopup ) this . ncPopup . remove ( ) ;
771+ if ( ! e . features ?. length ) return ;
772+
773+ const feature = e . features [ 0 ] ;
774+ const ncName = feature . properties . NAME ;
775+ const NC_ZOOM_LEVEL = 11 ;
776+ const coordinates = centroid ( feature ) . geometry . coordinates ;
777+
778+ const { selectedNc } = this . state ;
779+ const zoom = this . map . getZoom ( ) ;
780+
781+ const isZoomedIn = zoom >= NC_ZOOM_LEVEL ;
782+ const isSameNc = selectedNc && ncName == selectedNc ?. TOOLTIP ;
783+
784+ //Removes popup when zoomed in on a selected NC
785+ if ( isZoomedIn && isSameNc ) {
786+ if ( this . ncPopup ) {
787+ this . ncPopup . remove ( ) ;
788+ this . ncPopup = null ;
789+ }
790+ this . currentNc = null ;
791+ return ;
792+ }
793+
794+ //NC Name Tooltip Popup
795+ this . ncPopup = new mapboxgl . Popup ( {
796+ closeButton : false ,
797+ closeOnClick : false ,
798+ } )
799+ . setLngLat ( coordinates )
800+ . setHTML ( `<div>${ ncName } </div>` )
801+ . addTo ( this . map ) ;
802+
803+ if ( this . ncPopup . getElement ( ) ) {
804+ this . ncPopup . getElement ( ) . style . zIndex = '1' ;
805+ }
806+
807+ } ;
808+
809+ handleNcMouseLeave = ( ) => {
810+ if ( this . ncPopup ) this . ncPopup . remove ( ) ;
811+ } ;
812+
760813 //// RENDER ////
761814
762815 render ( ) {
0 commit comments