Skip to content
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
28 changes: 9 additions & 19 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,8 @@ module.exports = function(grunt) {
},
dist: {
files: {
'dist/mapml.js': ['<%= rollup.main.dest %>'],
'dist/web-map.js': ['src/web-map.js'],
'dist/mapml-viewer.js': ['src/mapml-viewer.js'],
'dist/map-caption.js': ['src/map-caption.js'],
'dist/map-feature.js': ['src/map-feature.js'],
'dist/map-extent.js': ['src/map-extent.js'],
'dist/map-input.js': ['src/map-input.js'],
'dist/map-select.js': ['src/map-select.js'],
'dist/map-link.js': ['src/map-link.js'],
'dist/map-style.js': ['src/map-style.js'],
'dist/map-area.js': ['src/map-area.js'],
'dist/layer.js': ['src/layer.js'],
'dist/leaflet.js': ['dist/leaflet-src.js',
'dist/proj4-src.js',
'dist/proj4leaflet.js',
'dist/L.Control.Locate.js']
'dist/mapml-viewer.js': ['<%= rollup.main.dest %>'],
'dist/web-map.js': ['<%= rollup.webmap.dest %>']
}
}
},
Expand Down Expand Up @@ -187,7 +173,7 @@ module.exports = function(grunt) {
},
clean: {
dist: ['dist'],
tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js','dist/L.Control.Locate.js'],
tidyup: ['dist/leaflet-src.js','dist/proj4-src.js','dist/proj4leaflet.js','dist/L.Control.Locate.js','dist/mapmlviewer.js','dist/webmap.js'],
experiments: {
options: {force: true},
src: ['../experiments/dist']
Expand All @@ -207,13 +193,17 @@ module.exports = function(grunt) {
},
rollup: {
options: {
format: 'iife',
format: 'es',
plugins: [nodeResolve()],
external: './pmtilesRules.js'
},
main: {
dest: 'dist/mapml.js',
dest: 'dist/mapmlviewer.js',
src: 'src/mapml/index.js' // Only one source file is permitted
},
webmap: {
dest: 'dist/webmap.js',
src: 'src/mapml/index-web-map.js' // Only one source file is permitted
}
},
prettier: {
Expand Down
19 changes: 10 additions & 9 deletions src/layer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './leaflet.js'; // a lightly modified version of Leaflet for use as browser module
import './mapml.js'; // modified URI to make the function a property of window scope (possibly a bad thing to do).
import { Util } from './mapml/utils/Util';
import { MapMLLayer, mapMLLayer } from './mapml/layers/MapMLLayer';
import { createLayerControlHTML } from './mapml/elementSupport/layers/createLayerControlForLayer';

export class MapLayer extends HTMLElement {
static get observedAttributes() {
Expand Down Expand Up @@ -67,7 +68,7 @@ export class MapLayer extends HTMLElement {
}
return this._layer
? Object.assign(
M._convertAndFormatPCRS(
Util._convertAndFormatPCRS(
this._layer.bounds,
M[this.getProjection()],
this.getProjection()
Expand Down Expand Up @@ -165,7 +166,7 @@ export class MapLayer extends HTMLElement {
/* jshint ignore:start */
this.#hasConnected = true;
/* jshint ignore:end */
this._createLayerControlHTML = M._createLayerControlHTML.bind(this);
this._createLayerControlHTML = createLayerControlHTML.bind(this);
const doConnected = this._onAdd.bind(this);
const doRemove = this._onRemove.bind(this);
this.parentElement
Expand Down Expand Up @@ -241,7 +242,7 @@ export class MapLayer extends HTMLElement {
this.checkForPreferredContent();
})
.then(() => {
this._layer = M.mapMLLayer(new URL(this.src, base).href, this, {
this._layer = mapMLLayer(new URL(this.src, base).href, this, {
projection: this.getProjection(),
opacity: this.opacity
});
Expand Down Expand Up @@ -278,7 +279,7 @@ export class MapLayer extends HTMLElement {
this.checkForPreferredContent();
})
.then(() => {
this._layer = M.mapMLLayer(null, this, {
this._layer = mapMLLayer(null, this, {
projection: this.getProjection(),
opacity: this.opacity
});
Expand Down Expand Up @@ -398,7 +399,7 @@ export class MapLayer extends HTMLElement {
let projection = this.parentElement.projection;
if (mapml.querySelector('map-meta[name=projection][content]')) {
projection =
M._metaContentToObject(
Util._metaContentToObject(
mapml
.querySelector('map-meta[name=projection]')
.getAttribute('content')
Expand Down Expand Up @@ -793,13 +794,13 @@ export class MapLayer extends HTMLElement {

let maxZoom = extent.zoom.maxZoom,
minZoom = extent.zoom.minZoom;
map.setView(center, M.getMaxZoom(layerBounds, map, minZoom, maxZoom), {
map.setView(center, Util.getMaxZoom(layerBounds, map, minZoom, maxZoom), {
animate: false
});
});
}
mapml2geojson(options = {}) {
return M.mapml2geojson(this, options);
return Util.mapml2geojson(this, options);
}
pasteFeature(feature) {
switch (typeof feature) {
Expand Down
3 changes: 0 additions & 3 deletions src/map-area.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import './leaflet.js'; // a lightly modified version of Leaflet for use as browser module
import './mapml.js'; // refactored URI usage, replaced with URL standard

export class MapArea extends HTMLAreaElement {
static get observedAttributes() {
return ['coords', 'alt', 'href', 'shape', 'rel', 'type', 'target'];
Expand Down
20 changes: 12 additions & 8 deletions src/map-extent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Util } from './mapml/utils/Util';
import { extentLayer } from './mapml/layers/ExtentLayer';
import { createLayerControlExtentHTML } from './mapml/elementSupport/extents/createLayerControlForExtent';

/* global M */
export class MapExtent extends HTMLElement {
static get observedAttributes() {
Expand Down Expand Up @@ -54,7 +58,7 @@ export class MapExtent extends HTMLElement {
get extent() {
const getExtent = (extent) => {
return Object.assign(
M._convertAndFormatPCRS(
Util._convertAndFormatPCRS(
extent._extentLayer.bounds,
M[extent.units],
extent.units
Expand Down Expand Up @@ -121,16 +125,16 @@ export class MapExtent extends HTMLElement {
center = map.options.crs.unproject(bounds.getCenter(true)),
maxZoom = extent.zoom.maxZoom,
minZoom = extent.zoom.minZoom;
map.setView(center, M.getMaxZoom(bounds, map, minZoom, maxZoom), {
map.setView(center, Util.getMaxZoom(bounds, map, minZoom, maxZoom), {
animate: false
});
}

getMapEl() {
return M.getClosest(this, 'mapml-viewer,map[is=web-map]');
return Util.getClosest(this, 'mapml-viewer,map[is=web-map]');
}
getLayerEl() {
return M.getClosest(this, 'layer-');
return Util.getClosest(this, 'layer-');
}
attributeChangedCallback(name, oldValue, newValue) {
if (this.#hasConnected /* jshint ignore:line */) {
Expand Down Expand Up @@ -226,7 +230,7 @@ export class MapExtent extends HTMLElement {
// Always call super first in constructor
super();
this._createLayerControlExtentHTML =
M._createLayerControlExtentHTML.bind(this);
createLayerControlExtentHTML.bind(this);
this._changeHandler = this._handleChange.bind(this);
}
async connectedCallback() {
Expand Down Expand Up @@ -257,7 +261,7 @@ export class MapExtent extends HTMLElement {
// this._opacity is used to record the current opacity value (with or without updates),
// the initial value of this._opacity should be set as opacity attribute value, if exists, or the default value 1.0
this._opacity = this.opacity || 1.0;
this._extentLayer = M.extentLayer({
this._extentLayer = extentLayer({
opacity: this.opacity,
crs: M[this.units],
extentZIndex: Array.from(
Expand Down Expand Up @@ -493,12 +497,12 @@ export class MapExtent extends HTMLElement {

// initialize bounds from this.scope > map-meta
let bounds = this.querySelector(':scope > map-meta[name=extent][content]')
? M.getBoundsFromMeta(this) // TODO rewrite this pile of doo doo
? Util.getBoundsFromMeta(this) // TODO rewrite this pile of doo doo
: undefined;

// initialize zoom bounds from this.scope > map-meta
let zoomBounds = this.querySelector(':scope > map-meta[name=zoom][content]')
? M.getZoomBoundsFromMeta(this) // TODO rewrite this pile of doo doo
? Util.getZoomBoundsFromMeta(this) // TODO rewrite this pile of doo doo
: undefined;

// bounds should be able to be calculated unconditionally, not depend on map-extent.checked
Expand Down
37 changes: 21 additions & 16 deletions src/map-feature.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Util } from './mapml/utils/Util';

export class MapFeature extends HTMLElement {
static get observedAttributes() {
return ['zoom', 'min', 'max'];
Expand All @@ -10,7 +12,8 @@ export class MapFeature extends HTMLElement {
// for templated or queried features ** native zoom is only used for zoomTo() **
let meta = {},
metaEl = this.getMeta('zoom');
if (metaEl) meta = M._metaContentToObject(metaEl.getAttribute('content'));
if (metaEl)
meta = Util._metaContentToObject(metaEl.getAttribute('content'));
if (this._parentEl.nodeName === 'MAP-LINK') {
// nativeZoom = zoom attribute || (sd.map-meta zoom 'value' || 'max') || this._initialZoom
return +(this.hasAttribute('zoom')
Expand Down Expand Up @@ -43,7 +46,8 @@ export class MapFeature extends HTMLElement {
// for templated or queried features ** native zoom is only used for zoomTo() **
let meta = {},
metaEl = this.getMeta('zoom');
if (metaEl) meta = M._metaContentToObject(metaEl.getAttribute('content'));
if (metaEl)
meta = Util._metaContentToObject(metaEl.getAttribute('content'));
let projectionMinZoom = 0;
if (this._parentEl.nodeName === 'MAP-LINK') {
// minZoom = min attribute || sd.map-meta min zoom || map-link minZoom
Expand Down Expand Up @@ -82,7 +86,8 @@ export class MapFeature extends HTMLElement {
// for templated or queried features ** native zoom is only used for zoomTo() **
let meta = {},
metaEl = this.getMeta('zoom');
if (metaEl) meta = M._metaContentToObject(metaEl.getAttribute('content'));
if (metaEl)
meta = Util._metaContentToObject(metaEl.getAttribute('content'));
let projectionMaxZoom =
this.getMapEl()._map.options.crs.options.resolutions.length - 1;
if (this._parentEl.nodeName === 'MAP-LINK') {
Expand Down Expand Up @@ -129,10 +134,10 @@ export class MapFeature extends HTMLElement {
}
}
getMapEl() {
return M.getClosest(this, 'mapml-viewer,map[is=web-map]');
return Util.getClosest(this, 'mapml-viewer,map[is=web-map]');
}
getLayerEl() {
return M.getClosest(this, 'layer-');
return Util.getClosest(this, 'layer-');
}

attributeChangedCallback(name, oldValue, newValue) {
Expand Down Expand Up @@ -231,7 +236,7 @@ export class MapFeature extends HTMLElement {
// layerToRemoveFrom is the L.LayerGroup or L.FeatureGroup to remove this
// feature from...
layerToRemoveFrom.removeLayer(this._geometry);
// TODO: MOVE THIS LOGIC TO layerToRemoveFrom.removeLayer(M.Geometry)
// TODO: MOVE THIS LOGIC TO layerToRemoveFrom.removeLayer(Geometry)
// if (layerToRemoveFrom._staticFeature) {
// if (layerToRemoveFrom._features[this.zoom]) {
// this._removeInFeatureList(this.zoom);
Expand Down Expand Up @@ -302,7 +307,7 @@ export class MapFeature extends HTMLElement {
// the fallback 'gcrs' SHOULD be specified by the MapML spec
// per https://github.com/Maps4HTML/MapML/issues/257
return csMeta
? M._metaContentToObject(csMeta.getAttribute('content')).content
? Util._metaContentToObject(csMeta.getAttribute('content')).content
: 'gcrs';
}

Expand Down Expand Up @@ -341,7 +346,7 @@ export class MapFeature extends HTMLElement {
}
let topLeft = L.point(bboxExtent[0], bboxExtent[1]);
let bottomRight = L.point(bboxExtent[2], bboxExtent[3]);
let pcrsBound = M.boundsToPCRSBounds(
let pcrsBound = Util.boundsToPCRSBounds(
L.bounds(topLeft, bottomRight),
zoom,
map.options.projection,
Expand All @@ -360,14 +365,14 @@ export class MapFeature extends HTMLElement {
pcrsBound.min,
M[projection].scale(+this.zoom || maxZoom)
);
pcrsBound = M.pixelToPCRSBounds(
pcrsBound = Util.pixelToPCRSBounds(
L.bounds(pixel.subtract(tileCenter), pixel.add(tileCenter)),
this.zoom || maxZoom,
projection
);
}
let result = Object.assign(
M._convertAndFormatPCRS(
Util._convertAndFormatPCRS(
pcrsBound,
map.options.crs,
map.options.projection
Expand All @@ -389,14 +394,14 @@ export class MapFeature extends HTMLElement {
.split(/[<>\ ]/g);
switch (shape.tagName.toUpperCase()) {
case 'MAP-POINT':
bboxExtent = M._updateExtent(bboxExtent, +data[0], +data[1]);
bboxExtent = Util._updateExtent(bboxExtent, +data[0], +data[1]);
break;
case 'MAP-LINESTRING':
case 'MAP-POLYGON':
case 'MAP-MULTIPOINT':
case 'MAP-MULTILINESTRING':
for (let i = 0; i < data.length; i += 2) {
bboxExtent = M._updateExtent(bboxExtent, +data[i], +data[i + 1]);
bboxExtent = Util._updateExtent(bboxExtent, +data[i], +data[i + 1]);
}
break;
default:
Expand Down Expand Up @@ -433,7 +438,7 @@ export class MapFeature extends HTMLElement {
newZoom = this.zoom;
} else {
// if not, calculate the maximum zoom level that can show the feature completely
newZoom = M.getMaxZoom(bound, this.getMapEl()._map, minZoom, maxZoom);
newZoom = Util.getMaxZoom(bound, this.getMapEl()._map, minZoom, maxZoom);
if (this.max < newZoom) {
// if the calculated zoom is greater than the value of max zoom attribute, go with max zoom attribute
newZoom = this.max;
Expand Down Expand Up @@ -495,7 +500,7 @@ export class MapFeature extends HTMLElement {
} else if (el.querySelector('table')) {
// setting properties when table presented
let table = el.querySelector('table').cloneNode(true);
json.properties = M._table2properties(table);
json.properties = Util._table2properties(table);
} else {
// when no table present, strip any possible html tags to only get text
json.properties = {
Expand Down Expand Up @@ -530,11 +535,11 @@ export class MapFeature extends HTMLElement {
json.geometry.geometries = [];
for (let shape of shapes) {
json.geometry.geometries.push(
M._geometry2geojson(shape, source, dest, options.transform)
Util._geometry2geojson(shape, source, dest, options.transform)
);
}
} else {
json.geometry = M._geometry2geojson(
json.geometry = Util._geometry2geojson(
shapes[0],
source,
dest,
Expand Down
Loading