Skip to content

Commit 4307b43

Browse files
committed
Change _convertAndFormatPCRS 'map' parameter to 'crs', since 'map'
often depends on the context environment being added to and having a _map property, which may not be the case. Uncomment playwright tests, need to see what's breaking without much bandwidth here to run tests Remove playwright retries, temporarily. Revert moveend->map-movend change from 9e06492 Changes so we can all look at what's going on with mapFeature.test.js Change expectation of DOM ordering of rendered <g> elements - should move away from DOM order dependency in test entirely TBD. Comment out continuous testing for now
1 parent cc4d5d7 commit 4307b43

File tree

11 files changed

+42
-39
lines changed

11 files changed

+42
-39
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
}
3333
],
3434
"scripts": {
35-
"test": "npx playwright test --retries=3",
35+
"test": "npx playwright test",
3636
"jest": "jest --verbose --noStackTrace"
3737
},
3838
"devDependencies": {

src/map-feature.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ export class MapFeature extends HTMLElement {
383383
projection
384384
);
385385
}
386-
let result = M._convertAndFormatPCRS(pcrsBound, map);
386+
let result = Object.assign(
387+
M._convertAndFormatPCRS(pcrsBound, map.options.crs),
388+
{ projection: map.options.projection }
389+
);
387390
// memoize calculated result
388391
extentCache = result;
389392
return result;

src/mapml-viewer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ export class MapViewer extends HTMLElement {
109109
map.getZoom(),
110110
map.options.projection
111111
);
112-
let formattedExtent = M._convertAndFormatPCRS(pcrsBounds, map);
112+
let formattedExtent = M._convertAndFormatPCRS(pcrsBounds, map.options.crs);
113113
if (map.getMaxZoom() !== Infinity) {
114114
formattedExtent.zoom = {
115115
minZoom: map.getMinZoom(),
116116
maxZoom: map.getMaxZoom()
117117
};
118118
}
119+
formattedExtent.projection = this.projection;
119120
return formattedExtent;
120121
}
121122
get static() {

src/mapml/features/path.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ export var Path = L.Path.extend({
7575
nextLayer = this.options._leafletLayer._layerEl.nextElementSibling;
7676
while (nextLayer && onTop) {
7777
if (nextLayer.tagName && nextLayer.tagName.toUpperCase() === 'LAYER-')
78-
onTop = !(nextLayer.checked && nextLayer._layer.queryable);
78+
onTop = !(
79+
nextLayer.checked &&
80+
nextLayer._layer &&
81+
nextLayer._layer.queryable
82+
);
7983
nextLayer = nextLayer.nextElementSibling;
8084
}
8185
if (onTop && dragStart) {
82-
//M._handleLink gets called twice, once in the target phase on the path element, then in the bubble phase on the g element
86+
//M._handleLink gets called twice, once in the target phase on the path
87+
//element, then in the bubble phase on the g element
8388
//Using stopPropagation leaves the mouse in the mousedown state
8489
if (e.eventPhase === Event.BUBBLING_PHASE) return;
8590
let dist = Math.sqrt(

src/mapml/handlers/AnnounceMovement.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export var AnnounceMovement = L.Handler.extend({
55
layerremove: this.totalBounds
66
});
77

8-
this._map.on('moveend', this.announceBounds, this._map.options.mapEl);
8+
this._map.on('map-moveend', this.announceBounds);
99
this._map.dragging._draggable.addEventListener('dragstart', this.dragged);
1010
this._map.options.mapEl.addEventListener(
1111
'mapfocused',
@@ -18,7 +18,7 @@ export var AnnounceMovement = L.Handler.extend({
1818
layerremove: this.totalBounds
1919
});
2020

21-
this._map.off('moveend', this.announceBounds, this._map.options.mapEl);
21+
this._map.off('map-moveend', this.announceBounds);
2222
this._map.dragging._draggable.removeEventListener(
2323
'dragstart',
2424
this.dragged

src/mapml/handlers/QueryHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export var QueryHandler = L.Handler.extend({
1616
// work backwards in document order (top down)
1717
for (var l = layers.length - 1; l >= 0; l--) {
1818
var mapmlLayer = layers[l]._layer;
19-
if (layers[l].checked && mapmlLayer.queryable) {
19+
if (layers[l].checked && mapmlLayer && mapmlLayer.queryable) {
2020
return mapmlLayer;
2121
}
2222
}
@@ -253,7 +253,7 @@ export var QueryHandler = L.Handler.extend({
253253
}
254254
function displayFeaturesPopup(features, loc) {
255255
if (features.length === 0) return;
256-
let f = M.featureLayer(null, {
256+
let f = M.featureLayer(features, {
257257
// pass the vector layer a renderer of its own, otherwise leaflet
258258
// puts everything into the overlayPane
259259
renderer: M.featureRenderer(),

src/mapml/layers/MapMLLayer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ export var MapMLLayer = L.Layer.extend({
395395
if (bounds) {
396396
//assigns the formatted extent object to .extent and spreads the zoom ranges to .extent also
397397
this._layerEl.extent = Object.assign(
398-
M._convertAndFormatPCRS(bounds, this._map),
398+
M._convertAndFormatPCRS(bounds, this._properties.crs),
399399
{ zoom: zoomBounds }
400400
);
401401
}

src/mapml/utils/Util.js

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,19 @@ import { FALLBACK_CS, FALLBACK_PROJECTION } from './Constants';
33
export var Util = {
44
// _convertAndFormatPCRS returns the converted CRS and formatted pcrsBounds in gcrs, pcrs, tcrs, and tilematrix. Used for setting extent for the map and layer (map.extent, layer.extent).
55
// _convertAndFormatPCRS: L.Bounds, _map -> {...}
6-
_convertAndFormatPCRS: function (pcrsBounds, map) {
7-
if (!pcrsBounds || !map) return {};
6+
_convertAndFormatPCRS: function (pcrsBounds, crs) {
7+
if (!pcrsBounds || !crs) return {};
88

99
let tcrsTopLeft = [],
1010
tcrsBottomRight = [],
1111
tileMatrixTopLeft = [],
1212
tileMatrixBottomRight = [],
13-
tileSize = map.options.crs.options.crs.tile.bounds.max.y;
13+
tileSize = crs.options.crs.tile.bounds.max.y;
1414

15-
for (let i = 0; i < map.options.crs.options.resolutions.length; i++) {
16-
let scale = map.options.crs.scale(i),
17-
minConverted = map.options.crs.transformation.transform(
18-
pcrsBounds.min,
19-
scale
20-
),
21-
maxConverted = map.options.crs.transformation.transform(
22-
pcrsBounds.max,
23-
scale
24-
);
15+
for (let i = 0; i < crs.options.resolutions.length; i++) {
16+
let scale = crs.scale(i),
17+
minConverted = crs.transformation.transform(pcrsBounds.min, scale),
18+
maxConverted = crs.transformation.transform(pcrsBounds.max, scale);
2519

2620
tcrsTopLeft.push({
2721
horizontal: minConverted.x,
@@ -44,8 +38,8 @@ export var Util = {
4438
}
4539

4640
//converts the gcrs, I believe it can take any number values from -inf to +inf
47-
let unprojectedMin = map.options.crs.unproject(pcrsBounds.min),
48-
unprojectedMax = map.options.crs.unproject(pcrsBounds.max);
41+
let unprojectedMin = crs.unproject(pcrsBounds.min),
42+
unprojectedMax = crs.unproject(pcrsBounds.max);
4943

5044
let gcrs = {
5145
topLeft: {
@@ -83,8 +77,7 @@ export var Util = {
8377
tilematrix: tileMatrixBottomRight,
8478
gcrs: gcrs.bottomRight,
8579
pcrs: pcrs.bottomRight
86-
},
87-
projection: map.options.projection
80+
}
8881
};
8982
},
9083

@@ -533,14 +526,12 @@ export var Util = {
533526
newLayer = true;
534527
}
535528
if (!link.inPlace && newLayer)
536-
layer.whenReady().then(() => {
537-
if (zoomTo)
538-
layer.parentElement.zoomTo(+zoomTo.lat, +zoomTo.lng, +zoomTo.z);
539-
else layer.zoomTo();
529+
if (zoomTo)
530+
layer.parentElement.zoomTo(+zoomTo.lat, +zoomTo.lng, +zoomTo.z);
531+
else layer.zoomTo();
540532

541-
if (opacity) layer.opacity = opacity;
542-
map.getContainer().focus();
543-
});
533+
if (opacity) layer.opacity = opacity;
534+
map.getContainer().focus();
544535
} else if (zoomTo && !link.inPlace && justPan) {
545536
leafletLayer._map.options.mapEl.zoomTo(
546537
+zoomTo.lat,

src/web-map.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,14 @@ export class WebMap extends HTMLMapElement {
113113
map.getZoom(),
114114
map.options.projection
115115
);
116-
let formattedExtent = M._convertAndFormatPCRS(pcrsBounds, map);
116+
let formattedExtent = M._convertAndFormatPCRS(pcrsBounds, map.options.crs);
117117
if (map.getMaxZoom() !== Infinity) {
118118
formattedExtent.zoom = {
119119
minZoom: map.getMinZoom(),
120120
maxZoom: map.getMaxZoom()
121121
};
122122
}
123+
formattedExtent.projection = this.projection;
123124
return formattedExtent;
124125
}
125126
get static() {

test/e2e/core/layerContextMenu.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test.describe('Playwright Layer Context Menu Tests', () => {
6565
);
6666

6767
expect(copyLayer).toEqual(
68-
'<layer- label="CBMT - INLINE" checked="">\n <map-link rel="license" title="Testing Inc."></map-link>\n <map-extent units="CBMTILE" hidden="">\n <map-input name="zoomLevel" type="zoom" value="3" min="0" max="3"></map-input>\n <map-input name="row" type="location" axis="row" units="tilematrix" min="14" max="21"></map-input>\n <map-input name="col" type="location" axis="column" units="tilematrix" min="14" max="19"></map-input>\n <map-link rel="tile" tref="http://localhost:30001/data/cbmt/{zoomLevel}/c{col}_r{row}.png"></map-link>\n </map-extent>\n </layer->'
68+
'<layer- label="CBMT - INLINE" checked="">\n <map-link rel="license" title="Testing Inc."></map-link>\n <map-extent units="CBMTILE" hidden="" checked="">\n <map-input name="zoomLevel" type="zoom" value="3" min="0" max="3"></map-input>\n <map-input name="row" type="location" axis="row" units="tilematrix" min="14" max="21"></map-input>\n <map-input name="col" type="location" axis="column" units="tilematrix" min="14" max="19"></map-input>\n <map-link rel="tile" tref="http://localhost:30001/data/cbmt/{zoomLevel}/c{col}_r{row}.png"></map-link>\n </map-extent>\n </layer->'
6969
);
7070
});
7171

0 commit comments

Comments
 (0)