|
4432 | 4432 | }, |
4433 | 4433 |
|
4434 | 4434 | 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": |
4438 | 4438 | return pcrsBounds; |
4439 | | - case "tcrs": |
4440 | | - case "tilematrix": |
| 4439 | + case "TCRS": |
| 4440 | + case "TILEMATRIX": |
4441 | 4441 | let minPixel = this[projection].transformation.transform(pcrsBounds.min, this[projection].scale(+zoom)), |
4442 | 4442 | 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); |
4444 | 4444 | let tileSize = M[projection].options.crs.tile.bounds.max.x; |
4445 | 4445 | 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": |
4447 | 4447 | let minGCRS = this[projection].unproject(pcrsBounds.min), |
4448 | 4448 | maxGCRS = this[projection].unproject(pcrsBounds.max); |
4449 | 4449 | return L.bounds(L.point(minGCRS.lng, minGCRS.lat), L.point(maxGCRS.lng, maxGCRS.lat)); |
|
4452 | 4452 | } |
4453 | 4453 | }, |
4454 | 4454 |
|
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; |
4457 | 4457 | let tileSize = M[projection].options.crs.tile.bounds.max.x; |
4458 | 4458 | switch(cs.toUpperCase()){ |
4459 | 4459 | 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); |
4461 | 4461 | case "PCRS": |
4462 | | - return p; |
| 4462 | + return point; |
4463 | 4463 | case "TCRS" : |
4464 | | - return M.pixelToPCRSPoint(p,zoom,projection); |
| 4464 | + return M.pixelToPCRSPoint(point,zoom,projection); |
4465 | 4465 | case "GCRS": |
4466 | | - return this[projection].project(L.latLng(p.y,p.x)); |
| 4466 | + return this[projection].project(L.latLng(point.y,point.x)); |
4467 | 4467 | default: |
4468 | 4468 | return undefined; |
4469 | 4469 | } |
4470 | 4470 | }, |
4471 | 4471 |
|
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)); |
4475 | 4475 | }, |
4476 | 4476 |
|
4477 | 4477 | 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; |
4479 | 4479 | return L.bounds(M.pointToPCRSPoint(bounds.min, zoom, projection, cs), M.pointToPCRSPoint(bounds.max, zoom, projection, cs)); |
4480 | 4480 | }, |
4481 | 4481 |
|
4482 | 4482 | //L.bounds have fixed point positions, where min is always topleft, max is always bottom right, and the values are always sorted by leaflet |
4483 | 4483 | //important to consider when working with pcrs where the origin is not topleft but rather bottomleft, could lead to confusion |
4484 | 4484 | 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; |
4486 | 4486 | return L.bounds(M.pixelToPCRSPoint(bounds.min, zoom, projection), M.pixelToPCRSPoint(bounds.max, zoom, projection)); |
4487 | 4487 | }, |
4488 | 4488 | //meta content is the content attribute of meta |
|
4842 | 4842 |
|
4843 | 4843 | /** |
4844 | 4844 | * 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 |
4847 | 4847 | * @param leafletLayer |
4848 | 4848 | */ |
4849 | | - attachLinkHandler: function (path, link, leafletLayer) { |
| 4849 | + attachLinkHandler: function (elem, link, leafletLayer) { |
4850 | 4850 | let dragStart, container = document.createElement('div'), p = document.createElement('p'), hovered = false; |
4851 | 4851 | container.classList.add('mapml-link-preview'); |
4852 | 4852 | 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) => { |
4856 | 4856 | let onTop = true, nextLayer = this.options._leafletLayer._layerEl.nextElementSibling; |
4857 | 4857 | while(nextLayer && onTop){ |
4858 | 4858 | if(nextLayer.tagName && nextLayer.tagName.toUpperCase() === "LAYER-") |
|
4865 | 4865 | if (dist <= 5) M.handleLink(link, leafletLayer); |
4866 | 4866 | } |
4867 | 4867 | }, this); |
4868 | | - L.DomEvent.on(path, "keypress", (e) => { |
| 4868 | + L.DomEvent.on(elem, "keypress", (e) => { |
4869 | 4869 | L.DomEvent.stop(e); |
4870 | 4870 | if(e.keyCode === 13 || e.keyCode === 32) |
4871 | 4871 | M.handleLink(link, leafletLayer); |
4872 | 4872 | }, this); |
4873 | | - L.DomEvent.on(path, 'mouseenter keyup', (e) => { |
| 4873 | + L.DomEvent.on(elem, 'mouseenter keyup', (e) => { |
4874 | 4874 | if(e.target !== e.currentTarget) return; |
4875 | 4875 | hovered = true; |
4876 | 4876 | let resolver = document.createElement('a'), mapWidth = this._map.getContainer().clientWidth; |
|
4886 | 4886 | if(hovered) p.innerHTML = resolver.href; |
4887 | 4887 | }, 1000); |
4888 | 4888 | }, this); |
4889 | | - L.DomEvent.on(path, 'mouseout keydown mousedown', (e) => { |
| 4889 | + L.DomEvent.on(elem, 'mouseout keydown mousedown', (e) => { |
4890 | 4890 | if(e.target !== e.currentTarget || !container.parentElement) return; |
4891 | 4891 | hovered = false; |
4892 | 4892 | this._map.getContainer().removeChild(container); |
|
4954 | 4954 |
|
4955 | 4955 | /** |
4956 | 4956 | * 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 |
4957 | 4958 | * @private |
4958 | 4959 | */ |
4959 | 4960 | _convertWrappers: function (elems) { |
4960 | 4961 | if(!elems || elems.length === 0) return; |
4961 | 4962 | let classList = '', output = {}; |
4962 | 4963 | for(let elem of elems){ |
4963 | 4964 | 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 | | - }*/ |
4970 | 4965 | classList +=`${elem.className} `; |
4971 | 4966 | } else if(!output.link && elem.getAttribute("href")) { |
4972 | 4967 | let link = {}; |
|
4998 | 4993 |
|
4999 | 4994 | let first = true; |
5000 | 4995 | 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 |
5003 | 4998 | if (!first && this.type === "POLYGON") { |
5004 | 4999 | 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); |
5007 | 5002 | } 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)) { |
5009 | 5004 | this._parts.push({ rings: [{ points: [point] }], subrings: [], cls:`${point.cls || ""} ${this.options.className || ""}`.trim() }); |
5010 | 5005 | } |
5011 | 5006 | } 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() }); |
5013 | 5008 | } |
5014 | 5009 | first = false; |
5015 | 5010 | } |
|
5080 | 5075 | if(attr[i].name === "class") continue; |
5081 | 5076 | attrMap[attr[i].name] = attr[i].value; |
5082 | 5077 | } |
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}); |
5084 | 5085 | } |
5085 | 5086 | }, |
5086 | 5087 |
|
|
5431 | 5432 |
|
5432 | 5433 | /** |
5433 | 5434 | * Handler for focus events |
5434 | | - * @param {L.DOMEvent} e - Event that occured |
| 5435 | + * @param {L.DOMEvent} e - Event that occurred |
5435 | 5436 | * @private |
5436 | 5437 | */ |
5437 | 5438 | _handleFocus: function(e) { |
|
5449 | 5450 | } |
5450 | 5451 | }, |
5451 | 5452 |
|
| 5453 | + /** |
| 5454 | + * Add a M.Feature to the M.FeatureGroup |
| 5455 | + * @param layer |
| 5456 | + */ |
5452 | 5457 | addLayer: function (layer) { |
5453 | 5458 | if(!layer.options.link && this.options.onEachFeature) { |
5454 | 5459 | this.options.onEachFeature(this.options.properties, layer); |
|
0 commit comments