|
1 | 1 | import { bounds, point } from 'leaflet';
|
2 | 2 |
|
| 3 | +import { featureLayer } from './mapml/layers/FeatureLayer.js'; |
| 4 | +import { featureRenderer } from './mapml/features/featureRenderer.js'; |
3 | 5 | import { Util } from './mapml/utils/Util.js';
|
4 | 6 | import proj4 from 'proj4';
|
5 | 7 |
|
@@ -180,6 +182,9 @@ export class HTMLFeatureElement extends HTMLElement {
|
180 | 182 | this._parentEl.parentElement?.hasAttribute('data-moving')
|
181 | 183 | )
|
182 | 184 | return;
|
| 185 | + if (this._parentEl.nodeName === 'MAP-LINK') { |
| 186 | + this._createOrGetFeatureLayer(); |
| 187 | + } |
183 | 188 | // use observer to monitor the changes in mapFeature's subtree
|
184 | 189 | // (i.e. map-properties, map-featurecaption, map-coordinates)
|
185 | 190 | this._observer = new MutationObserver((mutationList) => {
|
@@ -266,7 +271,64 @@ export class HTMLFeatureElement extends HTMLElement {
|
266 | 271 | layerToAddTo.addLayer(this._geometry);
|
267 | 272 | this._setUpEvents();
|
268 | 273 | }
|
| 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; |
269 | 300 |
|
| 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 | + } |
270 | 332 | _setUpEvents() {
|
271 | 333 | ['click', 'focus', 'blur', 'keyup', 'keydown'].forEach((name) => {
|
272 | 334 | // when <g> is clicked / focused / blurred
|
|
0 commit comments