@superrouteca/smap 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +136 -4
- package/dist/SOURCE.json +8 -8
- package/dist/smap-client.cjs +2 -2
- package/dist/smap-client.js +2 -2
- package/dist/smap-client.mjs +2 -2
- package/dist/smap.cjs +637 -31
- package/dist/smap.css +54 -0
- package/dist/smap.js +628 -29
- package/dist/smap.mjs +637 -32
- package/package.json +1 -1
- package/types/smap.d.cts +111 -6
- package/types/smap.d.mts +111 -6
package/dist/smap.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* Generated by js/build.mjs from js/src (see SOURCE.json). Do not edit. */
|
|
2
|
-
/*! sMap Web SDK 1.0.
|
|
2
|
+
/*! sMap Web SDK 1.0.5. Bundles maplibre-gl 6.16.0 (BSD-3-Clause), see vendor-licenses.txt. */
|
|
3
3
|
|
|
4
4
|
var smapCore = null;
|
|
5
5
|
function smapCreateEngine() {
|
|
6
|
+
var SMAP_BASE_URL = (typeof document !== 'undefined' && document.baseURI) || (typeof location !== 'undefined' && location.href) || 'about:blank';
|
|
6
7
|
var smapEngineExports = (() => {
|
|
7
8
|
var __defProp = Object.defineProperty;
|
|
8
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -4598,7 +4599,7 @@ Use an identity property function instead: \`{ "type": "identity", "property": $
|
|
|
4598
4599
|
}
|
|
4599
4600
|
}
|
|
4600
4601
|
function el() {
|
|
4601
|
-
let e66 =
|
|
4602
|
+
let e66 = SMAP_BASE_URL;
|
|
4602
4603
|
if (!/^https?:/.test(e66)) return ``;
|
|
4603
4604
|
let t2 = e66.endsWith(`-dev.mjs`) ? `maplibre-gl-worker-dev.mjs` : `maplibre-gl-worker.mjs`, n2 = new URL(`./${t2}`, e66);
|
|
4604
4605
|
return n2.searchParams.set(`v`, l), n2.href;
|
|
@@ -4621,7 +4622,7 @@ Use an identity property function instead: \`{ "type": "identity", "property": $
|
|
|
4621
4622
|
return URL.createObjectURL(r2);
|
|
4622
4623
|
}
|
|
4623
4624
|
function il(e66) {
|
|
4624
|
-
let t2 = new Blob([`import ${JSON.stringify(new URL(e66,
|
|
4625
|
+
let t2 = new Blob([`import ${JSON.stringify(new URL(e66, SMAP_BASE_URL).href)}`], { type: `text/javascript` });
|
|
4625
4626
|
return URL.createObjectURL(t2);
|
|
4626
4627
|
}
|
|
4627
4628
|
async function al() {
|
|
@@ -26864,14 +26865,14 @@ function smapCreateSdk(engine) {
|
|
|
26864
26865
|
*/
|
|
26865
26866
|
(function (root, factory) {
|
|
26866
26867
|
if (typeof module === 'object' && module.exports) {
|
|
26867
|
-
module.exports = factory(root.maplibregl
|
|
26868
|
+
module.exports = factory(root.maplibregl !== undefined ? root.maplibregl : require('maplibre-gl'));
|
|
26868
26869
|
} else {
|
|
26869
26870
|
root.sMap = factory(root.maplibregl);
|
|
26870
26871
|
}
|
|
26871
26872
|
})(typeof self !== 'undefined' ? self : this, function (engine) {
|
|
26872
26873
|
'use strict';
|
|
26873
26874
|
|
|
26874
|
-
var VERSION = '1.0.
|
|
26875
|
+
var VERSION = '1.0.5';
|
|
26875
26876
|
var FLAVORS = ['light', 'white', 'grayscale', 'dark', 'black'];
|
|
26876
26877
|
var BASEMAP_SOURCE = 'basemap';
|
|
26877
26878
|
var BUILDINGS_LAYER = 'smap-buildings-3d';
|
|
@@ -26970,6 +26971,203 @@ function smapCreateSdk(engine) {
|
|
|
26970
26971
|
};
|
|
26971
26972
|
}
|
|
26972
26973
|
|
|
26974
|
+
// ------------------------------------------------------------------ popups
|
|
26975
|
+
|
|
26976
|
+
var POPUP_OPTIONS = ['className', 'maxWidth', 'minWidth', 'offset', 'anchor', 'closeButton', 'closeOnClick', 'focusAfterOpen', 'autoPan'];
|
|
26977
|
+
// Shown while a popup's content is on its way: three pulsing dots, no text.
|
|
26978
|
+
var POPUP_LOADING = '<div class="smap-popup-loading" role="status"><span></span><span></span><span></span></div>';
|
|
26979
|
+
var HTML_ESCAPES = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
26980
|
+
|
|
26981
|
+
function escapeHtml(value) {
|
|
26982
|
+
return String(value).replace(/[&<>"']/g, function (c) { return HTML_ESCAPES[c]; });
|
|
26983
|
+
}
|
|
26984
|
+
|
|
26985
|
+
/**
|
|
26986
|
+
* A popup function from a template: every {name} is replaced by the feature's property of that name, HTML-escaped
|
|
26987
|
+
* (empty when the feature has none). The template itself is trusted HTML. Compiled once; nothing runs until a click.
|
|
26988
|
+
* popupTemplate('<b>{name}</b><br>{address}')
|
|
26989
|
+
*/
|
|
26990
|
+
function popupTemplate(template) {
|
|
26991
|
+
// Even entries are the template's own text, odd entries property names.
|
|
26992
|
+
var parts = String(template).split(/\{([^{}]+)\}/);
|
|
26993
|
+
for (var i = 1; i < parts.length; i += 2) { parts[i] = parts[i].trim(); }
|
|
26994
|
+
return function (properties) {
|
|
26995
|
+
var out = parts[0];
|
|
26996
|
+
for (var j = 1; j < parts.length; j += 2) {
|
|
26997
|
+
var v = properties ? properties[parts[j]] : undefined;
|
|
26998
|
+
out += (v === undefined || v === null ? '' : escapeHtml(v)) + parts[j + 1];
|
|
26999
|
+
}
|
|
27000
|
+
return out;
|
|
27001
|
+
};
|
|
27002
|
+
}
|
|
27003
|
+
|
|
27004
|
+
function isThenable(v) { return !!v && (typeof v === 'object' || typeof v === 'function') && typeof v.then === 'function'; }
|
|
27005
|
+
|
|
27006
|
+
function cssSize(v) { return typeof v === 'number' ? v + 'px' : v; }
|
|
27007
|
+
|
|
27008
|
+
// ------------------------------------------------------------------ drawn images (pins, numbers, badges, arrows)
|
|
27009
|
+
|
|
27010
|
+
// A style value: a constant, {property: 'name'} (the feature's property, `default` when it has none), or an engine
|
|
27011
|
+
// expression (an array).
|
|
27012
|
+
function valueExpr(v, fallback) {
|
|
27013
|
+
if (v === undefined || v === null) { return fallback; }
|
|
27014
|
+
if (Array.isArray(v)) { return v; }
|
|
27015
|
+
if (typeof v === 'object' && v.property) {
|
|
27016
|
+
return v['default'] !== undefined ? ['coalesce', ['get', v.property], v['default']] : ['get', v.property];
|
|
27017
|
+
}
|
|
27018
|
+
return v;
|
|
27019
|
+
}
|
|
27020
|
+
|
|
27021
|
+
// Image ids carry what the image shows; the map draws each one the first time a feature needs it (see _drawImage).
|
|
27022
|
+
var IMAGE_PREFIX = 'smap-img|';
|
|
27023
|
+
var SQRT1_2 = Math.SQRT1_2;
|
|
27024
|
+
|
|
27025
|
+
// The pin of Superroute's route map: a square with three rounded corners turned 45 degrees, its sharp corner the tip.
|
|
27026
|
+
// tipToHead: from the position up to the centre of the round part (where the number goes); badge: the badge's centre
|
|
27027
|
+
// from the position (right of the round part, as the page's badge sits on the turned pin's corner).
|
|
27028
|
+
function markerGeometry(shape, size) {
|
|
27029
|
+
var k = size / 32;
|
|
27030
|
+
if (shape === 'circle') {
|
|
27031
|
+
return { k: k, tipToHead: 0, badge: [size * 0.36, -size * 0.36] };
|
|
27032
|
+
}
|
|
27033
|
+
var half = size * SQRT1_2; // the centre of the round part, above the tip
|
|
27034
|
+
return { k: k, tipToHead: half, badge: [14.1 * k, -half] };
|
|
27035
|
+
}
|
|
27036
|
+
|
|
27037
|
+
// A rounded rectangle path whose corners are ellipses: radii [[rx, ry] top-left, top-right, bottom-right, bottom-left].
|
|
27038
|
+
function roundedPath(ctx, x, y, w, h, r) {
|
|
27039
|
+
ctx.beginPath();
|
|
27040
|
+
ctx.moveTo(x + r[0][0], y);
|
|
27041
|
+
ctx.lineTo(x + w - r[1][0], y);
|
|
27042
|
+
if (r[1][0] && r[1][1]) { ctx.ellipse(x + w - r[1][0], y + r[1][1], r[1][0], r[1][1], 0, -Math.PI / 2, 0); }
|
|
27043
|
+
ctx.lineTo(x + w, y + h - r[2][1]);
|
|
27044
|
+
if (r[2][0] && r[2][1]) { ctx.ellipse(x + w - r[2][0], y + h - r[2][1], r[2][0], r[2][1], 0, 0, Math.PI / 2); }
|
|
27045
|
+
ctx.lineTo(x + r[3][0], y + h);
|
|
27046
|
+
if (r[3][0] && r[3][1]) { ctx.ellipse(x + r[3][0], y + h - r[3][1], r[3][0], r[3][1], 0, Math.PI / 2, Math.PI); }
|
|
27047
|
+
ctx.lineTo(x, y + r[0][1]);
|
|
27048
|
+
if (r[0][0] && r[0][1]) { ctx.ellipse(x + r[0][0], y + r[0][1], r[0][0], r[0][1], 0, Math.PI, Math.PI * 1.5); }
|
|
27049
|
+
ctx.closePath();
|
|
27050
|
+
}
|
|
27051
|
+
|
|
27052
|
+
var PIN_PAD = 6; // room for the shadow around a pin, in pixels
|
|
27053
|
+
|
|
27054
|
+
// Each draw function gets a 2D context already scaled to the pixel ratio and returns nothing; sizes are in pixels.
|
|
27055
|
+
var IMAGE_KINDS = {
|
|
27056
|
+
// pin|shape|fill|border|borderWidth|size
|
|
27057
|
+
pin: function (args) {
|
|
27058
|
+
var shape = args[0], fill = args[1], border = args[2], bw = Number(args[3]), size = Number(args[4]);
|
|
27059
|
+
var g = markerGeometry(shape, size);
|
|
27060
|
+
var reach = shape === 'circle' ? size / 2 : g.tipToHead; // farthest the shape goes from its centre
|
|
27061
|
+
var w = Math.ceil(2 * reach + 2 * PIN_PAD), h = w;
|
|
27062
|
+
return {
|
|
27063
|
+
width: w, height: h,
|
|
27064
|
+
draw: function (ctx, ratio) {
|
|
27065
|
+
var c = w / 2;
|
|
27066
|
+
ctx.save();
|
|
27067
|
+
ctx.translate(c, c);
|
|
27068
|
+
var s = size / 2;
|
|
27069
|
+
var outer, inner;
|
|
27070
|
+
if (shape === 'circle') {
|
|
27071
|
+
outer = function () { ctx.beginPath(); ctx.arc(0, 0, s, 0, Math.PI * 2); };
|
|
27072
|
+
inner = function () { ctx.beginPath(); ctx.arc(0, 0, Math.max(0, s - bw), 0, Math.PI * 2); };
|
|
27073
|
+
ctx.shadowOffsetY = 3 * ratio;
|
|
27074
|
+
} else {
|
|
27075
|
+
ctx.rotate(Math.PI / 4);
|
|
27076
|
+
outer = function () { roundedPath(ctx, -s, -s, size, size, [[s, s], [s, size], [0, 0], [size, s]]); };
|
|
27077
|
+
var t = Math.max(0, s - bw), r2 = Math.max(0, size - bw);
|
|
27078
|
+
inner = function () { roundedPath(ctx, -s + bw, -s + bw, size - 2 * bw, size - 2 * bw, [[t, t], [t, r2], [0, 0], [r2, t]]); };
|
|
27079
|
+
// The page's box-shadow (0 3px) turns with the pin.
|
|
27080
|
+
ctx.shadowOffsetX = -3 * SQRT1_2 * ratio;
|
|
27081
|
+
ctx.shadowOffsetY = 3 * SQRT1_2 * ratio;
|
|
27082
|
+
}
|
|
27083
|
+
ctx.shadowColor = 'rgba(0,0,0,0.3)';
|
|
27084
|
+
ctx.shadowBlur = 8 * ratio;
|
|
27085
|
+
outer();
|
|
27086
|
+
ctx.fillStyle = border;
|
|
27087
|
+
ctx.fill();
|
|
27088
|
+
ctx.shadowColor = 'transparent';
|
|
27089
|
+
inner();
|
|
27090
|
+
ctx.fillStyle = fill;
|
|
27091
|
+
ctx.fill();
|
|
27092
|
+
ctx.restore();
|
|
27093
|
+
},
|
|
27094
|
+
};
|
|
27095
|
+
},
|
|
27096
|
+
// num|color|size|text (bold, with the route map's text shadow)
|
|
27097
|
+
num: function (args, measure) {
|
|
27098
|
+
var color = args[0], size = Number(args[1]), text = args.slice(2).join('|');
|
|
27099
|
+
var px = 14 * size / 32;
|
|
27100
|
+
var font = 'bold ' + px + 'px monospace';
|
|
27101
|
+
var w = Math.ceil(measure(font, text) + 6), h = Math.ceil(px * 1.4 + 4);
|
|
27102
|
+
return {
|
|
27103
|
+
width: w, height: h,
|
|
27104
|
+
draw: function (ctx, ratio) {
|
|
27105
|
+
ctx.font = font;
|
|
27106
|
+
ctx.textAlign = 'center';
|
|
27107
|
+
ctx.textBaseline = 'middle';
|
|
27108
|
+
ctx.shadowColor = 'rgba(0,0,0,0.5)';
|
|
27109
|
+
ctx.shadowOffsetX = ratio;
|
|
27110
|
+
ctx.shadowOffsetY = ratio;
|
|
27111
|
+
ctx.shadowBlur = 2 * ratio;
|
|
27112
|
+
ctx.fillStyle = color;
|
|
27113
|
+
ctx.fillText(text, w / 2, h / 2);
|
|
27114
|
+
},
|
|
27115
|
+
};
|
|
27116
|
+
},
|
|
27117
|
+
// badge|text (red circle, white border, at least 18 px inside the border)
|
|
27118
|
+
badge: function (args, measure) {
|
|
27119
|
+
var text = args.join('|');
|
|
27120
|
+
var font = 'bold 10px sans-serif';
|
|
27121
|
+
var inner = Math.max(18, Math.ceil(measure(font, text) + 4));
|
|
27122
|
+
var w = inner + 4 + 6, h = 18 + 4 + 6;
|
|
27123
|
+
return {
|
|
27124
|
+
width: w, height: h,
|
|
27125
|
+
draw: function (ctx, ratio) {
|
|
27126
|
+
var bw = inner + 4, bh = 22, x = 3, y = 2;
|
|
27127
|
+
var r = bh / 2;
|
|
27128
|
+
ctx.shadowColor = 'rgba(0,0,0,0.4)';
|
|
27129
|
+
ctx.shadowOffsetY = 2 * ratio;
|
|
27130
|
+
ctx.shadowBlur = 4 * ratio;
|
|
27131
|
+
roundedPath(ctx, x, y, bw, bh, [[r, r], [r, r], [r, r], [r, r]]);
|
|
27132
|
+
ctx.fillStyle = '#ffffff';
|
|
27133
|
+
ctx.fill();
|
|
27134
|
+
ctx.shadowColor = 'transparent';
|
|
27135
|
+
roundedPath(ctx, x + 2, y + 2, bw - 4, bh - 4, [[r - 2, r - 2], [r - 2, r - 2], [r - 2, r - 2], [r - 2, r - 2]]);
|
|
27136
|
+
ctx.fillStyle = '#e74c3c';
|
|
27137
|
+
ctx.fill();
|
|
27138
|
+
ctx.font = font;
|
|
27139
|
+
ctx.textAlign = 'center';
|
|
27140
|
+
ctx.textBaseline = 'middle';
|
|
27141
|
+
ctx.fillStyle = '#ffffff';
|
|
27142
|
+
ctx.fillText(text, x + bw / 2, y + bh / 2 + 0.5);
|
|
27143
|
+
},
|
|
27144
|
+
};
|
|
27145
|
+
},
|
|
27146
|
+
// arrow|size|color (an open arrowhead pointing along the line, like the route map's)
|
|
27147
|
+
arrow: function (args) {
|
|
27148
|
+
var size = Number(args[0]), color = args.slice(1).join('|');
|
|
27149
|
+
var w = Math.ceil(size + 4), h = w;
|
|
27150
|
+
return {
|
|
27151
|
+
width: w, height: h,
|
|
27152
|
+
draw: function (ctx) {
|
|
27153
|
+
var len = size, back = len * Math.cos(Math.PI / 6), half = len * Math.sin(Math.PI / 6);
|
|
27154
|
+
var tipX = w / 2 + back / 2, cy = h / 2;
|
|
27155
|
+
ctx.strokeStyle = color;
|
|
27156
|
+
ctx.lineWidth = 2;
|
|
27157
|
+
ctx.lineCap = 'round';
|
|
27158
|
+
ctx.lineJoin = 'round';
|
|
27159
|
+
ctx.beginPath();
|
|
27160
|
+
ctx.moveTo(tipX - back, cy - half);
|
|
27161
|
+
ctx.lineTo(tipX, cy);
|
|
27162
|
+
ctx.lineTo(tipX - back, cy + half);
|
|
27163
|
+
ctx.stroke();
|
|
27164
|
+
},
|
|
27165
|
+
};
|
|
27166
|
+
},
|
|
27167
|
+
};
|
|
27168
|
+
|
|
27169
|
+
function drawnImageId(kind, parts) { return ['concat', IMAGE_PREFIX + kind].concat(parts.reduce(function (a, p) { return a.concat(['|', p]); }, [])); }
|
|
27170
|
+
|
|
26973
27171
|
var NODE_TTL = 3600 * 1000;
|
|
26974
27172
|
|
|
26975
27173
|
function timed(url, ms) {
|
|
@@ -27050,6 +27248,9 @@ function smapCreateSdk(engine) {
|
|
|
27050
27248
|
* @param {boolean} [options.nearest=true] read from the nearest sMap node (asked of baseUrl, remembered for an hour)
|
|
27051
27249
|
* @param {string[]} [options.nodes] node URLs known in advance, used while baseUrl is down
|
|
27052
27250
|
* @param {'mercator'|'globe'} [options.projection]
|
|
27251
|
+
* @param {Object} [options.popup] default popup options of every layer and openPopup (className, maxWidth,
|
|
27252
|
+
* minWidth, offset, anchor, closeButton, closeOnClick, focusAfterOpen)
|
|
27253
|
+
* @param {string|Node} [options.popupLoading] shown while a popup's content is a pending promise (default: dots)
|
|
27053
27254
|
* Every other option (center, zoom, pitch, bearing, minZoom, maxZoom, maxBounds, hash, …) goes to the engine.
|
|
27054
27255
|
*/
|
|
27055
27256
|
function SMap(options) {
|
|
@@ -27069,6 +27270,12 @@ function smapCreateSdk(engine) {
|
|
|
27069
27270
|
this._buildings = false;
|
|
27070
27271
|
this._handlers = {};
|
|
27071
27272
|
this._refreshTimer = null;
|
|
27273
|
+
this._popupDefaults = options.popup || {};
|
|
27274
|
+
this._popupLoading = options.popupLoading;
|
|
27275
|
+
this._autoZoom = options.autoZoom !== false;
|
|
27276
|
+
this._wasd = options.keyboard3D;
|
|
27277
|
+
this._popup = null;
|
|
27278
|
+
this._popupSeq = 0;
|
|
27072
27279
|
// True between a style's load and the next style change. The engine's own isStyleLoaded() turns false while any
|
|
27073
27280
|
// source is loading data, which would leave layers added meanwhile waiting for a load that never comes.
|
|
27074
27281
|
this._styleReady = false;
|
|
@@ -27076,7 +27283,7 @@ function smapCreateSdk(engine) {
|
|
|
27076
27283
|
var self = this;
|
|
27077
27284
|
var engineOptions = {};
|
|
27078
27285
|
for (var k in options) {
|
|
27079
|
-
if (Object.prototype.hasOwnProperty.call(options, k) && ['token', 'getToken', 'apiKey', 'style', 'language', 'baseUrl', 'projection', 'nearest', 'nodes'].indexOf(k) < 0) {
|
|
27286
|
+
if (Object.prototype.hasOwnProperty.call(options, k) && ['token', 'getToken', 'apiKey', 'style', 'language', 'baseUrl', 'projection', 'nearest', 'nodes', 'popup', 'popupLoading', 'autoZoom', 'keyboard3D'].indexOf(k) < 0) {
|
|
27080
27287
|
engineOptions[k] = options[k];
|
|
27081
27288
|
}
|
|
27082
27289
|
}
|
|
@@ -27109,6 +27316,14 @@ function smapCreateSdk(engine) {
|
|
|
27109
27316
|
badge._place();
|
|
27110
27317
|
}
|
|
27111
27318
|
self.engine.on('style.load', function () { self._styleReady = true; self._restore(); });
|
|
27319
|
+
self._keyboard3D();
|
|
27320
|
+
// One click handler for every layer's popup: the engine's hit test over those layers, the top feature opens.
|
|
27321
|
+
self.engine.on('click', function (e) { self._popupClick(e); });
|
|
27322
|
+
self._styleClass();
|
|
27323
|
+
// Pins, numbers, badges and arrows are drawn the first time a feature needs one (and again after a style change).
|
|
27324
|
+
if (self.engine.setMissingStyleImageResolver) {
|
|
27325
|
+
self.engine.setMissingStyleImageResolver(function (id) { self._drawImage(id); });
|
|
27326
|
+
}
|
|
27112
27327
|
return new Promise(function (resolve) { self.engine.once('load', function () { resolve(self); }); });
|
|
27113
27328
|
});
|
|
27114
27329
|
if (this._token && this._getToken) { this._scheduleRefresh(); }
|
|
@@ -27144,10 +27359,242 @@ function smapCreateSdk(engine) {
|
|
|
27144
27359
|
if (FLAVORS.indexOf(style) >= 0) { this._flavor = style; this._customStyle = null; } else { this._customStyle = style; }
|
|
27145
27360
|
this._styleReady = false;
|
|
27146
27361
|
this.engine.setStyle(this._styleUrl());
|
|
27362
|
+
this._styleClass();
|
|
27363
|
+
return this;
|
|
27364
|
+
};
|
|
27365
|
+
|
|
27366
|
+
// The map container carries smap-style-<scheme>, so the stylesheet can follow the scheme (dark popups).
|
|
27367
|
+
SMap.prototype._styleClass = function () {
|
|
27368
|
+
var c = this.engine && this.engine.getContainer && this.engine.getContainer();
|
|
27369
|
+
if (!c || !c.classList) { return; }
|
|
27370
|
+
for (var i = 0; i < FLAVORS.length; i++) { c.classList.remove('smap-style-' + FLAVORS[i]); }
|
|
27371
|
+
if (!this._customStyle) { c.classList.add('smap-style-' + this._flavor); }
|
|
27372
|
+
};
|
|
27373
|
+
|
|
27374
|
+
// Draws an image the SDK named (IMAGE_PREFIX + kind|args) and adds it to the map; other names are left alone.
|
|
27375
|
+
SMap.prototype._drawImage = function (id) {
|
|
27376
|
+
if (typeof id !== 'string' || id.indexOf(IMAGE_PREFIX) !== 0) { return; }
|
|
27377
|
+
var m = this.engine;
|
|
27378
|
+
if (m.hasImage(id)) { return; }
|
|
27379
|
+
var parts = id.slice(IMAGE_PREFIX.length).split('|');
|
|
27380
|
+
var kind = IMAGE_KINDS[parts[0]];
|
|
27381
|
+
if (!kind) { return; }
|
|
27382
|
+
var doc = m.getContainer().ownerDocument;
|
|
27383
|
+
var win = doc.defaultView || {};
|
|
27384
|
+
var ratio = Math.min(3, Math.max(1, Math.ceil(win.devicePixelRatio || 1)));
|
|
27385
|
+
var canvas = doc.createElement('canvas');
|
|
27386
|
+
var ctx = canvas.getContext('2d');
|
|
27387
|
+
var measure = function (font, text) { ctx.font = font; return ctx.measureText(text).width; };
|
|
27388
|
+
var image = kind(parts.slice(1), measure);
|
|
27389
|
+
canvas.width = Math.ceil(image.width * ratio);
|
|
27390
|
+
canvas.height = Math.ceil(image.height * ratio);
|
|
27391
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
|
27392
|
+
image.draw(ctx, ratio);
|
|
27393
|
+
m.addImage(id, ctx.getImageData(0, 0, canvas.width, canvas.height), { pixelRatio: ratio });
|
|
27394
|
+
this._imagesDrawn = (this._imagesDrawn || 0) + 1;
|
|
27395
|
+
};
|
|
27396
|
+
|
|
27397
|
+
/**
|
|
27398
|
+
* Opens the map's popup at a position, closing the one open before (there is one popup per map).
|
|
27399
|
+
* @param {Array|Object} lngLat [lng, lat] or {lng, lat}
|
|
27400
|
+
* @param {string|Node|Promise} content trusted HTML (inserted as is, never sanitized), a DOM node, or a promise
|
|
27401
|
+
* of either (popupLoading shows meanwhile; a rejection closes the popup
|
|
27402
|
+
* and is reported as the map's 'error' event)
|
|
27403
|
+
* @param {Object} [options] popup options over the map's `popup` defaults, and `loading`
|
|
27404
|
+
*/
|
|
27405
|
+
SMap.prototype.openPopup = function (lngLat, content, options) {
|
|
27406
|
+
var self = this;
|
|
27407
|
+
if (!this.engine) { this.ready.then(function () { self.openPopup(lngLat, content, options); }); return this; }
|
|
27408
|
+
this.closePopup();
|
|
27409
|
+
if (!content) { return this; }
|
|
27410
|
+
var seq = ++this._popupSeq;
|
|
27411
|
+
var o = Object.assign({}, this._popupDefaults, options || {});
|
|
27412
|
+
var engineOptions = { offset: 12, className: 'smap-popup' + (o.className ? ' ' + o.className : '') };
|
|
27413
|
+
for (var i = 0; i < POPUP_OPTIONS.length; i++) {
|
|
27414
|
+
var k = POPUP_OPTIONS[i];
|
|
27415
|
+
if (k !== 'className' && k !== 'minWidth' && k !== 'autoPan' && o[k] !== undefined) { engineOptions[k] = k === 'maxWidth' ? cssSize(o[k]) : o[k]; }
|
|
27416
|
+
}
|
|
27417
|
+
var popup = new engine.Popup(engineOptions).setLngLat(lngLat);
|
|
27418
|
+
this._popup = popup;
|
|
27419
|
+
var pending = isThenable(content);
|
|
27420
|
+
var loading = o.loading !== undefined ? o.loading : (this._popupLoading !== undefined ? this._popupLoading : POPUP_LOADING);
|
|
27421
|
+
this._popupContent(popup, pending ? loading : content);
|
|
27422
|
+
popup.addTo(this.engine);
|
|
27423
|
+
var el = popup.getElement && popup.getElement();
|
|
27424
|
+
if (el && o.minWidth !== undefined) { el.style.minWidth = cssSize(o.minWidth); }
|
|
27425
|
+
if (o.autoPan !== false) {
|
|
27426
|
+
// After the engine has placed it (next frame), so its box is final.
|
|
27427
|
+
var raf = (typeof requestAnimationFrame === 'function') ? requestAnimationFrame : function (fn) { return setTimeout(fn, 16); };
|
|
27428
|
+
raf(function () { if (self._popup === popup) { self._panIntoView(popup); } });
|
|
27429
|
+
}
|
|
27430
|
+
if (pending) {
|
|
27431
|
+
content.then(function (answer) {
|
|
27432
|
+
// A later popup, or a close, makes this answer stale.
|
|
27433
|
+
if (seq !== self._popupSeq || self._popup !== popup) { return; }
|
|
27434
|
+
if (answer) { self._popupContent(popup, answer); } else { self.closePopup(); }
|
|
27435
|
+
}, function (error) {
|
|
27436
|
+
if (seq !== self._popupSeq || self._popup !== popup) { return; }
|
|
27437
|
+
self.closePopup();
|
|
27438
|
+
self._reportError(error);
|
|
27439
|
+
});
|
|
27440
|
+
}
|
|
27441
|
+
return this;
|
|
27442
|
+
};
|
|
27443
|
+
|
|
27444
|
+
/** Pans the map so the popup is fully inside it, with a small margin (Leaflet's autoPan). */
|
|
27445
|
+
SMap.prototype._panIntoView = function (popup) {
|
|
27446
|
+
var m = this.engine, el = popup.getElement && popup.getElement();
|
|
27447
|
+
if (!el || !m.getContainer || !m.panBy || !el.getBoundingClientRect) { return; }
|
|
27448
|
+
var box = el.getBoundingClientRect(), frame = m.getContainer().getBoundingClientRect(), pad = 10, dx = 0, dy = 0;
|
|
27449
|
+
if (box.top < frame.top + pad) { dy = box.top - frame.top - pad; } else if (box.bottom > frame.bottom - pad) { dy = box.bottom - frame.bottom + pad; }
|
|
27450
|
+
if (box.left < frame.left + pad) { dx = box.left - frame.left - pad; } else if (box.right > frame.right - pad) { dx = box.right - frame.right + pad; }
|
|
27451
|
+
if (dx || dy) { m.panBy([dx, dy], { duration: 250 }); }
|
|
27452
|
+
};
|
|
27453
|
+
|
|
27454
|
+
/** Closes the map's popup, if one is open. */
|
|
27455
|
+
SMap.prototype.closePopup = function () {
|
|
27456
|
+
var popup = this._popup;
|
|
27457
|
+
this._popup = null;
|
|
27458
|
+
this._popupSeq++;
|
|
27459
|
+
if (popup) { popup.remove(); }
|
|
27147
27460
|
return this;
|
|
27148
27461
|
};
|
|
27149
27462
|
|
|
27463
|
+
SMap.prototype._popupContent = function (popup, content) {
|
|
27464
|
+
if (typeof content === 'string') { popup.setHTML(content); } else { popup.setDOMContent(content); }
|
|
27465
|
+
};
|
|
27466
|
+
|
|
27467
|
+
SMap.prototype._reportError = function (error) {
|
|
27468
|
+
var m = this.engine;
|
|
27469
|
+
if (m && engine.ErrorEvent && m.fire) { m.fire(new engine.ErrorEvent(error)); } else if (typeof console !== 'undefined') { console.error(error); }
|
|
27470
|
+
};
|
|
27471
|
+
|
|
27472
|
+
// A click on the map: the top feature of the layers with a popup, if any, opens its layer's popup.
|
|
27473
|
+
SMap.prototype._popupClick = function (e) {
|
|
27474
|
+
var m = this.engine;
|
|
27475
|
+
var ids = [];
|
|
27476
|
+
var byEngineLayer = {};
|
|
27477
|
+
for (var i = 0; i < this._order.length; i++) {
|
|
27478
|
+
var def = this._layers[this._order[i]];
|
|
27479
|
+
if (def.o.popup && def.popupLayer && !def.hidden && m.getLayer(def.popupLayer)) {
|
|
27480
|
+
ids.push(def.popupLayer);
|
|
27481
|
+
byEngineLayer[def.popupLayer] = def;
|
|
27482
|
+
if (def.hoverLayer && m.getLayer(def.hoverLayer)) { ids.push(def.hoverLayer); byEngineLayer[def.hoverLayer] = def; }
|
|
27483
|
+
}
|
|
27484
|
+
}
|
|
27485
|
+
if (!ids.length) { return; }
|
|
27486
|
+
var hits = m.queryRenderedFeatures(e.point, { layers: ids });
|
|
27487
|
+
if (!hits || !hits.length) { return; }
|
|
27488
|
+
var f = hits[0];
|
|
27489
|
+
var hit = byEngineLayer[f.layer && f.layer.id];
|
|
27490
|
+
if (!hit) { return; }
|
|
27491
|
+
// A tight pile of pins: zoom in around the click so they come apart, or, when they still overlap close up (or
|
|
27492
|
+
// share one spot), offer a chooser. A layer turns this off with marker.overlap === false.
|
|
27493
|
+
if (this._autoZoom && hit.o.marker && hit.o.marker.overlap !== false && e.point && m.project) {
|
|
27494
|
+
var ov = hit.o.marker.overlap || {}, near = ov.radius || 12, threshold = ov.threshold || 4;
|
|
27495
|
+
var box = [[e.point.x - near, e.point.y - near], [e.point.x + near, e.point.y + near]];
|
|
27496
|
+
var seen = {}, pile = [];
|
|
27497
|
+
(m.queryRenderedFeatures(box, { layers: ids }) || []).forEach(function (x) {
|
|
27498
|
+
var d = byEngineLayer[x.layer && x.layer.id];
|
|
27499
|
+
if (d !== hit || !x.geometry || x.geometry.type !== 'Point') { return; }
|
|
27500
|
+
var key = JSON.stringify(x.geometry.coordinates) + JSON.stringify(x.properties || {});
|
|
27501
|
+
if (!seen[key]) { seen[key] = true; pile.push(x); }
|
|
27502
|
+
});
|
|
27503
|
+
if (pile.length >= 2) {
|
|
27504
|
+
var spots = {};
|
|
27505
|
+
pile.forEach(function (x) { spots[x.geometry.coordinates.map(function (c) { return c.toFixed(6); }).join(',')] = true; });
|
|
27506
|
+
var oneSpot = Object.keys(spots).length === 1;
|
|
27507
|
+
var closeUp = m.getZoom() >= (ov.maxZoom || 17);
|
|
27508
|
+
if (pile.length >= threshold && !oneSpot && !closeUp) {
|
|
27509
|
+
m.easeTo({ center: e.lngLat, zoom: Math.min(m.getZoom() + (ov.zoomBy || 2), ov.maxZoom || 17), duration: 400 });
|
|
27510
|
+
return;
|
|
27511
|
+
}
|
|
27512
|
+
if (pile.length >= threshold || oneSpot) { this._chooser(hit, pile, e.lngLat); return; }
|
|
27513
|
+
}
|
|
27514
|
+
}
|
|
27515
|
+
this._openFeaturePopup(hit, f, e.lngLat);
|
|
27516
|
+
};
|
|
27517
|
+
|
|
27518
|
+
/** A small list of the pins under a click; choosing one opens its popup. */
|
|
27519
|
+
SMap.prototype._chooser = function (hit, pile, lngLat) {
|
|
27520
|
+
var self = this, mk = hit.o.marker, doc = this.engine.getContainer().ownerDocument;
|
|
27521
|
+
var list = doc.createElement('div');
|
|
27522
|
+
list.className = 'smap-chooser';
|
|
27523
|
+
var esc = function (v) { return String(v == null ? '' : v).replace(/[&<>"']/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; }); };
|
|
27524
|
+
var plainValue = function (v, p) {
|
|
27525
|
+
if (v && typeof v === 'object' && !Array.isArray(v) && v.property) { return p[v.property] !== undefined ? p[v.property] : v.default; }
|
|
27526
|
+
return Array.isArray(v) ? undefined : v;
|
|
27527
|
+
};
|
|
27528
|
+
pile.slice(0, 50).forEach(function (x, i) {
|
|
27529
|
+
var p = x.properties || {};
|
|
27530
|
+
var label = mk.overlap && typeof mk.overlap.label === 'function' ? mk.overlap.label(p, x) : null;
|
|
27531
|
+
var number = plainValue(mk.text, p), fill = plainValue(mk.fill, p) || '#ffffff', border = plainValue(mk.border, p) || hit.o.color || '#4f46e5';
|
|
27532
|
+
var item = doc.createElement('button');
|
|
27533
|
+
item.type = 'button';
|
|
27534
|
+
item.className = 'smap-chooser-item';
|
|
27535
|
+
item.innerHTML = '<span class="smap-chooser-pin" style="background:' + esc(fill) + ';border-color:' + esc(border) + '">' + esc(number == null ? '' : number) + '</span>'
|
|
27536
|
+
+ '<span class="smap-chooser-label">' + esc(label != null ? label : (number != null ? number : i + 1)) + '</span>';
|
|
27537
|
+
item.addEventListener('click', function (ev) { ev.stopPropagation(); self._openFeaturePopup(hit, x, x.geometry.coordinates); });
|
|
27538
|
+
list.appendChild(item);
|
|
27539
|
+
});
|
|
27540
|
+
this._unpin();
|
|
27541
|
+
this.openPopup(lngLat, list, { className: 'smap-chooser-popup', anchor: 'bottom', offset: 12 });
|
|
27542
|
+
};
|
|
27543
|
+
|
|
27544
|
+
/** Opens a feature's own popup (the layer's popup function), above a pin when the layer draws pins. */
|
|
27545
|
+
SMap.prototype._openFeaturePopup = function (hit, f, lngLat) {
|
|
27546
|
+
var m = this.engine;
|
|
27547
|
+
// Points open at their own position; lines and areas where they were clicked.
|
|
27548
|
+
var at = hit.kind === 'points' && f.geometry && f.geometry.type === 'Point' ? f.geometry.coordinates : lngLat;
|
|
27549
|
+
var content;
|
|
27550
|
+
try { content = hit.o.popup(f.properties || {}, f); } catch (error) { this._reportError(error); return; }
|
|
27551
|
+
var popupOptions = Object.assign({}, hit.o.popupOptions || {});
|
|
27552
|
+
if (hit.o.marker && popupOptions.offset === undefined && this._popupDefaults.offset === undefined) {
|
|
27553
|
+
// Just above the pin as it is drawn now (its scale may follow the zoom).
|
|
27554
|
+
var mk = hit.o.marker, size = mk.size || 32, k = scaleAt(mk.scale, m.getZoom ? m.getZoom() : 0);
|
|
27555
|
+
popupOptions.offset = mk.shape === 'circle' ? Math.round((size / 2) * k + 4) : Math.round((markerGeometry('pin', size).tipToHead + size / 2) * k + 2);
|
|
27556
|
+
}
|
|
27557
|
+
// Above the pin, always (as on Superroute's route map); the map pans to make room instead of flipping it below.
|
|
27558
|
+
if (hit.o.marker && popupOptions.anchor === undefined && this._popupDefaults.anchor === undefined) { popupOptions.anchor = 'bottom'; }
|
|
27559
|
+
if (hit.o.popupLoading !== undefined) { popupOptions.loading = hit.o.popupLoading; }
|
|
27560
|
+
this._unpin();
|
|
27561
|
+
this.openPopup(at, content, popupOptions);
|
|
27562
|
+
// The clicked pin stays in front while its popup is open (the route map's rule).
|
|
27563
|
+
if (hit.hoverSource && this._popup) {
|
|
27564
|
+
var self = this, popup = this._popup;
|
|
27565
|
+
this._setHover(null, hit, f, 'popup');
|
|
27566
|
+
hit.pinned = popup;
|
|
27567
|
+
this._pinnedDef = hit;
|
|
27568
|
+
if (popup.on) { popup.on('close', function () { if (hit.pinned === popup) { self._unpin(); } }); }
|
|
27569
|
+
}
|
|
27570
|
+
};
|
|
27571
|
+
|
|
27150
27572
|
/** Switches the label language; your layers are kept. */
|
|
27573
|
+
/**
|
|
27574
|
+
* A marker scale at a zoom: a number, or the linear / step zoom expressions the SDK documents
|
|
27575
|
+
* (['interpolate', ['linear'], ['zoom'], z, v, …], ['step', ['zoom'], v, z, v, …]); anything else counts as 1.
|
|
27576
|
+
*/
|
|
27577
|
+
function scaleAt(scale, zoom) {
|
|
27578
|
+
if (scale === undefined || scale === null) { return 1; }
|
|
27579
|
+
if (typeof scale === 'number') { return scale; }
|
|
27580
|
+
if (!Array.isArray(scale)) { return 1; }
|
|
27581
|
+
var isZoom = function (x) { return Array.isArray(x) && x[0] === 'zoom'; };
|
|
27582
|
+
if (scale[0] === 'interpolate' && isZoom(scale[2])) {
|
|
27583
|
+
var stops = scale.slice(3);
|
|
27584
|
+
if (zoom <= stops[0]) { return stops[1]; }
|
|
27585
|
+
for (var i = 2; i < stops.length; i += 2) {
|
|
27586
|
+
if (zoom <= stops[i]) { var t = (zoom - stops[i - 2]) / (stops[i] - stops[i - 2]); return stops[i - 1] + t * (stops[i + 1] - stops[i - 1]); }
|
|
27587
|
+
}
|
|
27588
|
+
return stops[stops.length - 1];
|
|
27589
|
+
}
|
|
27590
|
+
if (scale[0] === 'step' && isZoom(scale[1])) {
|
|
27591
|
+
var value = scale[2];
|
|
27592
|
+
for (var j = 3; j < scale.length; j += 2) { if (zoom >= scale[j]) { value = scale[j + 1]; } }
|
|
27593
|
+
return value;
|
|
27594
|
+
}
|
|
27595
|
+
return 1;
|
|
27596
|
+
}
|
|
27597
|
+
|
|
27151
27598
|
SMap.prototype.setLanguage = function (language) {
|
|
27152
27599
|
this._language = language;
|
|
27153
27600
|
if (!this._customStyle) { this._styleReady = false; this.engine.setStyle(this._styleUrl()); }
|
|
@@ -27162,6 +27609,33 @@ function smapCreateSdk(engine) {
|
|
|
27162
27609
|
};
|
|
27163
27610
|
|
|
27164
27611
|
/** Shows buildings in 3D (and tilts the map when it is flat). */
|
|
27612
|
+
/**
|
|
27613
|
+
* Auto Zoom: a click on pins piled up zooms the map in around it, or lists them close up (see marker.overlap).
|
|
27614
|
+
* On by default (`autoZoom: false` in the options turns it off).
|
|
27615
|
+
*/
|
|
27616
|
+
SMap.prototype.setAutoZoom = function (on) { this._autoZoom = !!on; return this; };
|
|
27617
|
+
SMap.prototype.autoZoom = function () { return this._autoZoom; };
|
|
27618
|
+
|
|
27619
|
+
/**
|
|
27620
|
+
* In 3D (3D buildings on, or the map tilted) W / S tilt the view and A / D turn it; Shift takes bigger steps. Only
|
|
27621
|
+
* while the map has the keyboard focus, so typing elsewhere on the page is never taken.
|
|
27622
|
+
*/
|
|
27623
|
+
SMap.prototype._keyboard3D = function () {
|
|
27624
|
+
var self = this, m = this.engine;
|
|
27625
|
+
var el = m.getCanvasContainer ? m.getCanvasContainer() : (m.getContainer ? m.getContainer() : null);
|
|
27626
|
+
if (!el || !el.addEventListener || this._wasd === false) { return; }
|
|
27627
|
+
el.addEventListener('keydown', function (e) {
|
|
27628
|
+
if (e.altKey || e.ctrlKey || e.metaKey) { return; }
|
|
27629
|
+
if (!self._buildings && m.getPitch() < 1) { return; }
|
|
27630
|
+
var big = e.shiftKey, key = (e.key || '').toLowerCase();
|
|
27631
|
+
var pitch = m.getPitch(), bearing = m.getBearing();
|
|
27632
|
+
if (key === 'w') { pitch = Math.min(85, pitch + (big ? 15 : 5)); } else if (key === 's') { pitch = Math.max(0, pitch - (big ? 15 : 5)); }
|
|
27633
|
+
else if (key === 'a') { bearing -= big ? 45 : 15; } else if (key === 'd') { bearing += big ? 45 : 15; } else { return; }
|
|
27634
|
+
e.preventDefault();
|
|
27635
|
+
m.easeTo({ pitch: pitch, bearing: bearing, duration: 200 });
|
|
27636
|
+
});
|
|
27637
|
+
};
|
|
27638
|
+
|
|
27165
27639
|
SMap.prototype.setBuildings3D = function (on, options) {
|
|
27166
27640
|
this._buildings = !!on;
|
|
27167
27641
|
this._buildingOptions = options || this._buildingOptions || {};
|
|
@@ -27200,8 +27674,9 @@ function smapCreateSdk(engine) {
|
|
|
27200
27674
|
* @param {Object|Array} data GeoJSON, or an array of {lng, lat, …properties}
|
|
27201
27675
|
* @param {Object} [o]
|
|
27202
27676
|
* cluster: true | {radius, maxZoom}; color; radius; strokeColor; icon (image URL); iconSize; label (property name);
|
|
27203
|
-
* minzoom; maxzoom; zIndex (higher draws on top); onClick(feature, event);
|
|
27204
|
-
* (inserted as is, never sanitized: escape feature data
|
|
27677
|
+
* minzoom; maxzoom; zIndex (higher draws on top); onClick(feature, event);
|
|
27678
|
+
* popup(properties, feature) → trusted HTML (inserted as is, never sanitized: escape feature data, or use
|
|
27679
|
+
* sMap.popupTemplate), a DOM node, or a promise of either; popupOptions (over the map's `popup`); popupLoading
|
|
27205
27680
|
*/
|
|
27206
27681
|
SMap.prototype.addPoints = function (id, data, o) {
|
|
27207
27682
|
o = o || {};
|
|
@@ -27229,6 +27704,7 @@ function smapCreateSdk(engine) {
|
|
|
27229
27704
|
var def = this._layers[id];
|
|
27230
27705
|
if (!def) { throw new Error('sMap: no layer ' + id); }
|
|
27231
27706
|
def.data = toFeatureCollection(data);
|
|
27707
|
+
if (def.hovered) { this._setHover(id, def, null); }
|
|
27232
27708
|
var src = this.engine.getSource('smap-' + id);
|
|
27233
27709
|
if (src) { src.setData(def.data); }
|
|
27234
27710
|
return this;
|
|
@@ -27307,7 +27783,9 @@ function smapCreateSdk(engine) {
|
|
|
27307
27783
|
if (!m) { return; }
|
|
27308
27784
|
def.engineLayers.forEach(function (l) { if (m.getLayer(l)) { m.removeLayer(l); } });
|
|
27309
27785
|
if (m.getSource('smap-' + id)) { m.removeSource('smap-' + id); }
|
|
27310
|
-
(
|
|
27786
|
+
if (m.getSource('smap-' + id + '-hover')) { m.removeSource('smap-' + id + '-hover'); }
|
|
27787
|
+
def.hoverLayer = null; def.hovered = null;
|
|
27788
|
+
(this._handlers[id] || []).forEach(function (h) { if (h[1]) { m.off(h[0], h[1], h[2]); } else { m.off(h[0], h[2]); } });
|
|
27311
27789
|
this._handlers[id] = [];
|
|
27312
27790
|
def.engineLayers = [];
|
|
27313
27791
|
};
|
|
@@ -27340,7 +27818,10 @@ function smapCreateSdk(engine) {
|
|
|
27340
27818
|
layer.source = src;
|
|
27341
27819
|
// The engine refuses a filter key whose value is undefined (unclustered points have none).
|
|
27342
27820
|
if (layer.filter === undefined) { delete layer.filter; }
|
|
27343
|
-
|
|
27821
|
+
if (layer.minzoom === undefined) { delete layer.minzoom; }
|
|
27822
|
+
if (layer.paint === undefined) { delete layer.paint; }
|
|
27823
|
+
// A layer's own minzoom (a marker's textMinzoom / badgeMinzoom) never shows it before the layer's own range.
|
|
27824
|
+
for (var k in range) { layer[k] = k === 'minzoom' && layer.minzoom !== undefined ? Math.max(layer.minzoom, range.minzoom) : range[k]; }
|
|
27344
27825
|
layer.layout = Object.assign({ visibility: visibility }, layer.layout || {});
|
|
27345
27826
|
m.addLayer(layer, before);
|
|
27346
27827
|
def.engineLayers.push(layer.id);
|
|
@@ -27370,7 +27851,57 @@ function smapCreateSdk(engine) {
|
|
|
27370
27851
|
});
|
|
27371
27852
|
}
|
|
27372
27853
|
var only = o.cluster ? ['!', ['has', 'point_count']] : undefined;
|
|
27373
|
-
|
|
27854
|
+
var both = function (extra) { return only ? ['all', only, extra] : extra; };
|
|
27855
|
+
if (o.marker) {
|
|
27856
|
+
// Pins like Superroute's route map, drawn on the GPU: one image per colour pair (and per number, per badge),
|
|
27857
|
+
// made the first time a feature shows it. Numbers and badges are their own layers above the pins.
|
|
27858
|
+
var mk = o.marker;
|
|
27859
|
+
var shape = mk.shape === 'circle' ? 'circle' : 'pin';
|
|
27860
|
+
var size = mk.size || 32;
|
|
27861
|
+
var bw = mk.borderWidth !== undefined ? mk.borderWidth : 3;
|
|
27862
|
+
var g = markerGeometry(shape, size);
|
|
27863
|
+
var str = function (v, d) { return ['to-string', valueExpr(v, d)]; };
|
|
27864
|
+
// One scale for the pin, its number and its badge (a number, or an engine expression such as one of the zoom),
|
|
27865
|
+
// so the three stay together at every size: the offsets are in icon units and scale with them.
|
|
27866
|
+
var scale = mk.scale !== undefined ? mk.scale : 1;
|
|
27867
|
+
// Opacity of the pin, its number and its badge together (the route map draws settled stops at .72).
|
|
27868
|
+
var markerPaint = mk.opacity !== undefined ? { 'icon-opacity': valueExpr(mk.opacity, 1) } : undefined;
|
|
27869
|
+
main = src + '-points';
|
|
27870
|
+
var markerSpecs = [];
|
|
27871
|
+
var addMarker = function (layer) { markerSpecs.push(JSON.parse(JSON.stringify(layer))); add(layer); };
|
|
27872
|
+
addMarker({
|
|
27873
|
+
id: main, type: 'symbol', filter: only, paint: markerPaint,
|
|
27874
|
+
layout: {
|
|
27875
|
+
'icon-image': drawnImageId('pin', [shape, str(mk.fill, '#ffffff'), str(mk.border, color), String(bw), String(size)]),
|
|
27876
|
+
'icon-anchor': shape === 'circle' ? 'center' : 'bottom',
|
|
27877
|
+
// The image has room for the shadow below the tip: the tip, not the image's edge, is at the position.
|
|
27878
|
+
'icon-offset': [0, shape === 'circle' ? 0 : PIN_PAD], 'icon-size': scale,
|
|
27879
|
+
'icon-allow-overlap': true, 'icon-ignore-placement': true,
|
|
27880
|
+
},
|
|
27881
|
+
});
|
|
27882
|
+
if (mk.text !== undefined) {
|
|
27883
|
+
var text = str(mk.text, '');
|
|
27884
|
+
addMarker({
|
|
27885
|
+
id: src + '-numbers', type: 'symbol', filter: both(['!=', text, '']), minzoom: mk.textMinzoom, paint: markerPaint,
|
|
27886
|
+
layout: {
|
|
27887
|
+
'icon-image': drawnImageId('num', [str(mk.textColor, '#ffffff'), String(size), text]),
|
|
27888
|
+
'icon-offset': [0, -g.tipToHead], 'icon-size': scale, 'icon-allow-overlap': true, 'icon-ignore-placement': true,
|
|
27889
|
+
},
|
|
27890
|
+
});
|
|
27891
|
+
}
|
|
27892
|
+
if (mk.badge !== undefined) {
|
|
27893
|
+
var badge = ['to-number', valueExpr(mk.badge, 0), 0];
|
|
27894
|
+
addMarker({
|
|
27895
|
+
id: src + '-badges', type: 'symbol', filter: both(['>', badge, 1]), minzoom: mk.badgeMinzoom, paint: markerPaint,
|
|
27896
|
+
layout: {
|
|
27897
|
+
'icon-image': drawnImageId('badge', [['to-string', badge]]),
|
|
27898
|
+
'icon-offset': g.badge, 'icon-size': scale,
|
|
27899
|
+
'icon-allow-overlap': true, 'icon-ignore-placement': true,
|
|
27900
|
+
},
|
|
27901
|
+
});
|
|
27902
|
+
}
|
|
27903
|
+
if (mk.hoverRaise !== false) { this._hoverRaise(id, def, src, markerSpecs, main); }
|
|
27904
|
+
} else if (o.icon) {
|
|
27374
27905
|
var imageId = src + '-icon';
|
|
27375
27906
|
main = src + '-points';
|
|
27376
27907
|
var placeIcon = function () {
|
|
@@ -27404,9 +27935,35 @@ function smapCreateSdk(engine) {
|
|
|
27404
27935
|
}
|
|
27405
27936
|
} else if (def.kind === 'lines') {
|
|
27406
27937
|
main = src + '-lines';
|
|
27407
|
-
var
|
|
27938
|
+
var lineColor = valueExpr(o.color, '#4f46e5');
|
|
27939
|
+
var round = { 'line-cap': 'round', 'line-join': 'round' };
|
|
27940
|
+
// Bottom to top: casing, shadow, the line, its arrows (as on Superroute's route map).
|
|
27941
|
+
if (o.casing) {
|
|
27942
|
+
var cs = o.casing === true ? {} : o.casing;
|
|
27943
|
+
add({ id: src + '-casing', type: 'line', layout: round, paint: {
|
|
27944
|
+
'line-color': valueExpr(cs.color, '#ffffff'), 'line-width': cs.width || 9, 'line-opacity': cs.opacity !== undefined ? cs.opacity : 1 } });
|
|
27945
|
+
}
|
|
27946
|
+
if (o.shadow) {
|
|
27947
|
+
var sh = o.shadow === true ? {} : o.shadow;
|
|
27948
|
+
add({ id: src + '-shadow', type: 'line', layout: round, paint: {
|
|
27949
|
+
'line-color': valueExpr(sh.color, '#000000'), 'line-width': sh.width || 7, 'line-opacity': sh.opacity !== undefined ? sh.opacity : 0.3 } });
|
|
27950
|
+
}
|
|
27951
|
+
var paint = { 'line-color': lineColor, 'line-width': o.width || 3, 'line-opacity': o.opacity !== undefined ? o.opacity : 1 };
|
|
27408
27952
|
if (o.dash) { paint['line-dasharray'] = o.dash; }
|
|
27409
|
-
add({ id: main, type: 'line', layout:
|
|
27953
|
+
add({ id: main, type: 'line', layout: round, paint: paint });
|
|
27954
|
+
if (o.arrows) {
|
|
27955
|
+
var ar = o.arrows === true ? {} : o.arrows;
|
|
27956
|
+
var arrowSize = ar.size || 14;
|
|
27957
|
+
add({
|
|
27958
|
+
id: src + '-arrows', type: 'symbol',
|
|
27959
|
+
layout: {
|
|
27960
|
+
'symbol-placement': 'line', 'symbol-spacing': ar.spacing || 80,
|
|
27961
|
+
'icon-image': drawnImageId('arrow', [String(arrowSize), ['to-string', valueExpr(ar.color, lineColor)]]),
|
|
27962
|
+
'icon-rotation-alignment': 'map', 'icon-allow-overlap': true, 'icon-ignore-placement': true,
|
|
27963
|
+
},
|
|
27964
|
+
paint: { 'icon-opacity': ar.opacity !== undefined ? ar.opacity : 0.8 },
|
|
27965
|
+
});
|
|
27966
|
+
}
|
|
27410
27967
|
} else {
|
|
27411
27968
|
if (o.extrude) {
|
|
27412
27969
|
main = src + '-extrusion';
|
|
@@ -27426,32 +27983,74 @@ function smapCreateSdk(engine) {
|
|
|
27426
27983
|
add({ id: src + '-outline', type: 'line', paint: { 'line-color': o.outline || o.fill || color, 'line-width': o.outlineWidth || 1.5 } });
|
|
27427
27984
|
}
|
|
27428
27985
|
}
|
|
27986
|
+
// The popup is opened by the map's one click handler (_popupClick), from this layer's own hit test.
|
|
27987
|
+
def.popupLayer = o.popup ? main : null;
|
|
27429
27988
|
if (main && (o.popup || o.onClick)) {
|
|
27430
|
-
|
|
27431
|
-
|
|
27432
|
-
|
|
27433
|
-
if (o.popup) {
|
|
27434
|
-
// A string is inserted as HTML as it is (never sanitized): it must be trusted, with feature data escaped.
|
|
27435
|
-
// A DOM node is inserted as it is.
|
|
27436
|
-
var content = o.popup(f.properties, f);
|
|
27437
|
-
if (content) {
|
|
27438
|
-
var popup = new engine.Popup({ offset: 12 }).setLngLat(e.lngLat);
|
|
27439
|
-
if (typeof content === 'string') { popup.setHTML(content); } else { popup.setDOMContent(content); }
|
|
27440
|
-
popup.addTo(m);
|
|
27441
|
-
}
|
|
27442
|
-
}
|
|
27443
|
-
});
|
|
27989
|
+
if (o.onClick) {
|
|
27990
|
+
this._listen(id, 'click', main, function (e) { o.onClick(e.features[0], e); });
|
|
27991
|
+
}
|
|
27444
27992
|
this._listen(id, 'mouseenter', main, function () { m.getCanvas().style.cursor = 'pointer'; });
|
|
27445
27993
|
this._listen(id, 'mouseleave', main, function () { m.getCanvas().style.cursor = ''; });
|
|
27446
27994
|
}
|
|
27447
27995
|
};
|
|
27448
27996
|
|
|
27997
|
+
/**
|
|
27998
|
+
* Overlapping pins: the one under the pointer comes to the front, as on Superroute's route map, so it can be read
|
|
27999
|
+
* and clicked. A copy of that one feature is drawn in its own source above everything else; nothing is done per
|
|
28000
|
+
* feature, only for the feature under the pointer.
|
|
28001
|
+
*/
|
|
28002
|
+
SMap.prototype._hoverRaise = function (id, def, src, specs, main) {
|
|
28003
|
+
var m = this.engine, self = this;
|
|
28004
|
+
var hoverSrc = src + '-hover';
|
|
28005
|
+
m.addSource(hoverSrc, { type: 'geojson', data: { type: 'FeatureCollection', features: [] } });
|
|
28006
|
+
var top = null;
|
|
28007
|
+
specs.forEach(function (spec) {
|
|
28008
|
+
var layer = JSON.parse(JSON.stringify(spec));
|
|
28009
|
+
layer.id = spec.id.replace(src + '-', src + '-hover-');
|
|
28010
|
+
layer.source = hoverSrc;
|
|
28011
|
+
if (layer.filter === undefined) { delete layer.filter; }
|
|
28012
|
+
if (layer.paint === undefined) { delete layer.paint; }
|
|
28013
|
+
if (layer.minzoom === undefined) { delete layer.minzoom; }
|
|
28014
|
+
m.addLayer(layer);
|
|
28015
|
+
def.engineLayers.push(layer.id);
|
|
28016
|
+
if (!top) { top = layer.id; }
|
|
28017
|
+
});
|
|
28018
|
+
def.hoverLayer = top;
|
|
28019
|
+
def.hoverSource = hoverSrc;
|
|
28020
|
+
var keyOf = function (f) { return JSON.stringify(f.geometry && f.geometry.coordinates) + JSON.stringify(f.properties || {}); };
|
|
28021
|
+
this._listen(id, 'mousemove', null, function (e) {
|
|
28022
|
+
if (def.hidden || !m.getLayer(main) || def.pinned) { return; }
|
|
28023
|
+
// Still over the raised pin: keep it. Otherwise raise the top pin under the pointer, if any.
|
|
28024
|
+
if (def.hovered && m.getLayer(top) && m.queryRenderedFeatures(e.point, { layers: [top] }).length) { return; }
|
|
28025
|
+
var hits = m.queryRenderedFeatures(e.point, { layers: [main] });
|
|
28026
|
+
var f = hits && hits[0];
|
|
28027
|
+
if (!f) { if (def.hovered) { self._setHover(id, def, null); } return; }
|
|
28028
|
+
if (def.hovered && def.hovered.key === keyOf(f)) { return; }
|
|
28029
|
+
self._setHover(id, def, f, keyOf(f));
|
|
28030
|
+
});
|
|
28031
|
+
this._listen(id, 'mouseout', null, function () { if (def.hovered && !def.pinned) { self._setHover(id, def, null); } });
|
|
28032
|
+
};
|
|
28033
|
+
|
|
28034
|
+
SMap.prototype._unpin = function () {
|
|
28035
|
+
var def = this._pinnedDef;
|
|
28036
|
+
this._pinnedDef = null;
|
|
28037
|
+
if (def) { def.pinned = null; this._setHover(null, def, null); }
|
|
28038
|
+
};
|
|
28039
|
+
|
|
28040
|
+
SMap.prototype._setHover = function (id, def, f, key) {
|
|
28041
|
+
var source = def.hoverSource && this.engine.getSource(def.hoverSource);
|
|
28042
|
+
def.hovered = f ? { key: key } : null;
|
|
28043
|
+
if (!source) { return; }
|
|
28044
|
+
// A plain copy: the engine's own feature objects cannot be sent to its worker.
|
|
28045
|
+
source.setData({ type: 'FeatureCollection', features: f ? [JSON.parse(JSON.stringify({ type: 'Feature', properties: f.properties || {}, geometry: f.geometry }))] : [] });
|
|
28046
|
+
};
|
|
28047
|
+
|
|
27449
28048
|
SMap.prototype._listen = function (id, type, layer, fn) {
|
|
27450
|
-
this.engine.on(type, layer, fn);
|
|
28049
|
+
if (layer) { this.engine.on(type, layer, fn); } else { this.engine.on(type, fn); }
|
|
27451
28050
|
(this._handlers[id] = this._handlers[id] || []).push([type, layer, fn]);
|
|
27452
28051
|
};
|
|
27453
28052
|
|
|
27454
|
-
return { Map: SMap, version: VERSION, styles: FLAVORS.slice(), engine: engine };
|
|
28053
|
+
return { Map: SMap, version: VERSION, styles: FLAVORS.slice(), engine: engine, popupTemplate: popupTemplate };
|
|
27455
28054
|
});
|
|
27456
28055
|
|
|
27457
28056
|
return module.exports;
|
|
@@ -27471,10 +28070,16 @@ function SMapMap(options) {
|
|
|
27471
28070
|
SMapMap.prototype = core.Map.prototype;
|
|
27472
28071
|
return new core.Map(options);
|
|
27473
28072
|
}
|
|
27474
|
-
var smapVersion = "1.0.
|
|
28073
|
+
var smapVersion = "1.0.5";
|
|
27475
28074
|
var smapStyles = ['light', 'white', 'grayscale', 'dark', 'black'];
|
|
27476
28075
|
/** The bundled rendering engine, for anything the SDK does not wrap (loaded on the first call). */
|
|
27477
28076
|
function smapGetEngine() { return smapLoad().engine; }
|
|
27478
|
-
|
|
27479
|
-
|
|
28077
|
+
// Templates need no engine: before the first map they come from an SDK made without one.
|
|
28078
|
+
var smapNoEngine = null;
|
|
28079
|
+
function smapPopupTemplate(template) {
|
|
28080
|
+
if (!smapCore && !smapNoEngine) { smapNoEngine = smapCreateSdk(null); }
|
|
28081
|
+
return (smapCore || smapNoEngine).popupTemplate(template);
|
|
28082
|
+
}
|
|
28083
|
+
var smapDefault = { Map: SMapMap, version: smapVersion, styles: smapStyles, getEngine: smapGetEngine, popupTemplate: smapPopupTemplate };
|
|
28084
|
+
export { SMapMap as Map, smapVersion as version, smapStyles as styles, smapGetEngine as getEngine, smapPopupTemplate as popupTemplate };
|
|
27480
28085
|
export default smapDefault;
|