From 02d1f87a6390d4b7fcb4b1f58241dedf1db85316 Mon Sep 17 00:00:00 2001 From: AliyanH Date: Mon, 23 Jan 2023 17:10:24 -0500 Subject: [PATCH 1/3] privatize internal methods --- src/mapml/features/feature.js | 8 +-- src/mapml/index.js | 16 ++--- src/mapml/layers/FeatureLayer.js | 14 ++-- src/mapml/layers/MapLayer.js | 12 ++-- src/mapml/layers/StaticTileLayer.js | 2 +- src/mapml/layers/TemplatedFeaturesLayer.js | 6 +- src/mapml/layers/TemplatedImageLayer.js | 2 +- src/mapml/layers/TemplatedLayer.js | 2 +- src/mapml/layers/TemplatedTileLayer.js | 4 +- src/mapml/utils/Util.js | 22 +++--- test/utils/boundsUtils.spec.js | 56 +++++++-------- test/utils/util.spec.js | 84 +++++++++++----------- 12 files changed, 114 insertions(+), 114 deletions(-) diff --git a/src/mapml/features/feature.js b/src/mapml/features/feature.js index 60ba12936..de59335bb 100644 --- a/src/mapml/features/feature.js +++ b/src/mapml/features/feature.js @@ -78,7 +78,7 @@ export var Feature = L.Path.extend({ link.visited = true; elem.setAttribute("stroke", "#6c00a2"); elem.classList.add("map-a-visited"); - M.handleLink(link, leafletLayer); + M._handleLink(link, leafletLayer); } } }, this); @@ -88,7 +88,7 @@ export var Feature = L.Path.extend({ link.visited = true; elem.setAttribute("stroke", "#6c00a2"); elem.classList.add("map-a-visited"); - M.handleLink(link, leafletLayer); + M._handleLink(link, leafletLayer); } }, this); L.DomEvent.on(elem, 'mouseenter keyup', (e) => { @@ -287,8 +287,8 @@ export var Feature = L.Path.extend({ pairs = noSpan.match(/(\S+\s+\S+)/gim), local = [], bounds; for (let p of pairs) { let numPair = []; - p.split(/\s+/gim).forEach(M.parseNumber, numPair); - let point = M.pointToPCRSPoint(L.point(numPair), this.options.zoom, this.options.projection, this.options.nativeCS); + p.split(/\s+/gim).forEach(M._parseNumber, numPair); + let point = M._pointToPCRSPoint(L.point(numPair), this.options.zoom, this.options.projection, this.options.nativeCS); local.push(point); bounds = bounds ? bounds.extend(point) : L.bounds(point, point); } diff --git a/src/mapml/index.js b/src/mapml/index.js index b031675eb..51c487dd3 100644 --- a/src/mapml/index.js +++ b/src/mapml/index.js @@ -589,21 +589,21 @@ window.M = M; }); }()); -M.handleLink = Util.handleLink; +M._handleLink = Util._handleLink; M.convertPCRSBounds = Util.convertPCRSBounds; M.axisToXY = Util.axisToXY; M.csToAxes = Util.csToAxes; M.convertAndFormatPCRS = Util.convertAndFormatPCRS; M.axisToCS = Util.axisToCS; -M.parseNumber = Util.parseNumber; -M.extractInputBounds = Util.extractInputBounds; -M.splitCoordinate = Util.splitCoordinate; +M._parseNumber = Util._parseNumber; +M._extractInputBounds = Util._extractInputBounds; +M._splitCoordinate = Util._splitCoordinate; M.boundsToPCRSBounds = Util.boundsToPCRSBounds; M.pixelToPCRSBounds = Util.pixelToPCRSBounds; -M.metaContentToObject = Util.metaContentToObject; -M.coordsToArray = Util.coordsToArray; -M.parseStylesheetAsHTML = Util.parseStylesheetAsHTML; -M.pointToPCRSPoint = Util.pointToPCRSPoint; +M._metaContentToObject = Util._metaContentToObject; +M._coordsToArray = Util._coordsToArray; +M._parseStylesheetAsHTML = Util._parseStylesheetAsHTML; +M._pointToPCRSPoint = Util._pointToPCRSPoint; M.pixelToPCRSPoint = Util.pixelToPCRSPoint; M.gcrsToTileMatrix = Util.gcrsToTileMatrix; M._pasteLayer = Util._pasteLayer; diff --git a/src/mapml/layers/FeatureLayer.js b/src/mapml/layers/FeatureLayer.js index 0a7503e5b..5f58f9fcc 100644 --- a/src/mapml/layers/FeatureLayer.js +++ b/src/mapml/layers/FeatureLayer.js @@ -83,9 +83,9 @@ export var MapMLFeatures = L.FeatureGroup.extend({ _getNativeVariables: function(mapml){ let nativeZoom = (mapml.querySelector && mapml.querySelector("map-meta[name=zoom]") && - +M.metaContentToObject(mapml.querySelector("map-meta[name=zoom]").getAttribute("content")).value) || 0; + +M._metaContentToObject(mapml.querySelector("map-meta[name=zoom]").getAttribute("content")).value) || 0; let nativeCS = (mapml.querySelector && mapml.querySelector("map-meta[name=cs]") && - M.metaContentToObject(mapml.querySelector("map-meta[name=cs]").getAttribute("content")).content) || "PCRS"; + M._metaContentToObject(mapml.querySelector("map-meta[name=cs]").getAttribute("content")).content) || "PCRS"; return {zoom:nativeZoom, cs: nativeCS}; }, @@ -115,13 +115,13 @@ export var MapMLFeatures = L.FeatureGroup.extend({ if (!container) return null; let cs = FALLBACK_CS, projection = container.querySelector('map-meta[name=projection]') && - M.metaContentToObject( + M._metaContentToObject( container.querySelector('map-meta[name=projection]').getAttribute('content')) .content.toUpperCase() || FALLBACK_PROJECTION; try{ let meta = container.querySelector('map-meta[name=extent]') && - M.metaContentToObject( + M._metaContentToObject( container.querySelector('map-meta[name=extent]').getAttribute('content')); let zoom = meta.zoom || 0; @@ -189,8 +189,8 @@ export var MapMLFeatures = L.FeatureGroup.extend({ nMin = Math.min(nMin, lZoom); } try{ - projection = M.metaContentToObject(container.querySelector('map-meta[name=projection]').getAttribute('content')).content; - meta = M.metaContentToObject(container.querySelector('map-meta[name=zoom]').getAttribute('content')); + projection = M._metaContentToObject(container.querySelector('map-meta[name=projection]').getAttribute('content')).content; + meta = M._metaContentToObject(container.querySelector('map-meta[name=zoom]').getAttribute('content')); } catch(error){ return { minZoom:0, @@ -216,7 +216,7 @@ export var MapMLFeatures = L.FeatureGroup.extend({ var base = mapml.querySelector('map-base') && mapml.querySelector('map-base').hasAttribute('href') ? new URL(mapml.querySelector('map-base').getAttribute('href')).href : mapml.URL; - M.parseStylesheetAsHTML(mapml,base,this._container); + M._parseStylesheetAsHTML(mapml,base,this._container); } if (features) { for (i = 0, len = features.length; i < len; i++) { diff --git a/src/mapml/layers/MapLayer.js b/src/mapml/layers/MapLayer.js index f833592de..d1b1ab289 100644 --- a/src/mapml/layers/MapLayer.js +++ b/src/mapml/layers/MapLayer.js @@ -279,7 +279,7 @@ export var MapMLLayer = L.Layer.extend({ if(type === "_templatedLayer"){ for(let i = 0; i < this._extent._mapExtents.length; i++){ for(let j = 0; j < this._extent._mapExtents[i]._templateVars.length; j++){ - let inputData = M.extractInputBounds(this._extent._mapExtents[i]._templateVars[j]); + let inputData = M._extractInputBounds(this._extent._mapExtents[i]._templateVars[j]); this._extent._mapExtents[i]._templateVars[j].tempExtentBounds = inputData.bounds; this._extent._mapExtents[i]._templateVars[j].extentZoomBounds = inputData.zoomBounds; } @@ -862,7 +862,7 @@ export var MapMLLayer = L.Layer.extend({ extentFallback.zoom = 0; if (metaExtent){ - let content = M.metaContentToObject(metaExtent.getAttribute("content")), cs; + let content = M._metaContentToObject(metaExtent.getAttribute("content")), cs; extentFallback.zoom = content.zoom || extentFallback.zoom; @@ -901,7 +901,7 @@ export var MapMLLayer = L.Layer.extend({ inputs = [], tms = t && t.hasAttribute("tms"); var zoomBounds = mapml.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(mapml.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(mapml.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; while ((v = varNamesRe.exec(template)) !== null) { var varName = v[1], @@ -1017,7 +1017,7 @@ export var MapMLLayer = L.Layer.extend({ } } else if(serverMeta){ if (serverMeta.tagName.toLowerCase() === "map-meta" && serverMeta.hasAttribute('content')) { - projection = M.metaContentToObject(serverMeta.getAttribute('content')).content; + projection = M._metaContentToObject(serverMeta.getAttribute('content')).content; projectionMatch = projection && projection === layer.options.mapprojection; } } @@ -1085,7 +1085,7 @@ export var MapMLLayer = L.Layer.extend({ } layer._mapmlTileContainer.appendChild(tiles); } - M.parseStylesheetAsHTML(mapml, base, layer._container); + M._parseStylesheetAsHTML(mapml, base, layer._container); // add multiple extents if(layer._extent._mapExtents){ @@ -1192,7 +1192,7 @@ export var MapMLLayer = L.Layer.extend({ break; case "MAP-META": if(extent.hasAttribute('content')) - return M.metaContentToObject(extent.getAttribute('content')).content.toUpperCase(); + return M._metaContentToObject(extent.getAttribute('content')).content.toUpperCase(); break; default: return FALLBACK_PROJECTION; diff --git a/src/mapml/layers/StaticTileLayer.js b/src/mapml/layers/StaticTileLayer.js index 32263b0d9..7ffff3ad0 100644 --- a/src/mapml/layers/StaticTileLayer.js +++ b/src/mapml/layers/StaticTileLayer.js @@ -96,7 +96,7 @@ export var MapMLStaticTileLayer = L.GridLayer.extend({ _getZoomBounds: function(container, maxZoomBound){ if(!container) return null; - let meta = M.metaContentToObject(container.getElementsByTagName('map-tiles')[0].getAttribute('zoom')), + let meta = M._metaContentToObject(container.getElementsByTagName('map-tiles')[0].getAttribute('zoom')), zoom = {},tiles = container.getElementsByTagName("map-tile"); zoom.nativeZoom = +meta.value || 0; zoom.maxNativeZoom = 0; diff --git a/src/mapml/layers/TemplatedFeaturesLayer.js b/src/mapml/layers/TemplatedFeaturesLayer.js index 96ae77097..87b6dff0f 100644 --- a/src/mapml/layers/TemplatedFeaturesLayer.js +++ b/src/mapml/layers/TemplatedFeaturesLayer.js @@ -1,7 +1,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({ // this and M.ImageLayer could be merged or inherit from a common parent initialize: function(template, options) { - let inputData = M.extractInputBounds(template); + let inputData = M._extractInputBounds(template); this.zoomBounds = inputData.zoomBounds; this.extentBounds=inputData.bounds; this.isVisible = true; @@ -109,9 +109,9 @@ export var TemplatedFeaturesLayer = L.Layer.extend({ url = url ? (new URL(url, base)).href: null; // TODO if the xml parser barfed but the response is application/geo+json, use the parent addData method let nativeZoom = mapml.querySelector("map-meta[name=zoom]") && - +M.metaContentToObject(mapml.querySelector("map-meta[name=zoom]").getAttribute("content")).value || 0; + +M._metaContentToObject(mapml.querySelector("map-meta[name=zoom]").getAttribute("content")).value || 0; let nativeCS = mapml.querySelector("map-meta[name=cs]") && - M.metaContentToObject(mapml.querySelector("map-meta[name=cs]").getAttribute("content")).content || "GCRS"; + M._metaContentToObject(mapml.querySelector("map-meta[name=cs]").getAttribute("content")).content || "GCRS"; features.addData(mapml, nativeCS, nativeZoom); if (url && --limit) { return _pullFeatureFeed(url, limit); diff --git a/src/mapml/layers/TemplatedImageLayer.js b/src/mapml/layers/TemplatedImageLayer.js index df5bf0bf7..a8b379bae 100644 --- a/src/mapml/layers/TemplatedImageLayer.js +++ b/src/mapml/layers/TemplatedImageLayer.js @@ -3,7 +3,7 @@ export var TemplatedImageLayer = L.Layer.extend({ this._template = template; this._container = L.DomUtil.create('div', 'leaflet-layer', options.pane); L.DomUtil.addClass(this._container, 'mapml-image-container'); - let inputData = M.extractInputBounds(template); + let inputData = M._extractInputBounds(template); this.zoomBounds = inputData.zoomBounds; this.extentBounds=inputData.bounds; this.isVisible = true; diff --git a/src/mapml/layers/TemplatedLayer.js b/src/mapml/layers/TemplatedLayer.js index 33238a752..623c3f36a 100644 --- a/src/mapml/layers/TemplatedLayer.js +++ b/src/mapml/layers/TemplatedLayer.js @@ -24,7 +24,7 @@ export var TemplatedLayer = L.Layer.extend({ if (!this._queries) { this._queries = []; } - let inputData = M.extractInputBounds(templates[i]); + let inputData = M._extractInputBounds(templates[i]); templates[i].extentBounds = inputData.bounds; templates[i].zoomBounds = inputData.zoomBounds; this._queries.push(L.extend(templates[i], this._setupQueryVars(templates[i]))); diff --git a/src/mapml/layers/TemplatedTileLayer.js b/src/mapml/layers/TemplatedTileLayer.js index ed2b3667b..722ab947d 100644 --- a/src/mapml/layers/TemplatedTileLayer.js +++ b/src/mapml/layers/TemplatedTileLayer.js @@ -10,7 +10,7 @@ export var TemplatedTileLayer = L.TileLayer.extend({ initialize: function(template, options) { // _setUpTileTemplateVars needs options.crs, not available unless we set // options first... - let inputData = M.extractInputBounds(template); + let inputData = M._extractInputBounds(template); this.zoomBounds = inputData.zoomBounds; this.extentBounds=inputData.bounds; this.isVisible = true; @@ -121,7 +121,7 @@ export var TemplatedTileLayer = L.TileLayer.extend({ let base = markup.querySelector('map-base') && markup.querySelector('map-base').hasAttribute('href') ? new URL(markup.querySelector('map-base').getAttribute('href')).href : markup.URL; - M.parseStylesheetAsHTML(markup,base,tile); + M._parseStylesheetAsHTML(markup,base,tile); } let svg = L.SVG.create('svg'), g = L.SVG.create('g'), tileSize = this._map.options.crs.options.crs.tile.bounds.max.x, diff --git a/src/mapml/utils/Util.js b/src/mapml/utils/Util.js index ea0a6f719..6b680e3ce 100644 --- a/src/mapml/utils/Util.js +++ b/src/mapml/utils/Util.js @@ -77,7 +77,7 @@ export var Util = { projection:map.options.projection }; }, - extractInputBounds: function(template){ + _extractInputBounds: function(template){ if(!template) return undefined; //sets variables with their respective fallback values incase content is missing from the template @@ -233,7 +233,7 @@ export var Util = { } }, - pointToPCRSPoint: function(point, zoom, projection, cs){ + _pointToPCRSPoint: function(point, zoom, projection, cs){ if(!point || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !cs || !projection) return undefined; projection = (typeof projection === "string") ? M[projection] : projection; let tileSize = projection.options.crs.tile.bounds.max.x; @@ -260,7 +260,7 @@ export var Util = { boundsToPCRSBounds: function(bounds, zoom, projection, cs){ if(!bounds || !bounds.max || !bounds.min || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection || !cs) return undefined; projection = (typeof projection === "string") ? M[projection] : projection; - return L.bounds(M.pointToPCRSPoint(bounds.min, zoom, projection, cs), M.pointToPCRSPoint(bounds.max, zoom, projection, cs)); + return L.bounds(M._pointToPCRSPoint(bounds.min, zoom, projection, cs), M._pointToPCRSPoint(bounds.max, zoom, projection, cs)); }, //L.bounds have fixed point positions, where min is always topleft, max is always bottom right, and the values are always sorted by leaflet @@ -272,7 +272,7 @@ export var Util = { }, //meta content is the content attribute of meta // input "max=5,min=4" => [[max,5][min,5]] - metaContentToObject: function(input){ + _metaContentToObject: function(input){ if(!input || input instanceof Object)return {}; let content = input.split(/\s+/).join(""); let contentArray = {}; @@ -285,14 +285,14 @@ export var Util = { if(contentArray !== "" && stringSplit[0].split("=").length ===1)contentArray.content = stringSplit[0]; return contentArray; }, - coordsToArray: function(containerPoints) { - // returns an array of arrays of coordinate pairs coordsToArray("1,2,3,4") -> [[1,2],[3,4]] + _coordsToArray: function(containerPoints) { + // returns an array of arrays of coordinate pairs _coordsToArray("1,2,3,4") -> [[1,2],[3,4]] for (var i=1, pairs = [], coords = containerPoints.split(",");i { // projection:"CBMTILE" // zoomBounds:{max:, min:} //} - describe("M.extractInputBounds utility function tests", () => { + describe("M._extractInputBounds utility function tests", () => { test("Valid template with 3 inputs, tilematrix", async () => { let template = {}; let inputContainer = document.createElement("div"); @@ -180,12 +180,12 @@ describe("M.Util Bounds Related Tests", () => { // // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.extentPCRSFallback = {}; template.projection = "WGS84"; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: { max: { x: 0, y: 90 }, min: { x: -180, y: -90 } }, zoomBounds: { maxNativeZoom: 2, maxZoom: 5, minNativeZoom: 1, minZoom: 0 } }); }); @@ -199,12 +199,12 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.extentPCRSFallback = {}; template.projection = "WGS84"; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: { max: { x: 10, y: 10 }, min: { x: 5, y: 5 } }, zoomBounds: { maxNativeZoom: 5, maxZoom: 16, minNativeZoom: 1, minZoom: 1 } }); }); @@ -218,11 +218,11 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.projection = "OSMTILE"; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: { max: { x: 10, y: 10 }, min: { x: 5, y: 5 } }, zoomBounds: { maxNativeZoom: 24, maxZoom: 16, minNativeZoom: 1, minZoom: 1 } }); }); @@ -240,11 +240,11 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.projection = "CBMTILE"; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: { max: { x: 38608077, y: 42672085 }, min: { x: 28448056, y: 28448056 } }, zoomBounds: { maxNativeZoom: 19, maxZoom: 23, minNativeZoom: 0, minZoom: 0 } }); }); @@ -262,11 +262,11 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.projection = "CBMTILE"; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: { max: { x: 500, y: 500 }, min: { x: 0, y: 0 } }, zoomBounds: { maxNativeZoom: 5, maxZoom: 15, minNativeZoom: 3, minZoom: 2 } }); }); @@ -278,12 +278,12 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.extentPCRSFallback = {bounds: null}; template.projection = "WGS84"; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: { max: { x: 180, y: 90 }, min: { x: -180, y: -90 } }, zoomBounds: { maxNativeZoom: 5, maxZoom: 12, minNativeZoom: 1, minZoom: 1 } }); }); @@ -294,12 +294,12 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.extentPCRSFallback = {bounds: { max: { x: 170, y: 20 }, min: { x: 0, y: 0 }}}; template.projection = "WGS84"; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: { max: { x: 170, y: 20 }, min: { x: 0, y: 0 }}, zoomBounds: { maxNativeZoom: 21, maxZoom: 12, minNativeZoom: 0, minZoom: 3 } }); }); @@ -310,13 +310,13 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.projection = "WGS84"; // this is necessary. WHY? template.extentPCRSFallback = {}; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual( { bounds: M.WGS84.options.crs.pcrs.bounds, zoomBounds: { maxNativeZoom: 21, maxZoom: 12, minNativeZoom: 0, minZoom: 3 } }); }); @@ -330,10 +330,10 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); // this expect is logically equal, but not arithmetically equal to the // numbers used below, because the default projection is OSMTILE, but we // have to convert the provided bounds from tilematrix to pcrs coords, @@ -351,15 +351,15 @@ describe("M.Util Bounds Related Tests", () => { template.values = inputContainer.querySelectorAll("map-input"); // the code responsible for creating template.zoomBounds looks like this template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; template.extentPCRSFallback = {}; - let extractedBounds = M.extractInputBounds(template); + let extractedBounds = M._extractInputBounds(template); await expect(extractedBounds).toEqual({ bounds: M.OSMTILE.options.crs.pcrs.bounds, zoomBounds: { maxNativeZoom: 2, maxZoom: 5, minNativeZoom: 1, minZoom: 0 } }); }); test("Null template", async () => { - let extractedBounds = M.extractInputBounds(null); + let extractedBounds = M._extractInputBounds(null); await expect(extractedBounds).toEqual(undefined); }); @@ -369,9 +369,9 @@ describe("M.Util Bounds Related Tests", () => { inputContainer.innerHTML = ''; template.values = inputContainer.querySelectorAll("map-input"); template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; - let extractedZoomBounds = M.extractInputBounds(template).zoomBounds; + let extractedZoomBounds = M._extractInputBounds(template).zoomBounds; await expect(extractedZoomBounds).toEqual( { maxNativeZoom: 18, maxZoom: 24, minNativeZoom: 2, minZoom: 0 } ); }); test("Test that zoom bounds reflects map-meta zoom bounds", async() => { @@ -381,19 +381,19 @@ describe("M.Util Bounds Related Tests", () => { inputContainer.innerHTML += ''; template.values = inputContainer.querySelectorAll("map-input"); template.zoomBounds = inputContainer.querySelector('map-meta[name=zoom]')? - M.metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): + M._metaContentToObject(inputContainer.querySelector('map-meta[name=zoom]').getAttribute('content')): undefined; - let extractedZoomBounds = M.extractInputBounds(template).zoomBounds; + let extractedZoomBounds = M._extractInputBounds(template).zoomBounds; await expect(extractedZoomBounds).toEqual( { maxNativeZoom: 18, maxZoom: 5, minNativeZoom: 2, minZoom: 0 } ); }); - test("Test that extractInputBounds doesn't use template.zoomBounds.minZoom, template.zoomBounds.maxZoom", async() => { + test("Test that _extractInputBounds doesn't use template.zoomBounds.minZoom, template.zoomBounds.maxZoom", async() => { let template = {}; let inputContainer = document.createElement("div"); inputContainer.innerHTML += ''; template.values = inputContainer.querySelectorAll("map-input"); // min, max are expected but don't exist; minZoom, maxZoom properties should have no effect template.zoomBounds = { minZoom: 2, maxZoom: 5 }; - let extractedZoomBounds = M.extractInputBounds(template).zoomBounds; + let extractedZoomBounds = M._extractInputBounds(template).zoomBounds; await expect(extractedZoomBounds).toEqual( { maxNativeZoom: 18, maxZoom: 24, minNativeZoom: 2, minZoom: 0 } ); }); }); diff --git a/test/utils/util.spec.js b/test/utils/util.spec.js index 755c778c2..1a372134c 100644 --- a/test/utils/util.spec.js +++ b/test/utils/util.spec.js @@ -14,7 +14,7 @@ describe("M.Util Tests", () => { // base is a valid base var mapml = parser.parseFromString(mapmlString, "application/xml"); var testcontainer = document.createElement('div'); - M.parseStylesheetAsHTML(mapml, base, testcontainer); + M._parseStylesheetAsHTML(mapml, base, testcontainer); await expect(testcontainer.querySelector('link')).toBeFalsy(); await expect(testcontainer.querySelector('style')).toBeTruthy(); await expect(testcontainer.querySelector('style').textContent).toEqual('.css {property:cool}'); @@ -30,7 +30,7 @@ describe("M.Util Tests", () => { // we expect both the link and the inline style to be copied - M.parseStylesheetAsHTML(mapml, base, testcontainer); + M._parseStylesheetAsHTML(mapml, base, testcontainer); await expect(mapml.firstChild.firstChild.nodeName).toEqual("map-head"); await expect(testcontainer.querySelector('link')).toBeTruthy(); await expect(testcontainer.querySelector('style')).toBeTruthy(); @@ -42,7 +42,7 @@ describe("M.Util Tests", () => { test("M.parseStylesheetToHTML(mapml with inline styles only, base, container)", async () => { var testcontainer = document.createElement('div'); var mapml = parser.parseFromString(mapmlString, "application/xml"); - M.parseStylesheetAsHTML(mapml, base, testcontainer); + M._parseStylesheetAsHTML(mapml, base, testcontainer); await expect(testcontainer.querySelector('link')).toBeFalsy(); await expect(testcontainer.querySelector('style')).toBeTruthy(); await expect(testcontainer.querySelector('style').textContent).toEqual('.css {property:cool}'); @@ -53,7 +53,7 @@ describe("M.Util Tests", () => { mapml.firstChild.firstChild.append(base); mapml.firstChild.firstChild.append(link); - M.parseStylesheetAsHTML(mapml, base, testcontainer); + M._parseStylesheetAsHTML(mapml, base, testcontainer); await expect(testcontainer.querySelector('link')).toBeTruthy(); await expect(testcontainer.querySelector('style')).toBeTruthy(); await expect(testcontainer.querySelector('style').textContent).toEqual('.css {property:cool}'); @@ -68,7 +68,7 @@ describe("M.Util Tests", () => { mapml.firstChild.firstChild.append(styleLinkTwo); mapml.firstChild.firstChild.append(styleLinkThree); - M.parseStylesheetAsHTML(mapml, base, testcontainer); + M._parseStylesheetAsHTML(mapml, base, testcontainer); await expect(testcontainer.children[1].href).toEqual(base + "remote.css"); await expect(testcontainer.children[2].href).toEqual(base + "styleTwo.css"); @@ -79,7 +79,7 @@ describe("M.Util Tests", () => { //base = null test("(null, null, null) should do nothing", async () => { - var check = M.parseStylesheetAsHTML(null, null, null); + var check = M._parseStylesheetAsHTML(null, null, null); await expect(check).toBeFalsy(); }); @@ -87,7 +87,7 @@ describe("M.Util Tests", () => { var testcontainer = document.createElement('div'); var mapml = parser.parseFromString(mapmlString, "application/xml"); mapml.firstChild.firstChild.append(link); - var check = M.parseStylesheetAsHTML(mapml, null, testcontainer); + var check = M._parseStylesheetAsHTML(mapml, null, testcontainer); await expect(testcontainer).toEqual(document.createElement('div')); await expect(check).toBeFalsy(); @@ -103,7 +103,7 @@ describe("M.Util Tests", () => { mapml.firstChild.firstChild.append(styleLinkTwo); mapml.firstChild.firstChild.append(styleLinkThree); - var check = M.parseStylesheetAsHTML(mapml, null, testcontainer); + var check = M._parseStylesheetAsHTML(mapml, null, testcontainer); await expect(testcontainer).toEqual(document.createElement('div')); await expect(check).toBeFalsy(); }); @@ -115,7 +115,7 @@ describe("M.Util Tests", () => { var mapml = parser.parseFromString(mapmlString, "application/xml"); mapml.firstChild.firstChild.append(nullBase); mapml.firstChild.firstChild.append(link); - M.parseStylesheetAsHTML(mapml, nullBase, testcontainer); + M._parseStylesheetAsHTML(mapml, nullBase, testcontainer); await expect(testcontainer.querySelector('link').href).toEqual(document.URL + 'remote.css'); }); @@ -125,7 +125,7 @@ describe("M.Util Tests", () => { var mapml = parser.parseFromString(mapmlString, "application/xml"); mapml.firstChild.firstChild.append(testBase); mapml.firstChild.firstChild.append(link); - M.parseStylesheetAsHTML(mapml, testBase, testcontainer); + M._parseStylesheetAsHTML(mapml, testBase, testcontainer); await expect(testcontainer.querySelector('link').href).toEqual('http://test.com/remote.css'); }); @@ -135,7 +135,7 @@ describe("M.Util Tests", () => { var mapml = parser.parseFromString(mapmlString, "application/xml"); mapml.firstChild.firstChild.append(link); - var check = M.parseStylesheetAsHTML(mapml, {}, testcontainer); + var check = M._parseStylesheetAsHTML(mapml, {}, testcontainer); await expect(testcontainer).toEqual(document.createElement('div')); await expect(check).toBeFalsy(); }); @@ -146,7 +146,7 @@ describe("M.Util Tests", () => { var mapml = parser.parseFromString(mapmlString, "application/xml"); mapml.firstChild.firstChild.append(testBase); mapml.firstChild.firstChild.append(link); - var check = M.parseStylesheetAsHTML(mapml, base, null); + var check = M._parseStylesheetAsHTML(mapml, base, null); await expect(testcontainer).toEqual(document.createElement('div')); await expect(check).toBeFalsy(); }); @@ -156,136 +156,136 @@ describe("M.Util Tests", () => { var mapml = parser.parseFromString(mapmlString, "application/xml"); mapml.firstChild.firstChild.append(link); - var check = M.parseStylesheetAsHTML(mapml, base, {}); + var check = M._parseStylesheetAsHTML(mapml, base, {}); await expect(testcontainer).toEqual(document.createElement('div')); await expect(check).toBeFalsy(); }); }); - describe("M.coordsToArray(containerPoints) utility function tests", () => { + describe("M._coordsToArray(containerPoints) utility function tests", () => { /* test("Null input", () => { - var output = M.coordsToArray(null); + var output = M._coordsToArray(null); await expect(output).toEqual([]) }); test("Array of numbers input", () => { var inputArray = [1, 2, 3, 4]; - var output = M.coordsToArray(inputArray); + var output = M._coordsToArray(inputArray); await expect(output).toEqual([[1, 2], [3, 4]]) }); test("Single number array input", () => { var inputArray = [1]; - var output = M.coordsToArray(inputArray); + var output = M._coordsToArray(inputArray); await expect(output).toEqual([]) }); test("Empty array input", () => { var inputArray = []; - var output = M.coordsToArray(inputArray); + var output = M._coordsToArray(inputArray); await expect(output).toEqual([]) }); */ test("Even number of input coords", async () => { var inputArray = "1,2,3,4"; - var output = M.coordsToArray(inputArray); + var output = M._coordsToArray(inputArray); await expect(output).toEqual([[1, 2], [3, 4]]); }); test("Odd number of input coords", async () => { var inputArray = "1,2,3,4,5"; - var output = M.coordsToArray(inputArray); + var output = M._coordsToArray(inputArray); await expect(output).toEqual([[1, 2], [3, 4]]); }); test("Single number input", async () => { var inputArray = "1"; - var output = M.coordsToArray(inputArray); + var output = M._coordsToArray(inputArray); await expect(output).toEqual([]); }); test("Empty string input", async () => { var inputArray = ""; - var output = M.coordsToArray(inputArray); + var output = M._coordsToArray(inputArray); await expect(output).toEqual([]); }); }); - describe("M.metaContentToObject(content) utility function tests", () => { + describe("M._metaContentToObject(content) utility function tests", () => { test("Null object passed", async () => { - let output = M.metaContentToObject(null); + let output = M._metaContentToObject(null); await expect(output).toEqual({}); }); test("Valid single input", async () => { - let output = M.metaContentToObject("max=5"); + let output = M._metaContentToObject("max=5"); await expect(output).toEqual({ max: "5" }); }); test("Valid multiple input", async () => { - let output = M.metaContentToObject("max=5,min=23,zoom=65,x=65"); + let output = M._metaContentToObject("max=5,min=23,zoom=65,x=65"); await expect(output).toEqual({ max: "5", min: "23", zoom: "65", x: "65" }); }); test("Empty string", async () => { - let output = M.metaContentToObject(""); + let output = M._metaContentToObject(""); await expect(output).toEqual({}); }); test("No equal sign just value", async () => { - let output = M.metaContentToObject("noequal"); + let output = M._metaContentToObject("noequal"); await expect(output).toEqual({ content: "noequal" }); }); test("Invalid object", async () => { - let output = M.metaContentToObject({}); + let output = M._metaContentToObject({}); await expect(output).toEqual({}); }); }); - describe("M.metaContentToObject(content) utility function tests", () => { + describe("M._metaContentToObject(content) utility function tests", () => { test("Null object passed", async () => { - let output = M.metaContentToObject(null); + let output = M._metaContentToObject(null); await expect(output).toEqual({}); }); test("Valid single input", async () => { - let output = M.metaContentToObject("max=5"); + let output = M._metaContentToObject("max=5"); await expect(output).toEqual({ max: "5" }); }); test("Valid multiple input", async () => { - let output = M.metaContentToObject("max=5,min=23,zoom=65,x=65"); + let output = M._metaContentToObject("max=5,min=23,zoom=65,x=65"); await expect(output).toEqual({ max: "5", min: "23", zoom: "65", x: "65" }); }); test("Empty string", async () => { - let output = M.metaContentToObject(""); + let output = M._metaContentToObject(""); await expect(output).toEqual({}); }); test("No equal sign just value", async () => { - let output = M.metaContentToObject("noequal"); + let output = M._metaContentToObject("noequal"); await expect(output).toEqual({ content: "noequal" }); }); test("Invalid object", async () => { - let output = M.metaContentToObject({}); + let output = M._metaContentToObject({}); await expect(output).toEqual({}); }); }); @@ -376,7 +376,7 @@ describe("M.Util Tests", () => { }); }); - describe("M.pointToPCRSPoint() utility function tests", () => { + describe("M._pointToPCRSPoint() utility function tests", () => { let expected = [ [ {"x": 63557729.76039286, "y": -58903529.76039286}, @@ -404,7 +404,7 @@ describe("M.Util Tests", () => { for(let i in csArray ){ for(let j in projArray ){ test(`Valid conversion in ${projArray[j]} + ${csArray[i]}`, async () => { - let output = M.pointToPCRSPoint(point, 0, projArray[j], csArray[i]); + let output = M._pointToPCRSPoint(point, 0, projArray[j], csArray[i]); await expect(output).toEqual(expected[i][j]); }); } @@ -412,19 +412,19 @@ describe("M.Util Tests", () => { /* jshint ignore:end */ test("Null point", async () => { - let output = M.pointToPCRSPoint(null, 0, "CBMTILE"); + let output = M._pointToPCRSPoint(null, 0, "CBMTILE"); await expect(output).toEqual(undefined); }); test("Null zoom", async () => { - let output = M.pointToPCRSPoint(point, null, "CBMTILE"); + let output = M._pointToPCRSPoint(point, null, "CBMTILE"); await expect(output).toEqual(undefined); }); test("Null projection", async () => { - let output = M.pointToPCRSPoint(point, 1, null); + let output = M._pointToPCRSPoint(point, 1, null); await expect(output).toEqual(undefined); }); test("Null cs", async () => { - let output = M.pointToPCRSPoint(point, 1, "CBMTILE", null); + let output = M._pointToPCRSPoint(point, 1, "CBMTILE", null); await expect(output).toEqual(undefined); }); }); From 3290bead48c94cc84bd83409af10d7733a869eec Mon Sep 17 00:00:00 2001 From: AliyanH Date: Mon, 30 Jan 2023 14:38:05 -0500 Subject: [PATCH 2/3] Add comments --- src/map-area.js | 2 +- src/mapml-viewer.js | 2 +- src/mapml/features/feature.js | 2 +- src/mapml/handlers/AnnounceMovement.js | 4 +-- src/mapml/index.js | 6 ++-- src/mapml/layers/MapLayer.js | 2 +- src/mapml/utils/Util.js | 47 +++++++++++++++++++++----- src/web-map.js | 2 +- test/utils/boundsUtils.spec.js | 6 ++-- test/utils/util.spec.js | 12 +++---- 10 files changed, 58 insertions(+), 27 deletions(-) diff --git a/src/map-area.js b/src/map-area.js index 9cba3501e..eab576de6 100644 --- a/src/map-area.js +++ b/src/map-area.js @@ -132,7 +132,7 @@ export class MapArea extends HTMLAreaElement { delete this._feature; } _coordsToArray(containerPoints) { - // returns an array of arrays of coordinate pairs coordsToArray("1,2,3,4") -> [[1,2],[3,4]] + // returns an array of arrays of coordinate pairs _coordsToArray("1,2,3,4") -> [[1,2],[3,4]] for (var i=1, points = [], coords = containerPoints.split(",");i {...} + _convertAndFormatPCRS : function(pcrsBounds, map){ if(!pcrsBounds || !map) return {}; let tcrsTopLeft = [], tcrsBottomRight = [], @@ -77,6 +79,9 @@ export var Util = { projection:map.options.projection }; }, + + // _extractInputBounds extracts and returns Input Bounds from the provided template + // _extractInputBounds: Object -> {zoomBounds: ..., bounds: ...} _extractInputBounds: function(template){ if(!template) return undefined; @@ -146,6 +151,9 @@ export var Util = { }; }, + // axisToCS returns the CRS when given the axis: + // https://maps4html.org/web-map-doc/docs/elements/input/#axis + // axisToCS: (Axis String) -> (CRS String) axisToCS : function(axis){ try{ switch(axis.toLowerCase()){ @@ -170,7 +178,9 @@ export var Util = { } catch (e) {return undefined;} }, - //takes a given cs and retuns the axes, first horizontal then vertical + // csToAxes takes a given cs and retuns the axes, first horizontal then vertical + // https://maps4html.org/web-map-doc/docs/elements/input/#axis + // csToAxes: (CRS String) -> [(horizontal axis String), (Vertical axis String)] csToAxes: function(cs){ try{ switch(cs.toLowerCase()){ @@ -189,6 +199,9 @@ export var Util = { } catch (e) {return undefined;} }, + // axisToXY takes horizontal axis and returns 'x', or takes vertical axis and returns 'y' + // https://maps4html.org/web-map-doc/docs/elements/input/#axis + // axisToXY: (Axis String) -> 'x' or 'y' axisToXY: function(axis){ try{ switch(axis.toLowerCase()){ @@ -210,7 +223,9 @@ export var Util = { } } catch (e) {return undefined;} }, - + + // convertPCRSBounds converts pcrsBounds to the given cs Bounds. + // convertPCRSBounds: L.Bounds, Int, L.CRS, Str('PCRS'|'TCRS'|'TILEMATRIX'|'GCRS') -> L.Bounds convertPCRSBounds: function(pcrsBounds, zoom, projection, cs){ if(!pcrsBounds || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection || !cs) return undefined; projection = (typeof projection === "string") ? M[projection] : projection; @@ -233,7 +248,9 @@ export var Util = { } }, - _pointToPCRSPoint: function(point, zoom, projection, cs){ + // pointToPCRSPoint takes a point, with a projection and cs and converts it to a pcrs L.point/L.latLng + //pointToPCRSPoint: L.Point, Int, L.CRS, Str('PCRS'|'TCRS'|'TILEMATRIX'|'GCRS') -> L.point|L.latLng + pointToPCRSPoint: function(point, zoom, projection, cs){ if(!point || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !cs || !projection) return undefined; projection = (typeof projection === "string") ? M[projection] : projection; let tileSize = projection.options.crs.tile.bounds.max.x; @@ -251,16 +268,20 @@ export var Util = { } }, + // pixelToPCRSPoint takes a L.point, the zoom and projection and returns a L.point in pcrs + // pixelToPCRSPoint: L.Point, Int, L.CRS|Str -> L.point pixelToPCRSPoint: function(point, zoom, projection){ if(!point || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection) return undefined; projection = (typeof projection === "string") ? M[projection] : projection; return projection.transformation.untransform(point,projection.scale(zoom)); }, + // boundsToPCRSBounds converts bounds with projection and cs to PCRS bounds + // boundsToPCRSBounds: L.bounds, Int, L.CRS|Str, Str('PCRS'|'TCRS'|'TILEMATRIX'|'GCRS') -> L.bounds boundsToPCRSBounds: function(bounds, zoom, projection, cs){ if(!bounds || !bounds.max || !bounds.min || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection || !cs) return undefined; projection = (typeof projection === "string") ? M[projection] : projection; - return L.bounds(M._pointToPCRSPoint(bounds.min, zoom, projection, cs), M._pointToPCRSPoint(bounds.max, zoom, projection, cs)); + return L.bounds(M.pointToPCRSPoint(bounds.min, zoom, projection, cs), M.pointToPCRSPoint(bounds.max, zoom, projection, cs)); }, //L.bounds have fixed point positions, where min is always topleft, max is always bottom right, and the values are always sorted by leaflet @@ -270,6 +291,7 @@ export var Util = { projection = (typeof projection === "string") ? M[projection] : projection; return L.bounds(M.pixelToPCRSPoint(bounds.min, zoom, projection), M.pixelToPCRSPoint(bounds.max, zoom, projection)); }, + //meta content is the content attribute of meta // input "max=5,min=4" => [[max,5][min,5]] _metaContentToObject: function(input){ @@ -285,13 +307,17 @@ export var Util = { if(contentArray !== "" && stringSplit[0].split("=").length ===1)contentArray.content = stringSplit[0]; return contentArray; }, + + // _coordsToArray returns an array of arrays of coordinate pairs + // _coordsToArray: ("1,2,3,4") -> [[1,2],[3,4]] _coordsToArray: function(containerPoints) { - // returns an array of arrays of coordinate pairs _coordsToArray("1,2,3,4") -> [[1,2],[3,4]] for (var i=1, pairs = [], coords = containerPoints.split(",");i [column, row] + _gcrsToTileMatrix: function (mapEl) { let point = mapEl._map.project(mapEl._map.getCenter()); let tileSize = mapEl._map.options.crs.options.crs.tile.bounds.max.y; let column = Math.trunc(point.x / tileSize); diff --git a/src/web-map.js b/src/web-map.js index 324efe12f..4b379568b 100644 --- a/src/web-map.js +++ b/src/web-map.js @@ -88,7 +88,7 @@ export class WebMap extends HTMLMapElement { map.getPixelBounds(), map.getZoom(), map.options.projection); - let formattedExtent = M.convertAndFormatPCRS(pcrsBounds, map); + let formattedExtent = M._convertAndFormatPCRS(pcrsBounds, map); if(map.getMaxZoom() !== Infinity){ formattedExtent.zoom = { minZoom:map.getMinZoom(), diff --git a/test/utils/boundsUtils.spec.js b/test/utils/boundsUtils.spec.js index cc86e01b7..a5be1e20d 100644 --- a/test/utils/boundsUtils.spec.js +++ b/test/utils/boundsUtils.spec.js @@ -399,7 +399,7 @@ describe("M.Util Bounds Related Tests", () => { }); /* jshint ignore:start */ - describe("M.convertAndFormatPCRS utility function tests", () => { + describe("M._convertAndFormatPCRS utility function tests", () => { let projections = ["CBMTILE", "OSMTILE", "WGS84", "APSTILE"]; //all expected results are in the order of projections (CBMTILE then OSMTILE...) //all referring to bottomRight @@ -437,7 +437,7 @@ describe("M.Util Bounds Related Tests", () => { fadeAnimation: true }); let pcrsBounds = L.bounds(L.point(14, 16), L.point(643, 24454)); - let conversion = M.convertAndFormatPCRS(pcrsBounds, map); + let conversion = M._convertAndFormatPCRS(pcrsBounds, map); await expect(conversion.bottomRight.pcrs).toEqual(expectedPCRS[i]); await expect(conversion.bottomRight.gcrs).toEqual(expectedGCRS[i]); await expect(conversion.bottomRight.tilematrix[0]).toEqual(expectedFirstTileMatrix[i]); @@ -456,7 +456,7 @@ describe("M.Util Bounds Related Tests", () => { fadeAnimation: true }); let pcrsBounds = L.bounds(L.point(14, 16), L.point(643, 24454)); - let conversion = M.convertAndFormatPCRS(pcrsBounds, map); + let conversion = M._convertAndFormatPCRS(pcrsBounds, map); await expect(conversion.bottomRight.tilematrix.length).toEqual(M[projections[i]].options.resolutions.length); await expect(conversion.bottomRight.tcrs.length).toEqual(M[projections[i]].options.resolutions.length); }); diff --git a/test/utils/util.spec.js b/test/utils/util.spec.js index 1a372134c..99b24d6c8 100644 --- a/test/utils/util.spec.js +++ b/test/utils/util.spec.js @@ -376,7 +376,7 @@ describe("M.Util Tests", () => { }); }); - describe("M._pointToPCRSPoint() utility function tests", () => { + describe("M.pointToPCRSPoint() utility function tests", () => { let expected = [ [ {"x": 63557729.76039286, "y": -58903529.76039286}, @@ -404,7 +404,7 @@ describe("M.Util Tests", () => { for(let i in csArray ){ for(let j in projArray ){ test(`Valid conversion in ${projArray[j]} + ${csArray[i]}`, async () => { - let output = M._pointToPCRSPoint(point, 0, projArray[j], csArray[i]); + let output = M.pointToPCRSPoint(point, 0, projArray[j], csArray[i]); await expect(output).toEqual(expected[i][j]); }); } @@ -412,19 +412,19 @@ describe("M.Util Tests", () => { /* jshint ignore:end */ test("Null point", async () => { - let output = M._pointToPCRSPoint(null, 0, "CBMTILE"); + let output = M.pointToPCRSPoint(null, 0, "CBMTILE"); await expect(output).toEqual(undefined); }); test("Null zoom", async () => { - let output = M._pointToPCRSPoint(point, null, "CBMTILE"); + let output = M.pointToPCRSPoint(point, null, "CBMTILE"); await expect(output).toEqual(undefined); }); test("Null projection", async () => { - let output = M._pointToPCRSPoint(point, 1, null); + let output = M.pointToPCRSPoint(point, 1, null); await expect(output).toEqual(undefined); }); test("Null cs", async () => { - let output = M._pointToPCRSPoint(point, 1, "CBMTILE", null); + let output = M.pointToPCRSPoint(point, 1, "CBMTILE", null); await expect(output).toEqual(undefined); }); }); From 0ed61a56b9ce1811e5beb449e56febebd3b90d13 Mon Sep 17 00:00:00 2001 From: AliyanH Date: Fri, 10 Feb 2023 09:05:28 -0500 Subject: [PATCH 3/3] minor comment changes --- src/mapml/features/feature.js | 2 +- src/mapml/utils/Util.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mapml/features/feature.js b/src/mapml/features/feature.js index 072251f60..414673630 100644 --- a/src/mapml/features/feature.js +++ b/src/mapml/features/feature.js @@ -72,7 +72,7 @@ export var Feature = L.Path.extend({ nextLayer = nextLayer.nextElementSibling; } if(onTop && dragStart) { - //M.handleLink gets called twice, once in the target phase on the path element, then in the bubble phase on the g element + //M._handleLink gets called twice, once in the target phase on the path element, then in the bubble phase on the g element //Using stopPropagation leaves the mouse in the mousedown state if(e.eventPhase === Event.BUBBLING_PHASE) return; let dist = Math.sqrt(Math.pow(dragStart.x - e.clientX, 2) + Math.pow(dragStart.y - e.clientY, 2)); diff --git a/src/mapml/utils/Util.js b/src/mapml/utils/Util.js index 2ce6df553..a9d39b80d 100644 --- a/src/mapml/utils/Util.js +++ b/src/mapml/utils/Util.js @@ -2,7 +2,7 @@ import { FALLBACK_CS, FALLBACK_PROJECTION } from './Constants'; export var Util = { // _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). - // _convertAndFormatPCRS: pcrsBounds, _map -> {...} + // _convertAndFormatPCRS: L.Bounds, _map -> {...} _convertAndFormatPCRS : function(pcrsBounds, map){ if(!pcrsBounds || !map) return {}; @@ -268,7 +268,7 @@ export var Util = { } }, - // pixelToPCRSPoint takes a L.point, the zoom and projection and returns a L.point in pcrs + // pixelToPCRSPoint takes a pixel L.point, the zoom and projection and returns a L.point in pcrs // pixelToPCRSPoint: L.Point, Int, L.CRS|Str -> L.point pixelToPCRSPoint: function(point, zoom, projection){ if(!point || (!zoom && zoom !== 0) || !Number.isFinite(+zoom) || !projection) return undefined;