@geolonia/embed 3.0.0-pre.0 → 3.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "3.0.0-pre.0",
3
+ "version": "3.0.0",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
6
  "types": "src/embed.d.ts",
@@ -10,7 +10,7 @@
10
10
  "analyze": "ANALYZE=true webpack --mode production",
11
11
  "format": "prettier-eslint \"./src/**/*.js\" --write",
12
12
  "lint": "eslint \"src/**/*.js\"",
13
- "test": "npm run lint && mocha ./src/**/*.test.js --recursive -r jsdom-global/register -r @babel/register"
13
+ "test": "yarn run lint && mocha ./src/**/*.test.js --recursive -r jsdom-global/register -r @babel/register"
14
14
  },
15
15
  "author": "Geolonia (https://geolonia.com)",
16
16
  "repository": {
@@ -23,41 +23,44 @@
23
23
  },
24
24
  "homepage": "https://github.com/geolonia/embed#readme",
25
25
  "devDependencies": {
26
- "@babel/cli": "^7.12.1",
27
- "@babel/core": "^7.10.2",
28
- "@babel/plugin-transform-classes": "^7.10.1",
29
- "@babel/preset-env": "^7.10.2",
30
- "@babel/register": "^7.10.1",
26
+ "@babel/cli": "^7.19.3",
27
+ "@babel/core": "^7.20.5",
28
+ "@babel/plugin-transform-classes": "^7.20.2",
29
+ "@babel/preset-env": "^7.20.2",
30
+ "@babel/register": "^7.18.9",
31
31
  "@geolonia/eslint-config": "^0.0.1",
32
- "babel-eslint": "^10.1.0",
33
- "babel-loader": "^8.1.0",
34
- "css-loader": "^2.1.0",
35
- "eslint": "^7.16.0",
36
- "jsdom": "^16.2.2",
32
+ "@babel/eslint-parser": "^7.19.1",
33
+ "babel-loader": "^9.1.0",
34
+ "css-loader": "^6.7.2",
35
+ "eslint": "^8.29.0",
36
+ "jsdom": "^20.0.3",
37
37
  "jsdom-global": "^3.0.2",
38
- "mocha": "^5.2.0",
38
+ "mocha": "^10.2.0",
39
39
  "node-fetch": "2",
40
- "prettier-eslint": "^12.0.0",
41
- "prettier-eslint-cli": "^5.0.0",
42
- "style-loader": "^0.23.1",
40
+ "prettier-eslint": "^15.0.0",
41
+ "prettier-eslint-cli": "^7.1.0",
42
+ "style-loader": "^3.3.1",
43
43
  "svg-inline-loader": "^0.8.2",
44
- "webpack": "^5.59.1",
45
- "webpack-bundle-analyzer": "^4.5.0",
46
- "webpack-cli": "^4.9.1",
47
- "webpack-dev-server": "^4.3.1"
44
+ "webpack": "^5.75.0",
45
+ "webpack-bundle-analyzer": "^4.7.0",
46
+ "webpack-cli": "^5.0.1",
47
+ "webpack-dev-server": "^4.11.1"
48
48
  },
49
49
  "dependencies": {
50
50
  "@geolonia/mbgl-geolonia-control": "^0.4.2",
51
51
  "@geolonia/mbgl-gesture-handling": "^1.0.15",
52
- "@mapbox/geojson-extent": "^0.3.2",
52
+ "@mapbox/geojson-extent": "^1.0.0",
53
+ "@mapbox/point-geometry": "^0.1.0",
53
54
  "@turf/center": "^6.0.1",
54
- "core-js": "^3.6.5",
55
- "intersection-observer": "^0.5.1",
55
+ "core-js": "^3.26.1",
56
56
  "maplibre-gl": "2.4.0",
57
- "promise-polyfill": "^8.1.0",
58
- "sanitize-html": "^2.3.2",
57
+ "promise-polyfill": "^8.2.3",
58
+ "sanitize-html": "^2.8.0",
59
59
  "tinycolor2": "^1.4.1",
60
- "url-parse": "^1.4.7",
60
+ "url-parse": "^1.5.10",
61
61
  "whatwg-fetch": "^3.0.0"
62
- }
62
+ },
63
+ "browserslist": [
64
+ "defaults or >= 1% in JP"
65
+ ]
63
66
  }
package/src/embed.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import * as maplibregl from 'maplibre-gl';
2
+ import SimpleStyle from './lib/simplestyle'
2
3
 
3
4
  export class Map extends maplibregl.Map {}
4
5
  export class Marker extends maplibregl.Marker {}
6
+ export class Popup extends maplibregl.Popup {}
5
7
 
6
8
  export type EmbedAttributes = {
7
9
  lat: string;
@@ -45,6 +47,8 @@ declare global {
45
47
  baseApiUrl: string;
46
48
  Map: typeof Map;
47
49
  Marker: typeof Marker;
50
+ Popup: typeof Popup;
51
+ SimpleStyle: typeof SimpleStyle;
48
52
  registerPlugin: (embedPlugin: EmbedPlugin) => void;
49
53
  }
50
54
  }
package/src/embed.js CHANGED
@@ -2,7 +2,6 @@
2
2
  * @file Entry for embed.js
3
3
  */
4
4
 
5
- import 'intersection-observer';
6
5
  import maplibregl from 'maplibre-gl';
7
6
  import 'maplibre-gl/dist/maplibre-gl.css';
8
7
  import './style.css';
@@ -13,7 +12,7 @@ import * as util from './lib/util';
13
12
  import parseAtts from './lib/parse-atts';
14
13
  import parseApiKey from './lib/parse-api-key';
15
14
  import pkg from '../package.json';
16
- import simpleStyle from './lib/simplestyle';
15
+ import SimpleStyle from './lib/simplestyle';
17
16
 
