Skip to content

Commit 0887c84

Browse files
author
Peter Rushforth
committed
Save some work from today hopefully without breaking stuff
1 parent 2e8a315 commit 0887c84

File tree

4 files changed

+67
-384
lines changed

4 files changed

+67
-384
lines changed

src/map-feature.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { bounds, point } from 'leaflet';
22

3+
import { featureLayer } from './mapml/layers/FeatureLayer.js';
4+
import { featureRenderer } from './mapml/features/featureRenderer.js';
35
import { Util } from './mapml/utils/Util.js';
46
import proj4 from 'proj4';
57

@@ -180,6 +182,9 @@ export class HTMLFeatureElement extends HTMLElement {
180182
this._parentEl.parentElement?.hasAttribute('data-moving')
181183
)
182184
return;
185+
if (this._parentEl.nodeName === 'MAP-LINK') {
186+
this._createOrGetFeatureLayer();
187+
}
183188
// use observer to monitor the changes in mapFeature's subtree
184189
// (i.e. map-properties, map-featurecaption, map-coordinates)
185190
this._observer = new MutationObserver((mutationList) => {
@@ -266,7 +271,64 @@ export class HTMLFeatureElement extends HTMLElement {
266271
layerToAddTo.addLayer(this._geometry);
267272
this._setUpEvents();
268273
}
274+
isFirst() {
275+
// Get the previous element sibling
276+
const prevSibling = this.previousElementSibling;
277+
278+
// If there's no previous sibling, return true
279+
if (!prevSibling) {
280+
return true;
281+
}
282+
283+
// Compare the node names (tag names) - return true if they're different
284+
return this.nodeName !== prevSibling.nodeName;
285+
}
286+
getPrevious() {
287+
// Check if this is the first tile
288+
if (this.isFirst()) {
289+
return null; // No previous tile available
290+
}
291+
292+
// Since we know it's not the first, we can safely return the previous element sibling
293+
return this.previousElementSibling;
294+
}
295+
_createOrGetFeatureLayer() {
296+
if (this.isFirst() && this._parentEl._templatedLayer) {
297+
const parentElement = this._parentEl;
298+
299+
let map = parentElement.getMapEl()._map;
269300

301+
// Create a new FeatureLayer
302+
this._featureLayer = featureLayer(null, {
303+
// pass the vector layer a renderer of its own, otherwise leaflet
304+
// puts everything into the overlayPane
305+
renderer: featureRenderer(),
306+
// pass the vector layer the container for the parent into which
307+
// it will append its own container for rendering into
308+
pane: parentElement._templatedLayer.getContainer(),
309+
// the bounds will be static, fixed, constant for the lifetime of the layer
310+
layerBounds: parentElement.getBounds(),
311+
zoomBounds: this._getZoomBounds(),
312+
projection: map.options.projection,
313+
mapEl: parentElement.getMapEl()
314+
});
315+
this.addFeature(this._featureLayer);
316+
317+
// add featureLayer to TemplatedFeaturesOrTilesLayerGroup of the parentElement
318+
if (
319+
parentElement._templatedLayer &&
320+
parentElement._templatedLayer.addLayer
321+
) {
322+
parentElement._templatedLayer.addLayer(this._featureLayer);
323+
}
324+
} else {
325+
// get the previous feature's layer
326+
this._featureLayer = this.getPrevious()?._featureLayer;
327+
if (this._featureLayer) {
328+
this.addFeature(this._featureLayer);
329+
}
330+
}
331+
}
270332
_setUpEvents() {
271333
['click', 'focus', 'blur', 'keyup', 'keydown'].forEach((name) => {
272334
// when <g> is clicked / focused / blurred

src/map-link.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { Util } from './mapml/utils/Util.js';
1111
import { templatedImageLayer } from './mapml/layers/TemplatedImageLayer.js';
1212
import { templatedTileLayer } from './mapml/layers/TemplatedTileLayer.js';
13-
import { templatedFeaturesLayer } from './mapml/layers/TemplatedFeaturesLayer.js';
1413
import { templatedPMTilesLayer } from './mapml/layers/TemplatedPMTilesLayer.js';
1514
import { templatedFeaturesOrTilesLayerGroup } from './mapml/layers/TemplatedFeaturesOrTilesLayerGroup.js';
1615
/* global M */
@@ -437,7 +436,8 @@ export class HTMLLinkElement extends HTMLElement {
437436
// be loaded as part of a templated layer processing i.e. on moveend
438437
// and the generated <link> that implements this <map-link> should be located
439438
// in the parent <map-link>._templatedLayer.container root node if
440-
// the _templatedLayer is an instance of TemplatedTileLayer or TemplatedFeaturesLayer
439+
// the _templatedLayer is an instance of TemplatedTileLayer or
440+
// TemplatedFeaturesOrTilesLayerGroup
441441
//
442442
// if the parent node (or the host of the shadow root parent node) is map-layer, the link should be created in the _layer
443443
// container

0 commit comments

Comments
 (0)