Skip to content

Commit

Permalink
Remove 'meta' option for showPaginationFeature. Add meta array property
Browse files Browse the repository at this point in the history
to each feature that is returned by a query.  The meta array points
to an array of <map-meta> elements that were retrieved from the query
response document.  These are appended to the <map-link> shadow root
for each pagination feature, which might be a bit inefficient but will
not fail, I hope.
  • Loading branch information
prushforth committed Apr 25, 2024
1 parent 546ecc6 commit fc072e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
14 changes: 11 additions & 3 deletions src/mapml/handlers/QueryHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export var QueryHandler = L.Handler.extend({
})
.then((response) => {
let features = [];
let queryMetas = [];
let geom =
"<map-geometry cs='gcrs'><map-point><map-coordinates>" +
e.latlng.lng +
Expand Down Expand Up @@ -129,11 +130,13 @@ export var QueryHandler = L.Handler.extend({
mapmldoc.querySelectorAll('map-feature')
);
// <map-meta> elements for this query
layer.queryMetas = Array.prototype.slice.call(
queryMetas = Array.prototype.slice.call(
mapmldoc.querySelectorAll(
'map-meta[name=cs], map-meta[name=zoom], map-meta[name=projection]'
)
);
if (queryMetas.length)
features.forEach((f) => (f.meta = queryMetas));
} else {
try {
let featureDocument = parser.parseFromString(
Expand All @@ -149,10 +152,16 @@ export var QueryHandler = L.Handler.extend({
throw new Error('parsererror');
}
let g = parser.parseFromString(geom, 'application/xml');
queryMetas = Array.prototype.slice.call(
featureDocument.querySelectorAll(
'map-meta[name=cs], map-meta[name=zoom], map-meta[name=projection]'
)
);
for (let feature of featureCollection) {
if (!feature.querySelector('map-geometry')) {
feature.appendChild(g.firstElementChild.cloneNode(true));
}
feature.meta = queryMetas;
features.push(feature);
}
} catch (err) {
Expand Down Expand Up @@ -339,8 +348,7 @@ export var QueryHandler = L.Handler.extend({
});
f.showPaginationFeature({
i: 0,
popup: layer._popup,
meta: layer.queryMetas
popup: layer._popup
});
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/mapml/layers/ExtentLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export var ExtentLayer = L.LayerGroup.extend({
this._count--;
this._map.fire('featurepagination', {
i: this._count,
popup: this,
meta: this._source.queryMetas
popup: this
});
}
},
Expand All @@ -72,8 +71,7 @@ export var ExtentLayer = L.LayerGroup.extend({
this._count++;
this._map.fire('featurepagination', {
i: this._count,
popup: this,
meta: this._source.queryMetas
popup: this
});
}
},
Expand Down
15 changes: 4 additions & 11 deletions src/mapml/layers/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,12 @@ export var FeatureLayer = L.FeatureGroup.extend({
showPaginationFeature: function (e) {
if (this.options.query && this._queryFeatures[e.i]) {
let feature = this._queryFeatures[e.i];
if (e.type === 'featurepagination') {
// remove map-feature only (keep meta's) when paginating
feature._linkEl.shadowRoot.querySelector('map-feature')?.remove();
} else {
// empty the map-extent shadowRoot
// remove the prev / next one <map-feature> and <map-meta>'s from shadow if there is any
feature._linkEl.shadowRoot.replaceChildren();
}
feature._linkEl.shadowRoot.replaceChildren();
this.clearLayers();
// append all map-meta from mapml document
if (e.meta) {
for (let i = 0; i < e.meta.length; i++) {
feature._linkEl.shadowRoot.appendChild(e.meta[i]);
if (feature.meta) {
for (let i = 0; i < feature.meta.length; i++) {
feature._linkEl.shadowRoot.appendChild(feature.meta[i]);
}
}
feature._linkEl.shadowRoot.appendChild(feature);
Expand Down

0 comments on commit fc072e2

Please sign in to comment.