18
17
  if ( util.checkPermission() ) {
19
18
  let isDOMContentLoaded = false;
@@ -88,7 +87,9 @@ if ( util.checkPermission() ) {
88
87
  }
89
88
 
90
89
  window.geolonia.Map = GeoloniaMap;
91
- window.geolonia.simpleStyle = simpleStyle;
90
+ window.geolonia.simpleStyle = // backward compatibility
91
+ window.geolonia.SimpleStyle =
92
+ SimpleStyle;
92
93
  window.geolonia.Marker = GeoloniaMarker;
93
94
  window.geolonia.AmazonLocationServiceMapProvider = AmazonLocationServiceMapProvider;
94
95
  window.geolonia.embedVersion = pkg.version;
@@ -0,0 +1,339 @@
1
+ import { DOM, bindAll } from './maplibre-util';
2
+
3
+ /**
4
+ * This class is a copy of maplibre-gl-js's AttributionControl class and rewrite by shadow DOM.
5
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/ui/control/attribution_control.ts
6
+ */
7
+
8
+ /**
9
+ * When the map is too small to display the full attribution, it will be
10
+ * collapsed in to a "i" icon. It is open by default, and will hide itself
11
+ * when user interaction is detected.
12
+ * For more information on why this is open by default, see the following links:
13
+ *
14
+ * The OSM Foundation attribution guidelines.
15
+ * https://wiki.osmfoundation.org/wiki/Licence/Attribution_Guidelines#Interactive_maps
16
+ * > You may use a mechanism to fade/collapse the attribution under certain conditions:
17
+ * > * immediately with a dismiss interaction, for example clicking an ‘x’ in the corner of a dialog
18
+ * > * automatically on map interaction such as panning, clicking, or zooming
19
+ * > * automatically after five seconds. This also applies to splash screens or pop-ups.
20
+ *
21
+ * This is the issue where attribution is open by default in the MapLibre GL JS library:
22
+ * https://github.com/maplibre/maplibre-gl-js/issues/205
23
+ */
24
+
25
+ class CustomAttributionControl {
26
+
27
+ constructor(options = {}) {
28
+ this.options = options;
29
+ this._map;
30
+ this._compact;
31
+ this._container;
32
+ this._shadowContainer;
33
+ this._innerContainer;
34
+ this._compactButton;
35
+ this._editLink;
36
+ this._attribHTML;
37
+ this.styleId;
38
+ this.styleOwner;
39
+
40
+ bindAll([
41
+ '_toggleAttribution',
42
+ '_updateData',
43
+ '_updateCompact',
44
+ '_updateCompactMinimize',
45
+ ], this);
46
+ }
47
+
48
+ getDefaultPosition() {
49
+ return 'bottom-right';
50
+ }
51
+
52
+ onAdd(map) {
53
+ this._map = map;
54
+ this._compact = this.options && this.options.compact;
55
+ this._container = DOM.create('div');
56
+
57
+ const shadow = this._container.attachShadow({mode: 'open'});
58
+
59
+ this._shadowContainer = DOM.create('details', 'maplibregl-ctrl maplibregl-ctrl-attrib');
60
+ this._compactButton = DOM.create('summary', 'maplibregl-ctrl-attrib-button', this._shadowContainer);
61
+ this._compactButton.addEventListener('click', this._toggleAttribution);
62
+ this._setElementTitle(this._compactButton, 'ToggleAttribution');
63
+ this._innerContainer = DOM.create('div', 'maplibregl-ctrl-attrib-inner', this._shadowContainer);
64
+
65
+ const style = document.createElement('style');
66
+ style.textContent = `
67
+ .maplibregl-ctrl {
68
+ font: 12px/20px Helvetica Neue,Arial,Helvetica,sans-serif;
69
+ clear: both;
70
+ pointer-events: auto;
71
+ transform: translate(0);
72
+ }
73
+
74
+ .maplibregl-ctrl-attrib-button:focus,.maplibregl-ctrl-group button:focus {
75
+ box-shadow: 0 0 2px 2px #0096ff
76
+ }
77
+
78
+ .maplibregl-ctrl.maplibregl-ctrl-attrib {
79
+ background-color: hsla(0,0%,100%,.5);
80
+ margin: 0;
81
+ padding: 0 5px
82
+ }
83
+
84
+ @media screen {
85
+ .maplibregl-ctrl-attrib.maplibregl-compact {
86
+ background-color: #fff;
87
+ border-radius: 12px;
88
+ box-sizing: content-box;
89
+ min-height: 20px;
90
+ padding: 2px 24px 2px 0;
91
+ position: relative;
92
+ margin: 10px 10px 10px auto;
93
+ width: 0;
94
+ }
95
+
96
+ .maplibregl-ctrl-attrib.maplibregl-compact-show {
97
+ padding: 2px 28px 2px 8px;
98
+ visibility: visible;
99
+ width: auto;
100
+ }
101
+
102
+ .maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact-show,.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact-show {
103
+ border-radius: 12px;
104
+ padding: 2px 8px 2px 28px
105
+ }
106
+
107
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-inner {
108
+ display: none
109
+ }
110
+
111
+ .maplibregl-ctrl-attrib-button {
112
+ background-color: hsla(0,0%,100%,.5);
113
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E");
114
+ border: 0;
115
+ border-radius: 12px;
116
+ box-sizing: border-box;
117
+ cursor: pointer;
118
+ display: none;
119
+ height: 24px;
120
+ outline: none;
121
+ position: absolute;
122
+ right: 0;
123
+ top: 0;
124
+ width: 24px
125
+ }
126
+
127
+ .maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button {
128
+ appearance: none;
129
+ list-style: none
130
+ }
131
+
132
+ .maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button::-webkit-details-marker {
133
+ display: none
134
+ }
135
+
136
+ .maplibregl-ctrl-bottom-left .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-top-left .maplibregl-ctrl-attrib-button {
137
+ left: 0
138
+ }
139
+
140
+ .maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner {
141
+ display: block
142
+ }
143
+
144
+ .maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-button {
145
+ background-color: rgb(0 0 0/5%)
146
+ }
147
+
148
+ .maplibregl-ctrl-bottom-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
149
+ bottom: 0;
150
+ right: 0
151
+ }
152
+
153
+ .maplibregl-ctrl-top-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
154
+ right: 0;
155
+ top: 0
156
+ }
157
+
158
+ .maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
159
+ left: 0;
160
+ top: 0
161
+ }
162
+
163
+ .maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
164
+ bottom: 0;
165
+ left: 0
166
+ }
167
+ }
168
+
169
+ @media screen and (-ms-high-contrast:active) {
170
+ .maplibregl-ctrl-attrib.maplibregl-compact:after {
171
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' fill='%23fff'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E")
172
+ }
173
+ }
174
+
175
+ @media screen and (-ms-high-contrast:black-on-white) {
176
+ .maplibregl-ctrl-attrib.maplibregl-compact:after {
177
+ background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E")
178
+ }
179
+ }
180
+
181
+ .maplibregl-ctrl-attrib a {
182
+ color: rgba(0,0,0,.75);
183
+ text-decoration: none;
184
+ white-space: nowrap;
185
+ }
186
+
187
+ .maplibregl-ctrl-attrib a:hover {
188
+ color: inherit;
189
+ text-decoration: underline
190
+ }
191
+
192
+ .maplibregl-attrib-empty {
193
+ display: none
194
+ }
195
+ `;
196
+
197
+ this._updateAttributions();
198
+ this._updateCompact();
199
+
200
+ this._map.on('styledata', this._updateData);
201
+ this._map.on('sourcedata', this._updateData);
202
+ this._map.on('terrain', this._updateData);
203
+ this._map.on('resize', this._updateCompact);
204
+ this._map.on('drag', this._updateCompactMinimize);
205
+
206
+ shadow.appendChild(style);
207
+ shadow.appendChild(this._shadowContainer);
208
+
209
+ return this._container;
210
+ }
211
+
212
+ onRemove() {
213
+ DOM.remove(this._container);
214
+
215
+ this._map.off('styledata', this._updateData);
216
+ this._map.off('sourcedata', this._updateData);
217
+ this._map.off('terrain', this._updateData);
218
+ this._map.off('resize', this._updateCompact);
219
+ this._map.off('drag', this._updateCompactMinimize);
220
+
221
+ this._map = undefined;
222
+ this._compact = undefined;
223
+ this._attribHTML = undefined;
224
+ }
225
+
226
+ _setElementTitle(element, title) {
227
+ const str = this._map._getUIString(`AttributionControl.${title}`);
228
+ element.title = str;
229
+ element.setAttribute('aria-label', str);
230
+ }
231
+
232
+ _toggleAttribution() {
233
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
234
+ if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
235
+ this._shadowContainer.setAttribute('open', '');
236
+ this._shadowContainer.classList.remove('maplibregl-compact-show');
237
+ } else {
238
+ this._shadowContainer.classList.add('maplibregl-compact-show');
239
+ this._shadowContainer.removeAttribute('open');
240
+ }
241
+ }
242
+ }
243
+
244
+ _updateData(e) {
245
+ if (e && (e.sourceDataType === 'metadata' || e.sourceDataType === 'visibility' || e.dataType === 'style' || e.type === 'terrain')) {
246
+ this._updateAttributions();
247
+ }
248
+ }
249
+
250
+ _updateAttributions() {
251
+ if (!this._map.style) return;
252
+ let attributions = [];
253
+ if (this.options.customAttribution) {
254
+ if (Array.isArray(this.options.customAttribution)) {
255
+ attributions = attributions.concat(
256
+ this.options.customAttribution.map((attribution) => {
257
+ if (typeof attribution !== 'string') return '';
258
+ return attribution;
259
+ }),
260
+ );
261
+ } else if (typeof this.options.customAttribution === 'string') {
262
+ attributions.push(this.options.customAttribution);
263
+ }
264
+ }
265
+
266
+ if (this._map.style.stylesheet) {
267
+ const stylesheet = this._map.style.stylesheet;
268
+ this.styleOwner = stylesheet.owner;
269
+ this.styleId = stylesheet.id;
270
+ }
271
+
272
+ const sourceCaches = this._map.style.sourceCaches;
273
+ for (const id in sourceCaches) {
274
+ const sourceCache = sourceCaches[id];
275
+ if (sourceCache.used || sourceCache.usedForTerrain) {
276
+ const source = sourceCache.getSource();
277
+ if (source.attribution && attributions.indexOf(source.attribution) < 0) {
278
+ attributions.push(source.attribution);
279
+ }
280
+ }
281
+ }
282
+
283
+ // remove any entries that are whitespace
284
+ attributions = attributions.filter((e) => String(e).trim());
285
+
286
+ // remove any entries that are substrings of another entry.
287
+ // first sort by length so that substrings come first
288
+ attributions.sort((a, b) => a.length - b.length);
289
+ attributions = attributions.filter((attrib, i) => {
290
+ for (let j = i + 1; j < attributions.length; j++) {
291
+ if (attributions[j].indexOf(attrib) >= 0) { return false; }
292
+ }
293
+ return true;
294
+ });
295
+
296
+ // check if attribution string is different to minimize DOM changes
297
+ const attribHTML = attributions.join(' | ');
298
+ if (attribHTML === this._attribHTML) return;
299
+
300
+ this._attribHTML = attribHTML;
301
+
302
+ if (attributions.length) {
303
+ this._innerContainer.innerHTML = attribHTML;
304
+ this._shadowContainer.classList.remove('maplibregl-attrib-empty');
305
+ } else {
306
+ this._shadowContainer.classList.add('maplibregl-attrib-empty');
307
+ }
308
+ this._updateCompact();
309
+ // remove old DOM node from _editLink
310
+ this._editLink = null;
311
+ }
312
+
313
+ _updateCompact() {
314
+ if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
315
+ if (this._compact === false) {
316
+ this._shadowContainer.setAttribute('open', '');
317
+ } else if (!this._shadowContainer.classList.contains('maplibregl-compact') && !this._shadowContainer.classList.contains('maplibregl-attrib-empty')) {
318
+ this._shadowContainer.setAttribute('open', '');
319
+ this._shadowContainer.classList.add('maplibregl-compact', 'maplibregl-compact-show');
320
+ }
321
+ } else {
322
+ this._shadowContainer.setAttribute('open', '');
323
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
324
+ this._shadowContainer.classList.remove('maplibregl-compact', 'maplibregl-compact-show');
325
+ }
326
+ }
327
+ }
328
+
329
+ _updateCompactMinimize() {
330
+ if (this._shadowContainer.classList.contains('maplibregl-compact')) {
331
+ if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
332
+ this._shadowContainer.classList.remove('maplibregl-compact-show');
333
+ }
334
+ }
335
+ }
336
+
337
+ }
338
+
339
+ export default CustomAttributionControl;
@@ -2,6 +2,7 @@ import 'whatwg-fetch';
2
2
  import 'promise-polyfill/src/polyfill';
