@geolonia/embed 2.1.3 → 2.1.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/.github/workflows/build.yml +0 -29
- package/README.md +0 -26
- package/dist/embed +1 -1
- package/dist/embed-chunks/{21811c8ee88c2037c1dc.js → 9c922d7b054813866369.js} +2 -2
- package/dist/embed-chunks/{21811c8ee88c2037c1dc.js.LICENSE.txt → 9c922d7b054813866369.js.LICENSE.txt} +0 -0
- package/dist/embed.js +1 -1
- package/package.json +3 -5
- package/src/embed.js +4 -2
- package/src/lib/CustomAttributionControl.js +317 -0
- package/src/lib/geolonia-map.js +20 -5
- package/src/lib/geolonia-marker.js +1 -1
- package/src/lib/maplibre-util.js +125 -0
- package/src/lib/util.js +1 -1
- package/.dockerignore +0 -5
- package/Dockerfile +0 -48
- package/test/snapshot.test.js +0 -97
- package/test/util.js +0 -96
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/embed",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "Geolonia embed JS API",
|
|
5
5
|
"main": "dist/embed.js",
|
|
6
6
|
"types": "src/embed.d.ts",
|
|
@@ -10,8 +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"
|
|
14
|
-
"test:snapshot": "mkdir -p snapshots && mocha test/snapshot.test.js --timeout 30000"
|
|
13
|
+
"test": "npm run lint && mocha ./src/**/*.test.js --recursive -r jsdom-global/register -r @babel/register"
|
|
15
14
|
},
|
|
16
15
|
"author": "Geolonia (https://geolonia.com)",
|
|
17
16
|
"repository": {
|
|
@@ -38,10 +37,8 @@
|
|
|
38
37
|
"jsdom-global": "^3.0.2",
|
|
39
38
|
"mocha": "^5.2.0",
|
|
40
39
|
"node-fetch": "2",
|
|
41
|
-
"pngjs": "^6.0.0",
|
|
42
40
|
"prettier-eslint": "^12.0.0",
|
|
43
41
|
"prettier-eslint-cli": "^5.0.0",
|
|
44
|
-
"puppeteer": "^9.1.1",
|
|
45
42
|
"style-loader": "^0.23.1",
|
|
46
43
|
"svg-inline-loader": "^0.8.2",
|
|
47
44
|
"webpack": "^5.59.1",
|
|
@@ -53,6 +50,7 @@
|
|
|
53
50
|
"@geolonia/mbgl-geolonia-control": "^0.4.2",
|
|
54
51
|
"@geolonia/mbgl-gesture-handling": "^1.0.15",
|
|
55
52
|
"@mapbox/geojson-extent": "^0.3.2",
|
|
53
|
+
"@mapbox/point-geometry": "^0.1.0",
|
|
56
54
|
"@turf/center": "^6.0.1",
|
|
57
55
|
"core-js": "^3.6.5",
|
|
58
56
|
"intersection-observer": "^0.5.1",
|
package/src/embed.js
CHANGED
|
@@ -13,7 +13,7 @@ import * as util from './lib/util';
|
|
|
13
13
|
import parseAtts from './lib/parse-atts';
|
|
14
14
|
import parseApiKey from './lib/parse-api-key';
|
|
15
15
|
import pkg from '../package.json';
|
|
16
|
-
import
|
|
16
|
+
import SimpleStyle from './lib/simplestyle';
|
|
17
17
|
|
|
18
18
|
if ( util.checkPermission() ) {
|
|
19
19
|
let isDOMContentLoaded = false;
|
|
@@ -88,7 +88,9 @@ if ( util.checkPermission() ) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
window.geolonia.Map = GeoloniaMap;
|
|
91
|
-
window.geolonia.simpleStyle =
|
|
91
|
+
window.geolonia.simpleStyle = // backward compatibility
|
|
92
|
+
window.geolonia.SimpleStyle =
|
|
93
|
+
SimpleStyle;
|
|
92
94
|
window.geolonia.Marker = GeoloniaMarker;
|
|
93
95
|
window.geolonia.AmazonLocationServiceMapProvider = AmazonLocationServiceMapProvider;
|
|
94
96
|
window.geolonia.embedVersion = pkg.version;
|
|
@@ -0,0 +1,317 @@
|
|
|
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
|
+
class CustomAttributionControl {
|
|
9
|
+
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
this._map;
|
|
13
|
+
this._compact;
|
|
14
|
+
this._container;
|
|
15
|
+
this._shadowContainer;
|
|
16
|
+
this._innerContainer;
|
|
17
|
+
this._compactButton;
|
|
18
|
+
this._editLink;
|
|
19
|
+
this._attribHTML;
|
|
20
|
+
this.styleId;
|
|
21
|
+
this.styleOwner;
|
|
22
|
+
|
|
23
|
+
bindAll([
|
|
24
|
+
'_toggleAttribution',
|
|
25
|
+
'_updateData',
|
|
26
|
+
'_updateCompact',
|
|
27
|
+
'_updateCompactMinimize',
|
|
28
|
+
], this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getDefaultPosition() {
|
|
32
|
+
return 'bottom-right';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
onAdd(map) {
|
|
36
|
+
this._map = map;
|
|
37
|
+
this._compact = this.options && this.options.compact;
|
|
38
|
+
this._container = DOM.create('div');
|
|
39
|
+
|
|
40
|
+
const shadow = this._container.attachShadow({mode: 'open'});
|
|
41
|
+
|
|
42
|
+
this._shadowContainer = DOM.create('details', 'maplibregl-ctrl maplibregl-ctrl-attrib');
|
|
43
|
+
this._compactButton = DOM.create('summary', 'maplibregl-ctrl-attrib-button', this._shadowContainer);
|
|
44
|
+
this._compactButton.addEventListener('click', this._toggleAttribution);
|
|
45
|
+
this._setElementTitle(this._compactButton, 'ToggleAttribution');
|
|
46
|
+
this._innerContainer = DOM.create('div', 'maplibregl-ctrl-attrib-inner', this._shadowContainer);
|
|
47
|
+
|
|
48
|
+
const style = document.createElement('style');
|
|
49
|
+
style.textContent = `
|
|
50
|
+
.maplibregl-ctrl {
|
|
51
|
+
clear: both;
|
|
52
|
+
pointer-events: auto;
|
|
53
|
+
transform: translate(0);
|
|
54
|
+
}
|
|
55
|
+
.maplibregl-ctrl-attrib-button:focus,.maplibregl-ctrl-group button:focus {
|
|
56
|
+
box-shadow: 0 0 2px 2px #0096ff
|
|
57
|
+
}
|
|
58
|
+
.maplibregl-ctrl.maplibregl-ctrl-attrib {
|
|
59
|
+
background-color: hsla(0,0%,100%,.5);
|
|
60
|
+
margin: 0;
|
|
61
|
+
padding: 0 5px
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@media screen {
|
|
65
|
+
.maplibregl-ctrl-attrib.maplibregl-compact {
|
|
66
|
+
background-color: #fff;
|
|
67
|
+
border-radius: 12px;
|
|
68
|
+
box-sizing: content-box;
|
|
69
|
+
margin: 10px;
|
|
70
|
+
min-height: 20px;
|
|
71
|
+
padding: 2px 24px 2px 0;
|
|
72
|
+
position: relative
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.maplibregl-ctrl-attrib.maplibregl-compact-show {
|
|
76
|
+
padding: 2px 28px 2px 8px;
|
|
77
|
+
visibility: visible
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact-show,.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact-show {
|
|
81
|
+
border-radius: 12px;
|
|
82
|
+
padding: 2px 8px 2px 28px
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-inner {
|
|
86
|
+
display: none
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.maplibregl-ctrl-attrib-button {
|
|
90
|
+
background-color: hsla(0,0%,100%,.5);
|
|
91
|
+
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");
|
|
92
|
+
border: 0;
|
|
93
|
+
border-radius: 12px;
|
|
94
|
+
box-sizing: border-box;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
display: none;
|
|
97
|
+
height: 24px;
|
|
98
|
+
outline: none;
|
|
99
|
+
position: absolute;
|
|
100
|
+
right: 0;
|
|
101
|
+
top: 0;
|
|
102
|
+
width: 24px
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button {
|
|
106
|
+
appearance: none;
|
|
107
|
+
list-style: none
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button::-webkit-details-marker {
|
|
111
|
+
display: none
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.maplibregl-ctrl-bottom-left .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-top-left .maplibregl-ctrl-attrib-button {
|
|
115
|
+
left: 0
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button,.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner {
|
|
119
|
+
display: block
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-button {
|
|
123
|
+
background-color: rgb(0 0 0/5%)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.maplibregl-ctrl-bottom-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
127
|
+
bottom: 0;
|
|
128
|
+
right: 0
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.maplibregl-ctrl-top-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
132
|
+
right: 0;
|
|
133
|
+
top: 0
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
137
|
+
left: 0;
|
|
138
|
+
top: 0
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
142
|
+
bottom: 0;
|
|
143
|
+
left: 0
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@media screen and (-ms-high-contrast:active) {
|
|
148
|
+
.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
149
|
+
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")
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@media screen and (-ms-high-contrast:black-on-white) {
|
|
154
|
+
.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
155
|
+
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")
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.maplibregl-ctrl-attrib a {
|
|
160
|
+
color: rgba(0,0,0,.75);
|
|
161
|
+
text-decoration: none;
|
|
162
|
+
white-space: nowrap;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.maplibregl-ctrl-attrib a:hover {
|
|
166
|
+
color: inherit;
|
|
167
|
+
text-decoration: underline
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.maplibregl-attrib-empty {
|
|
171
|
+
display: none
|
|
172
|
+
}
|
|
173
|
+
`;
|
|
174
|
+
|
|
175
|
+
this._updateAttributions();
|
|
176
|
+
this._updateCompact();
|
|
177
|
+
|
|
178
|
+
this._map.on('styledata', this._updateData);
|
|
179
|
+
this._map.on('sourcedata', this._updateData);
|
|
180
|
+
this._map.on('terrain', this._updateData);
|
|
181
|
+
this._map.on('resize', this._updateCompact);
|
|
182
|
+
this._map.on('drag', this._updateCompactMinimize);
|
|
183
|
+
|
|
184
|
+
shadow.appendChild(style);
|
|
185
|
+
shadow.appendChild(this._shadowContainer);
|
|
186
|
+
|
|
187
|
+
return this._container;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
onRemove() {
|
|
191
|
+
DOM.remove(this._container);
|
|
192
|
+
|
|
193
|
+
this._map.off('styledata', this._updateData);
|
|
194
|
+
this._map.off('sourcedata', this._updateData);
|
|
195
|
+
this._map.off('terrain', this._updateData);
|
|
196
|
+
this._map.off('resize', this._updateCompact);
|
|
197
|
+
this._map.off('drag', this._updateCompactMinimize);
|
|
198
|
+
|
|
199
|
+
this._map = undefined;
|
|
200
|
+
this._compact = undefined;
|
|
201
|
+
this._attribHTML = undefined;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
_setElementTitle(element, title) {
|
|
205
|
+
const str = this._map._getUIString(`AttributionControl.${title}`);
|
|
206
|
+
element.title = str;
|
|
207
|
+
element.setAttribute('aria-label', str);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
_toggleAttribution() {
|
|
211
|
+
if (this._shadowContainer.classList.contains('maplibregl-compact')) {
|
|
212
|
+
if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
|
|
213
|
+
this._shadowContainer.setAttribute('open', '');
|
|
214
|
+
this._shadowContainer.classList.remove('maplibregl-compact-show');
|
|
215
|
+
} else {
|
|
216
|
+
this._shadowContainer.classList.add('maplibregl-compact-show');
|
|
217
|
+
this._shadowContainer.removeAttribute('open');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
_updateData(e) {
|
|
223
|
+
if (e && (e.sourceDataType === 'metadata' || e.sourceDataType === 'visibility' || e.dataType === 'style' || e.type === 'terrain')) {
|
|
224
|
+
this._updateAttributions();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_updateAttributions() {
|
|
229
|
+
if (!this._map.style) return;
|
|
230
|
+
let attributions = [];
|
|
231
|
+
if (this.options.customAttribution) {
|
|
232
|
+
if (Array.isArray(this.options.customAttribution)) {
|
|
233
|
+
attributions = attributions.concat(
|
|
234
|
+
this.options.customAttribution.map((attribution) => {
|
|
235
|
+
if (typeof attribution !== 'string') return '';
|
|
236
|
+
return attribution;
|
|
237
|
+
}),
|
|
238
|
+
);
|
|
239
|
+
} else if (typeof this.options.customAttribution === 'string') {
|
|
240
|
+
attributions.push(this.options.customAttribution);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (this._map.style.stylesheet) {
|
|
245
|
+
const stylesheet = this._map.style.stylesheet;
|
|
246
|
+
this.styleOwner = stylesheet.owner;
|
|
247
|
+
this.styleId = stylesheet.id;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const sourceCaches = this._map.style.sourceCaches;
|
|
251
|
+
for (const id in sourceCaches) {
|
|
252
|
+
const sourceCache = sourceCaches[id];
|
|
253
|
+
if (sourceCache.used || sourceCache.usedForTerrain) {
|
|
254
|
+
const source = sourceCache.getSource();
|
|
255
|
+
if (source.attribution && attributions.indexOf(source.attribution) < 0) {
|
|
256
|
+
attributions.push(source.attribution);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// remove any entries that are whitespace
|
|
262
|
+
attributions = attributions.filter((e) => String(e).trim());
|
|
263
|
+
|
|
264
|
+
// remove any entries that are substrings of another entry.
|
|
265
|
+
// first sort by length so that substrings come first
|
|
266
|
+
attributions.sort((a, b) => a.length - b.length);
|
|
267
|
+
attributions = attributions.filter((attrib, i) => {
|
|
268
|
+
for (let j = i + 1; j < attributions.length; j++) {
|
|
269
|
+
if (attributions[j].indexOf(attrib) >= 0) { return false; }
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// check if attribution string is different to minimize DOM changes
|
|
275
|
+
const attribHTML = attributions.join(' | ');
|
|
276
|
+
if (attribHTML === this._attribHTML) return;
|
|
277
|
+
|
|
278
|
+
this._attribHTML = attribHTML;
|
|
279
|
+
|
|
280
|
+
if (attributions.length) {
|
|
281
|
+
this._innerContainer.innerHTML = attribHTML;
|
|
282
|
+
this._shadowContainer.classList.remove('maplibregl-attrib-empty');
|
|
283
|
+
} else {
|
|
284
|
+
this._shadowContainer.classList.add('maplibregl-attrib-empty');
|
|
285
|
+
}
|
|
286
|
+
this._updateCompact();
|
|
287
|
+
// remove old DOM node from _editLink
|
|
288
|
+
this._editLink = null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
_updateCompact() {
|
|
292
|
+
if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
|
|
293
|
+
if (this._compact === false) {
|
|
294
|
+
this._shadowContainer.setAttribute('open', '');
|
|
295
|
+
} else if (!this._shadowContainer.classList.contains('maplibregl-compact') && !this._shadowContainer.classList.contains('maplibregl-attrib-empty')) {
|
|
296
|
+
this._shadowContainer.setAttribute('open', '');
|
|
297
|
+
this._shadowContainer.classList.add('maplibregl-compact', 'maplibregl-compact-show');
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
this._shadowContainer.setAttribute('open', '');
|
|
301
|
+
if (this._shadowContainer.classList.contains('maplibregl-compact')) {
|
|
302
|
+
this._shadowContainer.classList.remove('maplibregl-compact', 'maplibregl-compact-show');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
_updateCompactMinimize() {
|
|
308
|
+
if (this._shadowContainer.classList.contains('maplibregl-compact')) {
|
|
309
|
+
if (this._shadowContainer.classList.contains('maplibregl-compact-show')) {
|
|
310
|
+
this._shadowContainer.classList.remove('maplibregl-compact-show');
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export default CustomAttributionControl;
|
package/src/lib/geolonia-map.js
CHANGED
|
@@ -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
|
|
|
@@ -84,15 +85,27 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
const transformedUrlObj = new URL(transformedUrl);
|
|
89
|
+
|
|
87
90
|
if (resourceType === 'Source' && transformedUrl.startsWith('https://tileserver.geolonia.com')) {
|
|
88
|
-
const tileserverSourcesUrl = new URL(transformedUrl);
|
|
89
91
|
if (atts.stage !== 'v1') {
|
|
90
|
-
|
|
92
|
+
transformedUrlObj.hostname = `tileserver-${atts.stage}.geolonia.com`;
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
transformedUrlObj.searchParams.set('sessionId', sessionId);
|
|
95
|
+
transformedUrlObj.searchParams.set('key', atts.key);
|
|
94
96
|
return {
|
|
95
|
-
url:
|
|
97
|
+
url: transformedUrlObj.toString(),
|
|
98
|
+
};
|
|
99
|
+
} else if (
|
|
100
|
+
(resourceType === 'SpriteJSON' || resourceType === 'SpriteImage') &&
|
|
101
|
+
transformedUrl.match(/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//)
|
|
102
|
+
) {
|
|
103
|
+
const pathParts = transformedUrlObj.pathname.split('/');
|
|
104
|
+
pathParts[1] = atts.stage;
|
|
105
|
+
transformedUrlObj.pathname = pathParts.join('/');
|
|
106
|
+
transformedUrlObj.searchParams.set('key', atts.key);
|
|
107
|
+
return {
|
|
108
|
+
url: transformedUrlObj.toString(),
|
|
96
109
|
};
|
|
97
110
|
}
|
|
98
111
|
|
|
@@ -116,6 +129,8 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
116
129
|
const { position: geoloniaControlPosition } = util.parseControlOption(atts.geoloniaControl);
|
|
117
130
|
map.addControl(new GeoloniaControl(), geoloniaControlPosition);
|
|
118
131
|
|
|
132
|
+
map.addControl(new CustomAttributionControl(), 'bottom-right');
|
|
133
|
+
|
|
119
134
|
const { enabled: fullscreenControlEnabled, position: fullscreenControlPosition } = util.parseControlOption(atts.fullscreenControl);
|
|
120
135
|
if (fullscreenControlEnabled) {
|
|
121
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
|
+
}
|
package/src/lib/util.js
CHANGED
|
@@ -201,7 +201,7 @@ export function getOptions(container, params, atts) {
|
|
|
201
201
|
zoom: parseFloat(atts.zoom),
|
|
202
202
|
hash: (atts.hash === 'on'),
|
|
203
203
|
localIdeographFontFamily: 'sans-serif',
|
|
204
|
-
attributionControl:
|
|
204
|
+
attributionControl: false,
|
|
205
205
|
};
|
|
206
206
|
|
|
207
207
|
if (atts.minZoom !== '' && (Number(atts.minZoom) === 0 || Number(atts.minZoom))) {
|
package/.dockerignore
DELETED
package/Dockerfile
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
FROM node:14
|
|
2
|
-
WORKDIR /app
|
|
3
|
-
RUN apt-get update && apt-get install -y \
|
|
4
|
-
gconf-service \
|
|
5
|
-
libasound2 \
|
|
6
|
-
libatk1.0-0 \
|
|
7
|
-
libc6 \
|
|
8
|
-
libcairo2 \
|
|
9
|
-
libcups2 \
|
|
10
|
-
libdbus-1-3 \
|
|
11
|
-
libexpat1 \
|
|
12
|
-
libfontconfig1 \
|
|
13
|
-
libgcc1 \
|
|
14
|
-
libgconf-2-4 \
|
|
15
|
-
libgdk-pixbuf2.0-0 \
|
|
16
|
-
libglib2.0-0 \
|
|
17
|
-
libgtk-3-0 \
|
|
18
|
-
libnspr4 \
|
|
19
|
-
libpango-1.0-0 \
|
|
20
|
-
libpangocairo-1.0-0 \
|
|
21
|
-
libstdc++6 \
|
|
22
|
-
libx11-6 \
|
|
23
|
-
libx11-xcb1 \
|
|
24
|
-
libxcb1 \
|
|
25
|
-
libxcomposite1 \
|
|
26
|
-
libxcursor1 \
|
|
27
|
-
libxdamage1 \
|
|
28
|
-
libxext6 \
|
|
29
|
-
libxfixes3 \
|
|
30
|
-
libxi6 \
|
|
31
|
-
libxrandr2 \
|
|
32
|
-
libxrender1 \
|
|
33
|
-
libxss1 \
|
|
34
|
-
libxtst6 \
|
|
35
|
-
ca-certificates \
|
|
36
|
-
fonts-liberation \
|
|
37
|
-
libappindicator1 \
|
|
38
|
-
libnss3 \
|
|
39
|
-
lsb-release \
|
|
40
|
-
xdg-utils \
|
|
41
|
-
wget \
|
|
42
|
-
fonts-ipafont-mincho \
|
|
43
|
-
fonts-ipafont-gothic
|
|
44
|
-
COPY . .
|
|
45
|
-
RUN yarn install
|
|
46
|
-
ENV GEOLONIA_API_KEY=YOUR-API-KEY
|
|
47
|
-
ENV NO_SANDBOX=true
|
|
48
|
-
ENTRYPOINT ["yarn", "test:snapshot"]
|