import * as L from 'leaflet' ; import { UtfGrid } from './utf-grid' ; const CLASSES = 'leaflet-mouseover-tooltip' ; /**
 * Mouse overlay layer group for leaflet map
 */ const MouseOverLayer = L . LayerGroup . extend ( { _initialized : false , dataUrl : null , tileUrl : null , param options { Object } initialize : function ( options ) { this . _tileLayer = new L . TileLayer ( options . tileUrl , options . tileOpts ) ; this . _dataLayer = new UtfGrid ( options . dataUrl , options . dataOpts ) ; this . _legend = options . legend || null ; if ( typeof options . tiptext === 'string' ) { this . _tiptext = options . tiptext ; this . _tooltip = L . DomUtil . create ( 'span' , CLASSES ) ; } L . LayerGroup . prototype . initialize . call ( this , [ ] ) ; this . addLayer ( this . _tileLayer ) ; if ( ! this . isMobile ( ) ) { this . addLayer ( this . _dataLayer ) ; } this . _initialized = true ; } , getLegends : function ( ) { return this . _legend ; } , isMobile : function ( ) : boolean { if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i . test ( navigator . userAgent ) ) { return true ; } return false ; } , onAdd : function ( map ) { L . LayerGroup . prototype . onAdd . apply ( this , arguments ) ; if ( this . _tooltip ) { map . getPanes ( ) . popupPane . appendChild ( this . _tooltip ) ; this . _dataLayer . on ( 'mouseover' , this . _onMouseOver , this ) ; this . _dataLayer . on ( 'mouseout' , this . _onMouseOut , this ) ; } } , onRemove : function ( ) { L . LayerGroup . prototype . onRemove . apply ( this , arguments ) ; if ( this . _tooltip && this . _tooltip . parentNode ) { this . _tooltip . parentNode . removeChild ( this . _tooltip ) ; this . _dataLayer . off ( 'mouseover' , this . _onMouseOver , this ) ; this . _dataLayer . off ( 'mouseout' , this . _onMouseOut , this ) ; } } , _onMouseOver : function ( evt ) { this . _tooltip . innerHTML = L . Util . template ( this . _tiptext , evt . data ) ; L . DomUtil . setPosition ( this . _tooltip , this . _map . latLngToLayerPoint ( evt . latlng ) ) ; this . _tooltip . style . display = 'block' ; } , _onMouseOut : function ( ) { this . _tooltip . style . display = '' ; } } ) ; export { MouseOverLayer } ;