3
3
  import maplibregl from 'maplibre-gl';
4
4
  import GeoloniaControl from '@geolonia/mbgl-geolonia-control';
5
+ import CustomAttributionControl from './CustomAttributionControl';
5
6
  import GestureHandling from '@geolonia/mbgl-gesture-handling';
6
7
  import parseAtts from './parse-atts';
7
8
 
@@ -128,6 +129,8 @@ export default class GeoloniaMap extends maplibregl.Map {
128
129
  const { position: geoloniaControlPosition } = util.parseControlOption(atts.geoloniaControl);
129
130
  map.addControl(new GeoloniaControl(), geoloniaControlPosition);
130
131
 
132
+ map.addControl(new CustomAttributionControl(), 'bottom-right');
133
+
131
134
  const { enabled: fullscreenControlEnabled, position: fullscreenControlPosition } = util.parseControlOption(atts.fullscreenControl);
132
135
  if (fullscreenControlEnabled) {
133
136
  // IE patch for fullscreen mode
@@ -0,0 +1,125 @@
1
+ import Point from '@mapbox/point-geometry';
2
+
3
+ /**
4
+ * This class is a copy of maplibre-gl-js's util DOM class and rewrite it to JavaScript.
5
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/dom.ts
6
+ * */
7
+ export class DOM {
8
+ static #docStyle = typeof window !== 'undefined' && window.document && window.document.documentElement.style;
9
+
10
+ static #userSelect;
11
+
12
+ static #selectProp = DOM.testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
13
+
14
+ static #transformProp = DOM.testProp(['transform', 'WebkitTransform']);
15
+
16
+ static testProp(props) {
17
+ if (!DOM['#docStyle']) return props[0];
18
+ for (let i = 0; i < props.length; i++) {
19
+ if (props[i] in DOM['#docStyle']) {
20
+ return props[i];
21
+ }
22
+ }
23
+ return props[0];
24
+ }
25
+
26
+ static create(tagName, className, container) {
27
+ const el = window.document.createElement(tagName);
28
+ if (className !== undefined) el.className = className;
29
+ if (container) container.appendChild(el);
30
+ return el;
31
+ }
32
+
33
+ static createNS(namespaceURI, tagName) {
34
+ const el = window.document.createElementNS(namespaceURI, tagName);
35
+ return el;
36
+ }
37
+
38
+ static disableDrag() {
39
+ if (DOM['#docStyle'] && DOM['#selectProp']) {
40
+ DOM['#userSelect'] = DOM['#docStyle'][DOM['#selectProp']];
41
+ DOM['#docStyle'][DOM['#selectProp']] = 'none';
42
+ }
43
+ }
44
+
45
+ static enableDrag() {
46
+ if (DOM['#docStyle'] && DOM['#selectProp']) {
47
+ DOM['#docStyle'][DOM['#selectProp']] = DOM['#userSelect'];
48
+ }
49
+ }
50
+
51
+ static setTransform(el, value) {
52
+ el.style[DOM['#transformProp']] = value;
53
+ }
54
+
55
+ static addEventListener(target, type, callback, options) {
56
+ if ('passive' in options) {
57
+ target.addEventListener(type, callback, options);
58
+ } else {
59
+ target.addEventListener(type, callback, options.capture);
60
+ }
61
+ }
62
+
63
+ static removeEventListener(target, type, callback, options) {
64
+ if ('passive' in options) {
65
+ target.removeEventListener(type, callback, options);
66
+ } else {
67
+ target.removeEventListener(type, callback, options.capture);
68
+ }
69
+ }
70
+
71
+ // Suppress the next click, but only if it's immediate.
72
+ static #suppressClickInternal(e) {
73
+ e.preventDefault();
74
+ e.stopPropagation();
75
+ window.removeEventListener('click', DOM['#transformProp'], true);
76
+ }
77
+
78
+ static suppressClick() {
79
+ window.addEventListener('click', DOM['#transformProp'], true);
80
+ window.setTimeout(() => {
81
+ window.removeEventListener('click', DOM['#transformProp'], true);
82
+ }, 0);
83
+ }
84
+
85
+ static mousePos(el, e) {
86
+ const rect = el.getBoundingClientRect();
87
+ return new Point(
88
+ e.clientX - rect.left - el.clientLeft,
89
+ e.clientY - rect.top - el.clientTop,
90
+ );
91
+ }
92
+
93
+ static touchPos(el, touches) {
94
+ const rect = el.getBoundingClientRect();
95
+ const points = [];
96
+ for (let i = 0; i < touches.length; i++) {
97
+ points.push(new Point(
98
+ touches[i].clientX - rect.left - el.clientLeft,
99
+ touches[i].clientY - rect.top - el.clientTop,
100
+ ));
101
+ }
102
+ return points;
103
+ }
104
+
105
+ static mouseButton(e) {
106
+ return e.button;
107
+ }
108
+
109
+ static remove(node) {
110
+ if (node.parentNode) {
111
+ node.parentNode.removeChild(node);
112
+ }
113
+ }
114
+ }
115
+
116
+ /**
117
+ * This function is a copy of maplibre-gl-js's util function and rewrite it to JavaScript.
118
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/util.ts#L223-L228
119
+ * */
120
+ export function bindAll(fns, context) {
121
+ fns.forEach((fn) => {
122
+ if (!context[fn]) { return; }
123
+ context[fn] = context[fn].bind(context);
124
+ });
125
+ }
@@ -1,5 +1,4 @@
1
1
  import urlParse from 'url-parse';
2
- import querystring from 'querystring';
3
2
 
4
3
  export default (document) => {
5
4
  if (typeof window.geolonia === 'undefined') {
@@ -21,10 +20,10 @@ export default (document) => {
21
20
 
22
21
  for (const script of scripts) {
23
22
  const { pathname, query } = urlParse(script.src);
24
- const q = querystring.parse(query.replace(/^\?/, ''));
23
+ const q = new URLSearchParams(query.replace(/^\?/, ''));
25
24
 
26
- if (q['geolonia-api-key']) {
27
- params.key = q['geolonia-api-key'] || 'YOUR-API-KEY';
25
+ if (q.get('geolonia-api-key')) {
26
+ params.key = q.get('geolonia-api-key') || 'YOUR-API-KEY';
28
27
 
29
28
  const res = pathname.match( /^\/(v[0-9.]+)\/embed/ );
30
29
  if (res && res[1]) {
@@ -152,7 +152,7 @@ class SimpleStyleVector {
152
152
  type: 'circle',
153
153
  source: this.sourceName,
154
154
  'source-layer': 'g-simplestyle-v1',
155
- filter: ['==', '$type', 'Point'],
155
+ filter: ['all', ['==', '$type', 'Point'], ['!has', 'marker-symbol']],
156
156
  paint: {
157
157
  'circle-radius': [
158
158
  'case',
@@ -180,11 +180,7 @@ class SimpleStyleVector {
180
180
  'text-halo-width': 1,
181
181
  },
182
182
  layout: {
183
- 'icon-image': [
184
- 'case',
185
- ['==', 'large', ['get', 'marker-size']], ['image', ['concat', ['get', 'marker-symbol'], '-15']],
186
- ['image', ['concat', ['get', 'marker-symbol'], '-11']],
187
- ],
183
+ 'icon-image': ['get', 'marker-symbol'],
188
184
  'text-field': ['get', 'title'],
189
185
  'text-font': ['Noto Sans Regular'],
190
186
  'text-size': 12,
@@ -201,6 +197,7 @@ class SimpleStyleVector {
201
197
  });
202
198
 
203
199
  this.setPopup(map, 'vt-circle-simple-style-points');
200
+ this.setPopup(map, 'vt-geolonia-simple-style-points');
204
201
  }
205
202
 
206
203
  async setPopup(map, source) {