Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Privatize global M. Methods which were not intended to become global #734

Merged
merged 5 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/map-area.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<coords.length;i+=2) {
points.push([parseInt(coords[i-1]),parseInt(coords[i])]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/mapml-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MapViewer extends HTMLElement {
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(),
Expand Down
8 changes: 4 additions & 4 deletions src/mapml/features/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ 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));
if (dist <= 5){
link.visited = true;
elem.setAttribute("stroke", "#6c00a2");
elem.classList.add("map-a-visited");
M.handleLink(link, leafletLayer);
M._handleLink(link, leafletLayer);
}
}
}, this);
Expand All @@ -90,7 +90,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) => {
Expand Down Expand Up @@ -289,7 +289,7 @@ 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);
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);
Expand Down
4 changes: 2 additions & 2 deletions src/mapml/handlers/AnnounceMovement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export var AnnounceMovement = L.Handler.extend({
mapEl.shadowRoot.querySelector(".leaflet-container");

let mapZoom = mapEl._map.getZoom();
let location = M.gcrsToTileMatrix(mapEl);
let location = M._gcrsToTileMatrix(mapEl);
let standard = M.options.locale.amZoom + " " + mapZoom + " " + M.options.locale.amColumn + " " + location[0] + " " + M.options.locale.amRow + " " + location[1];

if(mapZoom === mapEl._map._layersMaxZoom){
Expand Down Expand Up @@ -61,7 +61,7 @@ export var AnnounceMovement = L.Handler.extend({
this.shadowRoot.querySelector(".mapml-screen-reader-output");

//GCRS to TileMatrix
let location = M.gcrsToTileMatrix(this);
let location = M._gcrsToTileMatrix(this);
let standard = M.options.locale.amZoom + " " + mapZoom + " " + M.options.locale.amColumn + " " + location[0] + " " + M.options.locale.amRow + " " + location[1];

if(!visible){
Expand Down
18 changes: 9 additions & 9 deletions src/mapml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,23 +589,23 @@ 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._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._metaContentToObject = Util._metaContentToObject;
M._coordsToArray = Util._coordsToArray;
M._parseStylesheetAsHTML = Util._parseStylesheetAsHTML;
M.pointToPCRSPoint = Util.pointToPCRSPoint;
M.pixelToPCRSPoint = Util.pixelToPCRSPoint;
M.gcrsToTileMatrix = Util.gcrsToTileMatrix;
M._gcrsToTileMatrix = Util._gcrsToTileMatrix;
M._pasteLayer = Util._pasteLayer;
M._properties2Table = Util._properties2Table;
M._updateExtent = Util._updateExtent;
Expand Down
14 changes: 7 additions & 7 deletions src/mapml/layers/FeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export var FeatureLayer = 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};
},

Expand Down Expand Up @@ -115,13 +115,13 @@ export var FeatureLayer = 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;
Expand Down Expand Up @@ -189,8 +189,8 @@ export var FeatureLayer = 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,
Expand All @@ -216,7 +216,7 @@ export var FeatureLayer = 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++) {
Expand Down
14 changes: 7 additions & 7 deletions src/mapml/layers/MapMLLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,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;
}
Expand Down Expand Up @@ -333,7 +333,7 @@ export var MapMLLayer = L.Layer.extend({
if(bounds){
//assigns the formatted extent object to .extent and spreads the zoom ranges to .extent also
this._layerEl.extent = (Object.assign(
M.convertAndFormatPCRS(bounds,this._map),
M._convertAndFormatPCRS(bounds,this._map),
{zoom:zoomBounds}));
}
},
Expand Down Expand Up @@ -864,7 +864,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;

Expand Down Expand Up @@ -903,7 +903,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],
Expand Down Expand Up @@ -1019,7 +1019,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;
}
}
Expand Down Expand Up @@ -1087,7 +1087,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){
Expand Down Expand Up @@ -1194,7 +1194,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;
Expand Down
2 changes: 1 addition & 1 deletion src/mapml/layers/StaticTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export var StaticTileLayer = 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;
Expand Down
6 changes: 3 additions & 3 deletions src/mapml/layers/TemplatedFeaturesLayer.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/mapml/layers/TemplatedImageLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/mapml/layers/TemplatedLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])));
Expand Down
4 changes: 2 additions & 2 deletions src/mapml/layers/TemplatedTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading