Skip to content

Commit e8dad99

Browse files
committed
[AUTO] Sync MapML Build
1 parent 913312c commit e8dad99

1 file changed

Lines changed: 46 additions & 41 deletions

File tree

dist/mapml.js

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,18 +4432,18 @@
44324432
},
44334433

44344434
convertPCRSBounds: function(pcrsBounds, zoom, projection, cs){
4435-
if(!pcrsBounds || !zoom && +zoom !== 0 || !cs) return undefined;
4436-
switch (cs.toLowerCase()) {
4437-
case "pcrs":
4435+
if(!pcrsBounds || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection || !cs) return undefined;
4436+
switch (cs.toUpperCase()) {
4437+
case "PCRS":
44384438
return pcrsBounds;
4439-
case "tcrs":
4440-
case "tilematrix":
4439+
case "TCRS":
4440+
case "TILEMATRIX":
44414441
let minPixel = this[projection].transformation.transform(pcrsBounds.min, this[projection].scale(+zoom)),
44424442
maxPixel = this[projection].transformation.transform(pcrsBounds.max, this[projection].scale(+zoom));
4443-
if (cs.toLowerCase() === "tcrs") return L.bounds(minPixel, maxPixel);
4443+
if (cs.toUpperCase() === "TCRS") return L.bounds(minPixel, maxPixel);
44444444
let tileSize = M[projection].options.crs.tile.bounds.max.x;
44454445
return L.bounds(L.point(minPixel.x / tileSize, minPixel.y / tileSize), L.point(maxPixel.x / tileSize,maxPixel.y / tileSize));
4446-
case "gcrs":
4446+
case "GCRS":
44474447
let minGCRS = this[projection].unproject(pcrsBounds.min),
44484448
maxGCRS = this[projection].unproject(pcrsBounds.max);
44494449
return L.bounds(L.point(minGCRS.lng, minGCRS.lat), L.point(maxGCRS.lng, maxGCRS.lat));
@@ -4452,37 +4452,37 @@
44524452
}
44534453
},
44544454

4455-
pointToPCRSPoint: function(p, zoom, projection, cs){
4456-
if(!p || !zoom && +zoom !== 0 || !cs || !projection) return undefined;
4455+
pointToPCRSPoint: function(point, zoom, projection, cs){
4456+
if(!point || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !cs || !projection) return undefined;
44574457
let tileSize = M[projection].options.crs.tile.bounds.max.x;
44584458
switch(cs.toUpperCase()){
44594459
case "TILEMATRIX":
4460-
return M.pixelToPCRSPoint(L.point(p.x*tileSize,p.y*tileSize),zoom,projection);
4460+
return M.pixelToPCRSPoint(L.point(point.x*tileSize,point.y*tileSize),zoom,projection);
44614461
case "PCRS":
4462-
return p;
4462+
return point;
44634463
case "TCRS" :
4464-
return M.pixelToPCRSPoint(p,zoom,projection);
4464+
return M.pixelToPCRSPoint(point,zoom,projection);
44654465
case "GCRS":
4466-
return this[projection].project(L.latLng(p.y,p.x));
4466+
return this[projection].project(L.latLng(point.y,point.x));
44674467
default:
44684468
return undefined;
44694469
}
44704470
},
44714471

4472-
pixelToPCRSPoint: function(p, zoom, projection){
4473-
if(!p || !zoom && +zoom !== 0) return undefined;
4474-
return this[projection].transformation.untransform(p,this[projection].scale(zoom));
4472+
pixelToPCRSPoint: function(point, zoom, projection){
4473+
if(!point || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection) return undefined;
4474+
return this[projection].transformation.untransform(point,this[projection].scale(zoom));
44754475
},
44764476

44774477
boundsToPCRSBounds: function(bounds, zoom, projection, cs){
4478-
if(!bounds || !zoom && +zoom !== 0 || !cs) return undefined;
4478+
if(!bounds || !bounds.max || !bounds.min || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection || !cs) return undefined;
44794479
return L.bounds(M.pointToPCRSPoint(bounds.min, zoom, projection, cs), M.pointToPCRSPoint(bounds.max, zoom, projection, cs));
44804480
},
44814481

44824482
//L.bounds have fixed point positions, where min is always topleft, max is always bottom right, and the values are always sorted by leaflet
44834483
//important to consider when working with pcrs where the origin is not topleft but rather bottomleft, could lead to confusion
44844484
pixelToPCRSBounds : function(bounds, zoom, projection){
4485-
if(!bounds || !bounds.max || !bounds.min ||zoom === undefined || zoom === null || zoom instanceof Object) return undefined;
4485+
if(!bounds || !bounds.max || !bounds.min || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection) return undefined;
44864486
return L.bounds(M.pixelToPCRSPoint(bounds.min, zoom, projection), M.pixelToPCRSPoint(bounds.max, zoom, projection));
44874487
},
44884488
//meta content is the content attribute of meta
@@ -4842,17 +4842,17 @@
48424842

48434843
/**
48444844
* Attaches link handler to the sub parts' paths
4845-
* @param path
4846-
* @param link
4845+
* @param {SVGElement} elem - The element to add listeners to, either path or g elements
4846+
* @param {Object} link - The link object that contains the url, type and target data
48474847
* @param leafletLayer
48484848
*/
4849-
attachLinkHandler: function (path, link, leafletLayer) {
4849+
attachLinkHandler: function (elem, link, leafletLayer) {
48504850
let dragStart, container = document.createElement('div'), p = document.createElement('p'), hovered = false;
48514851
container.classList.add('mapml-link-preview');
48524852
container.appendChild(p);
4853-
path.classList.add('map-a');
4854-
L.DomEvent.on(path, 'mousedown', e => dragStart = {x:e.clientX, y:e.clientY}, this);
4855-
L.DomEvent.on(path, "mouseup", (e) => {
4853+
elem.classList.add('map-a');
4854+
L.DomEvent.on(elem, 'mousedown', e => dragStart = {x:e.clientX, y:e.clientY}, this);
4855+
L.DomEvent.on(elem, "mouseup", (e) => {
48564856
let onTop = true, nextLayer = this.options._leafletLayer._layerEl.nextElementSibling;
48574857
while(nextLayer && onTop){
48584858
if(nextLayer.tagName && nextLayer.tagName.toUpperCase() === "LAYER-")
@@ -4865,12 +4865,12 @@
48654865
if (dist <= 5) M.handleLink(link, leafletLayer);
48664866
}
48674867
}, this);
4868-
L.DomEvent.on(path, "keypress", (e) => {
4868+
L.DomEvent.on(elem, "keypress", (e) => {
48694869
L.DomEvent.stop(e);
48704870
if(e.keyCode === 13 || e.keyCode === 32)
48714871
M.handleLink(link, leafletLayer);
48724872
}, this);
4873-
L.DomEvent.on(path, 'mouseenter keyup', (e) => {
4873+
L.DomEvent.on(elem, 'mouseenter keyup', (e) => {
48744874
if(e.target !== e.currentTarget) return;
48754875
hovered = true;
48764876
let resolver = document.createElement('a'), mapWidth = this._map.getContainer().clientWidth;
@@ -4886,7 +4886,7 @@
48864886
if(hovered) p.innerHTML = resolver.href;
48874887
}, 1000);
48884888
}, this);
4889-
L.DomEvent.on(path, 'mouseout keydown mousedown', (e) => {
4889+
L.DomEvent.on(elem, 'mouseout keydown mousedown', (e) => {
48904890
if(e.target !== e.currentTarget || !container.parentElement) return;
48914891
hovered = false;
48924892
this._map.getContainer().removeChild(container);
@@ -4954,19 +4954,14 @@
49544954

49554955
/**
49564956
* Converts the spans, a and divs around a geometry subtype into options for the feature
4957+
* @param {HTMLElement[]} elems - The current zoom level of the map
49574958
* @private
49584959
*/
49594960
_convertWrappers: function (elems) {
49604961
if(!elems || elems.length === 0) return;
49614962
let classList = '', output = {};
49624963
for(let elem of elems){
49634964
if(elem.tagName.toUpperCase() !== "MAP-A" && elem.className){
4964-
// Useful if getting other attributes off spans and divs is useful
4965-
/* let attr = elem.attributes;
4966-
for(let i = 0; i < attr.length; i++){
4967-
if(attr[i].name === "class" || attributes[attr[i].name]) continue;
4968-
attributes[attr[i].name] = attr[i].value;
4969-
}*/
49704965
classList +=`${elem.className} `;
49714966
} else if(!output.link && elem.getAttribute("href")) {
49724967
let link = {};
@@ -4998,18 +4993,18 @@
49984993

49994994
let first = true;
50004995
for (let c of this._markup.querySelectorAll('coordinates')) { //loops through the coordinates of the child
5001-
let ring = [], subrings = [];
5002-
this._coordinateToArrays(c, ring, subrings, this.options.className); //creates an array of pcrs points for the main ring and the subparts
4996+
let ring = [], subRings = [];
4997+
this._coordinateToArrays(c, ring, subRings, this.options.className); //creates an array of pcrs points for the main ring and the subparts
50034998
if (!first && this.type === "POLYGON") {
50044999
this._parts[0].rings.push(ring[0]);
5005-
if (subrings.length > 0)
5006-
this._parts[0].subrings = this._parts[0].subrings.concat(subrings);
5000+
if (subRings.length > 0)
5001+
this._parts[0].subrings = this._parts[0].subrings.concat(subRings);
50075002
} else if (this.type === "MULTIPOINT") {
5008-
for (let point of ring[0].points.concat(subrings)) {
5003+
for (let point of ring[0].points.concat(subRings)) {
50095004
this._parts.push({ rings: [{ points: [point] }], subrings: [], cls:`${point.cls || ""} ${this.options.className || ""}`.trim() });
50105005
}
50115006
} else {
5012-
this._parts.push({ rings: ring, subrings: subrings, cls: `${this.featureAttributes.class || ""} ${this.options.className || ""}`.trim() });
5007+
this._parts.push({ rings: ring, subrings: subRings, cls: `${this.featureAttributes.class || ""} ${this.options.className || ""}`.trim() });
50135008
}
50145009
first = false;
50155010
}
@@ -5080,7 +5075,13 @@
50805075
if(attr[i].name === "class") continue;
50815076
attrMap[attr[i].name] = attr[i].value;
50825077
}
5083-
subParts.unshift({ points: local, cls: `${cls || ""} ${wrapperAttr.className || ""}`.trim(), attr: attrMap, link: wrapperAttr.link, linkTarget: wrapperAttr.linkTarget, linkType: wrapperAttr.linkType});
5078+
subParts.unshift({
5079+
points: local,
5080+
cls: `${cls || ""} ${wrapperAttr.className || ""}`.trim(),
5081+
attr: attrMap,
5082+
link: wrapperAttr.link,
5083+
linkTarget: wrapperAttr.linkTarget,
5084+
linkType: wrapperAttr.linkType});
50845085
}
50855086
},
50865087

@@ -5431,7 +5432,7 @@
54315432

54325433
/**
54335434
* Handler for focus events
5434-
* @param {L.DOMEvent} e - Event that occured
5435+
* @param {L.DOMEvent} e - Event that occurred
54355436
* @private
54365437
*/
54375438
_handleFocus: function(e) {
@@ -5449,6 +5450,10 @@
54495450
}
54505451
},
54515452

5453+
/**
5454+
* Add a M.Feature to the M.FeatureGroup
5455+
* @param layer
5456+
*/
54525457
addLayer: function (layer) {
54535458
if(!layer.options.link && this.options.onEachFeature) {
54545459
this.options.onEachFeature(this.options.properties, layer);

0 commit comments

Comments
 (0)