@@ -108,7 +108,8 @@ export var MapMLLayer = L.Layer.extend({
108108 opacity : extentEl . _templateVars . opacity ,
109109 _leafletLayer : this ,
110110 crs : extentEl . crs ,
111- extentZIndex : extentEl . extentZIndex
111+ extentZIndex : extentEl . extentZIndex ,
112+ extentEl : extentEl . _DOMnode || extentEl
112113 } ) . addTo ( this . _map ) ;
113114 extentEl . templatedLayer . setZIndex ( ) ;
114115 this . _setLayerElExtent ( ) ;
@@ -147,14 +148,6 @@ export var MapMLLayer = L.Layer.extend({
147148 var c = document . createElement ( 'div' ) ;
148149 c . classList . add ( "mapml-popup-content" ) ;
149150 c . insertAdjacentHTML ( 'afterbegin' , properties . innerHTML ) ;
150- c . insertAdjacentHTML ( 'beforeend' , `<a href="" class="zoomLink">${ M . options . locale . popupZoom } </a>` ) ;
151- let zoomLink = c . querySelector ( 'a.zoomLink' ) ;
152- zoomLink . onclick = zoomLink . onkeydown = function ( e ) {
153- if ( ! ( e instanceof MouseEvent ) && e . keyCode !== 13 ) return ;
154- e . preventDefault ( ) ;
155- let mapmlFeature = geometry . _featureEl ? geometry . _featureEl : geometry . _groupLayer . _featureEl ;
156- mapmlFeature . zoomTo ( ) ;
157- } ;
158151 geometry . bindPopup ( c , { autoClose : false , minWidth : 165 } ) ;
159152 }
160153 }
@@ -187,14 +180,6 @@ export var MapMLLayer = L.Layer.extend({
187180 var c = document . createElement ( 'div' ) ;
188181 c . classList . add ( "mapml-popup-content" ) ;
189182 c . insertAdjacentHTML ( 'afterbegin' , properties . innerHTML ) ;
190- c . insertAdjacentHTML ( 'beforeend' , `<a href="" class="zoomLink">${ M . options . locale . popupZoom } </a>` ) ;
191- let zoomLink = c . querySelector ( 'a.zoomLink' ) ;
192- zoomLink . onclick = zoomLink . onkeydown = function ( e ) {
193- if ( ! ( e instanceof MouseEvent ) && e . keyCode !== 13 ) return ;
194- e . preventDefault ( ) ;
195- let mapmlFeature = geometry . _featureEl ? geometry . _featureEl : geometry . _groupLayer . _featureEl ;
196- mapmlFeature . zoomTo ( ) ;
197- } ;
198183 geometry . bindPopup ( c , { autoClose : false , minWidth : 165 } ) ;
199184 }
200185 } ,
@@ -261,6 +246,9 @@ export var MapMLLayer = L.Layer.extend({
261246 _leafletLayer : this ,
262247 crs : this . _extent . crs ,
263248 extentZIndex : this . _extent . _mapExtents [ i ] . extentZIndex ,
249+ // when a <map-extent> migrates from a remote mapml file and attaches to the shadow of <layer- >
250+ // this._extent._mapExtents[i] refers to the <map-extent> in remote mapml
251+ extentEl : this . _extent . _mapExtents [ i ] . _DOMnode || this . _extent . _mapExtents [ i ] ,
264252 } ) . addTo ( map ) ;
265253 this . _extent . _mapExtents [ i ] . templatedLayer = this . _templatedLayer ;
266254 if ( this . _templatedLayer . _queries ) {
@@ -278,7 +266,6 @@ export var MapMLLayer = L.Layer.extend({
278266 }
279267 } ,
280268
281-
282269 _validProjection : function ( map ) {
283270 let noLayer = false ;
284271 if ( this . _extent && this . _extent . _mapExtents ) {
@@ -1324,8 +1311,12 @@ export var MapMLLayer = L.Layer.extend({
13241311 if ( popup . _source . _eventParents ) { // check if the popup is for a feature or query
13251312 layer = popup . _source . _eventParents [ Object . keys ( popup . _source . _eventParents ) [ 0 ] ] ; // get first parent of feature, there should only be one
13261313 group = popup . _source . group ;
1314+ // if the popup is for a static / templated feature, the "zoom to here" link can be attached once the popup opens
1315+ attachZoomLink . call ( popup ) ;
13271316 } else {
13281317 layer = popup . _source . _templatedLayer ;
1318+ // if the popup is for a query, the "zoom to here" link should be re-attached every time new pagination features are displayed
1319+ map . on ( "attachZoomLink" , attachZoomLink , popup ) ;
13291320 }
13301321
13311322 if ( popup . _container . querySelector ( 'nav[class="mapml-focus-buttons"]' ) ) {
@@ -1381,7 +1372,7 @@ export var MapMLLayer = L.Layer.extend({
13811372 map . _controlContainer . querySelector ( "A:not([hidden])" ) . focus ( ) ;
13821373 } , popup ) ;
13831374
1384- let divider = L . DomUtil . create ( "hr" ) ;
1375+ let divider = L . DomUtil . create ( "hr" , "mapml-popup-divider" ) ;
13851376
13861377 popup . _navigationBar = div ;
13871378 popup . _content . appendChild ( divider ) ;
@@ -1452,12 +1443,36 @@ export var MapMLLayer = L.Layer.extend({
14521443 }
14531444 }
14541445
1446+ function attachZoomLink ( e ) {
1447+ // this === popup
1448+ let content = this . _content ,
1449+ featureEl = e ? e . currFeature : this . _source . _groupLayer . _featureEl ;
1450+ if ( content . querySelector ( 'a.mapml-zoom-link' ) ) {
1451+ content . querySelector ( 'a.mapml-zoom-link' ) . remove ( ) ;
1452+ }
1453+ if ( ! featureEl . querySelector ( 'map-geometry' ) ) return ;
1454+ let tL = featureEl . extent . topLeft . gcrs ,
1455+ bR = featureEl . extent . bottomRight . gcrs ,
1456+ center = L . latLngBounds ( L . latLng ( tL . horizontal , tL . vertical ) , L . latLng ( bR . horizontal , bR . vertical ) ) . getCenter ( true ) ;
1457+ let zoomLink = document . createElement ( 'a' ) ;
1458+ zoomLink . href = `#${ featureEl . getMaxZoom ( ) } ,${ center . lng } ,${ center . lat } ` ;
1459+ zoomLink . innerHTML = `${ M . options . locale . popupZoom } ` ;
1460+ zoomLink . className = "mapml-zoom-link" ;
1461+ zoomLink . onclick = zoomLink . onkeydown = function ( e ) {
1462+ if ( ! ( e instanceof MouseEvent ) && e . keyCode !== 13 ) return ;
1463+ e . preventDefault ( ) ;
1464+ featureEl . zoomTo ( ) ;
1465+ } ;
1466+ content . insertBefore ( zoomLink , content . querySelector ( 'hr.mapml-popup-divider' ) ) ;
1467+ }
1468+
14551469 // if popup closes then the focusFeature handler can be removed
14561470 map . on ( "popupclose" , removeHandlers ) ;
14571471 function removeHandlers ( removeEvent ) {
14581472 if ( removeEvent . popup === popup ) {
14591473 map . off ( "keydown" , focusFeature ) ;
14601474 map . off ( "keydown" , focusMap ) ;
1475+ map . off ( "popupopen" , attachZoomLink ) ;
14611476 map . off ( 'popupclose' , removeHandlers ) ;
14621477 if ( group ) group . setAttribute ( "aria-expanded" , "false" ) ;
14631478 }
0 commit comments