@geolonia/embed 4.3.0 → 5.0.2
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 +99 -36
- package/.nvmrc +1 -1
- package/.prettierrc.json +4 -0
- package/.tool-versions +1 -1
- package/README.md +7 -1
- package/dist/e2e/basic.spec.d.ts +8 -0
- package/dist/e2e/helper.d.ts +4 -0
- package/dist/embed +2 -1
- package/dist/embed-chunks/2489af4328c51b71e92d.js +2 -0
- package/dist/embed-chunks/6e05bbf5f391fda5b858.js +1 -0
- package/dist/embed.js +2 -1
- package/dist/embed.js.LICENSE.txt +4 -0
- package/dist/playwright.config.d.ts +9 -0
- package/dist/{embed.d.ts → src/embed.d.ts} +3 -1
- package/dist/{lib → src/lib}/geolonia-map.d.ts +10 -2
- package/dist/{lib → src/lib}/geolonia-marker.d.ts +1 -2
- package/dist/{lib → src/lib}/maplibre-util.d.ts +1 -3
- package/dist/{lib → src/lib}/util.d.ts +6 -3
- package/dist/src/lib/util.test.d.ts +1 -0
- package/dist/src/testability.test.d.ts +1 -0
- package/dist/src/version.d.ts +1 -0
- package/e2e/basic.spec.ts +52 -0
- package/e2e/helper.ts +12 -0
- package/e2e/map.spec.ts +69 -0
- package/eslint.config.js +232 -0
- package/package.json +25 -12
- package/playwright.config.ts +79 -0
- package/src/embed.ts +13 -7
- package/src/lib/CustomAttributionControl.ts +52 -29
- package/src/lib/geolonia-map.ts +144 -38
- package/src/lib/geolonia-marker.ts +9 -6
- package/src/lib/keyring.test.ts +18 -0
- package/src/lib/keyring.ts +11 -13
- package/src/lib/maplibre-util.ts +31 -19
- package/src/lib/parse-atts.test.ts +2 -1
- package/src/lib/render.ts +18 -7
- package/src/lib/simplestyle-vector.ts +42 -13
- package/src/lib/simplestyle.test.ts +80 -69
- package/src/lib/simplestyle.ts +61 -43
- package/src/lib/util.test.ts +108 -21
- package/src/lib/util.ts +115 -32
- package/src/testability.test.ts +46 -0
- package/tsconfig.json +3 -1
- package/webpack.config.js +10 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -14
- package/.prettierrc.js +0 -1
- package/dist/embed-chunks/b52b89229e47dc93c64b.js +0 -2
- package/dist/embed-chunks/d0f087405f7ae2fcf1c1.js +0 -1
- package/dist/version.d.ts +0 -1
- /package/dist/{lib/keyring.test.d.ts → e2e/map.spec.d.ts} +0 -0
- /package/dist/embed-chunks/{b52b89229e47dc93c64b.js.LICENSE.txt → 2489af4328c51b71e92d.js.LICENSE.txt} +0 -0
- /package/dist/{lib → src/lib}/CustomAttributionControl.d.ts +0 -0
- /package/dist/{lib → src/lib}/controls/geolonia-control.d.ts +0 -0
- /package/dist/{lib → src/lib}/keyring.d.ts +0 -0
- /package/dist/{lib/parse-atts.test.d.ts → src/lib/keyring.test.d.ts} +0 -0
- /package/dist/{lib → src/lib}/parse-atts.d.ts +0 -0
- /package/dist/{lib/simplestyle.test.d.ts → src/lib/parse-atts.test.d.ts} +0 -0
- /package/dist/{lib → src/lib}/render.d.ts +0 -0
- /package/dist/{lib → src/lib}/simplestyle-vector.d.ts +0 -0
- /package/dist/{lib → src/lib}/simplestyle.d.ts +0 -0
- /package/dist/{lib/util.test.d.ts → src/lib/simplestyle.test.d.ts} +0 -0
- /package/dist/{types-internal.d.ts → src/types-internal.d.ts} +0 -0
package/src/lib/maplibre-util.ts
CHANGED
|
@@ -5,18 +5,26 @@ import Point from '@mapbox/point-geometry';
|
|
|
5
5
|
* https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/dom.ts
|
|
6
6
|
* */
|
|
7
7
|
export class DOM {
|
|
8
|
-
static #docStyle =
|
|
8
|
+
static #docStyle =
|
|
9
|
+
typeof window !== 'undefined' &&
|
|
10
|
+
window.document &&
|
|
11
|
+
window.document.documentElement.style;
|
|
9
12
|
|
|
10
13
|
static #userSelect;
|
|
11
14
|
|
|
12
|
-
static #selectProp = DOM.testProp([
|
|
15
|
+
static #selectProp = DOM.testProp([
|
|
16
|
+
'userSelect',
|
|
17
|
+
'MozUserSelect',
|
|
18
|
+
'WebkitUserSelect',
|
|
19
|
+
'msUserSelect',
|
|
20
|
+
]);
|
|
13
21
|
|
|
14
22
|
static #transformProp = DOM.testProp(['transform', 'WebkitTransform']);
|
|
15
23
|
|
|
16
24
|
static testProp(props) {
|
|
17
|
-
if (!DOM
|
|
25
|
+
if (!DOM.#docStyle) return props[0];
|
|
18
26
|
for (let i = 0; i < props.length; i++) {
|
|
19
|
-
if (props[i] in DOM
|
|
27
|
+
if (props[i] in DOM.#docStyle) {
|
|
20
28
|
return props[i];
|
|
21
29
|
}
|
|
22
30
|
}
|
|
@@ -36,20 +44,20 @@ export class DOM {
|
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
static disableDrag() {
|
|
39
|
-
if (DOM
|
|
40
|
-
DOM
|
|
41
|
-
DOM
|
|
47
|
+
if (DOM.#docStyle && DOM.#selectProp) {
|
|
48
|
+
DOM.#userSelect = DOM.#docStyle[DOM.#selectProp];
|
|
49
|
+
DOM.#docStyle[DOM.#selectProp] = 'none';
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
static enableDrag() {
|
|
46
|
-
if (DOM
|
|
47
|
-
DOM
|
|
54
|
+
if (DOM.#docStyle && DOM.#selectProp) {
|
|
55
|
+
DOM.#docStyle[DOM.#selectProp] = DOM.#userSelect;
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
static setTransform(el, value) {
|
|
52
|
-
el.style[DOM
|
|
60
|
+
el.style[DOM.#transformProp] = value;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
static addEventListener(target, type, callback, options) {
|
|
@@ -69,16 +77,16 @@ export class DOM {
|
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
// Suppress the next click, but only if it's immediate.
|
|
72
|
-
static #suppressClickInternal(e) {
|
|
80
|
+
/*static #suppressClickInternal(e) {
|
|
73
81
|
e.preventDefault();
|
|
74
82
|
e.stopPropagation();
|
|
75
83
|
window.removeEventListener('click', DOM['#transformProp'], true);
|
|
76
|
-
}
|
|
84
|
+
}*/
|
|
77
85
|
|
|
78
86
|
static suppressClick() {
|
|
79
|
-
window.addEventListener('click', DOM
|
|
87
|
+
window.addEventListener('click', DOM.#transformProp, true);
|
|
80
88
|
window.setTimeout(() => {
|
|
81
|
-
window.removeEventListener('click', DOM
|
|
89
|
+
window.removeEventListener('click', DOM.#transformProp, true);
|
|
82
90
|
}, 0);
|
|
83
91
|
}
|
|
84
92
|
|
|
@@ -94,10 +102,12 @@ export class DOM {
|
|
|
94
102
|
const rect = el.getBoundingClientRect();
|
|
95
103
|
const points = [];
|
|
96
104
|
for (let i = 0; i < touches.length; i++) {
|
|
97
|
-
points.push(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
points.push(
|
|
106
|
+
new Point(
|
|
107
|
+
touches[i].clientX - rect.left - el.clientLeft,
|
|
108
|
+
touches[i].clientY - rect.top - el.clientTop,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
101
111
|
}
|
|
102
112
|
return points;
|
|
103
113
|
}
|
|
@@ -119,7 +129,9 @@ export class DOM {
|
|
|
119
129
|
* */
|
|
120
130
|
export function bindAll(fns, context) {
|
|
121
131
|
fns.forEach((fn) => {
|
|
122
|
-
if (!context[fn]) {
|
|
132
|
+
if (!context[fn]) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
123
135
|
context[fn] = context[fn].bind(context);
|
|
124
136
|
});
|
|
125
137
|
}
|
|
@@ -4,10 +4,10 @@ import { JSDOM } from 'jsdom';
|
|
|
4
4
|
import { keyring } from './keyring';
|
|
5
5
|
|
|
6
6
|
describe('tests for parse Attributes', () => {
|
|
7
|
-
|
|
8
7
|
const prevWindow = global.window;
|
|
9
8
|
|
|
10
9
|
beforeEach(() => {
|
|
10
|
+
process.env.MAP_PLATFORM_STAGE = 'v1';
|
|
11
11
|
global.window = {
|
|
12
12
|
// @ts-ignore forcefully assigning values to readonly properties
|
|
13
13
|
navigator: { languages: ['ja'] },
|
|
@@ -60,5 +60,6 @@ describe('tests for parse Attributes', () => {
|
|
|
60
60
|
afterEach(() => {
|
|
61
61
|
global.window = prevWindow;
|
|
62
62
|
keyring.reset();
|
|
63
|
+
delete process.env.MAP_PLATFORM_STAGE;
|
|
63
64
|
});
|
|
64
65
|
});
|
package/src/lib/render.ts
CHANGED
|
@@ -13,7 +13,7 @@ export const renderGeoloniaMap = () => {
|
|
|
13
13
|
const protocol = new Protocol();
|
|
14
14
|
maplibregl.addProtocol('pmtiles', protocol.tile);
|
|
15
15
|
|
|
16
|
-
if (
|
|
16
|
+
if (checkPermission()) {
|
|
17
17
|
let isDOMContentLoaded = false;
|
|
18
18
|
const alreadyRenderedMaps = [];
|
|
19
19
|
const isRemoved = Symbol('map-is-removed');
|
|
@@ -35,7 +35,9 @@ export const renderGeoloniaMap = () => {
|
|
|
35
35
|
// remove map instance automatically if the container removed.
|
|
36
36
|
// prevent memory leak
|
|
37
37
|
const observer = new MutationObserver((mutationRecords) => {
|
|
38
|
-
const removed = mutationRecords.some((record) =>
|
|
38
|
+
const removed = mutationRecords.some((record) =>
|
|
39
|
+
[...record.removedNodes].some((node) => node === target),
|
|
40
|
+
);
|
|
39
41
|
if (removed && !map[isRemoved]) {
|
|
40
42
|
map.remove();
|
|
41
43
|
}
|
|
@@ -77,12 +79,16 @@ export const renderGeoloniaMap = () => {
|
|
|
77
79
|
});
|
|
78
80
|
});
|
|
79
81
|
|
|
80
|
-
const containers = document.querySelectorAll(
|
|
81
|
-
|
|
82
|
+
const containers = document.querySelectorAll(
|
|
83
|
+
'.geolonia[data-lazy-loading="off"]',
|
|
84
|
+
);
|
|
85
|
+
const lazyContainers = document.querySelectorAll(
|
|
86
|
+
'.geolonia:not([data-lazy-loading="off"])',
|
|
87
|
+
);
|
|
82
88
|
|
|
83
89
|
// This is required for correct initialization! Don't delete!
|
|
84
90
|
if (!keyring.apiKey) {
|
|
85
|
-
console.error('[Geolonia] Missing API key.') // eslint-disable-line
|
|
91
|
+
console.error('[Geolonia] Missing API key.'); // eslint-disable-line
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
// render Map immediately
|
|
@@ -100,11 +106,16 @@ export const renderGeoloniaMap = () => {
|
|
|
100
106
|
observer.observe(lazyContainers[i]);
|
|
101
107
|
}
|
|
102
108
|
} else {
|
|
103
|
-
|
|
109
|
+
/* eslint-disable-next-line no-console */
|
|
110
|
+
console.error(
|
|
111
|
+
"[Geolonia] We are very sorry, but we can't display our map in iframe.",
|
|
112
|
+
);
|
|
104
113
|
}
|
|
105
114
|
};
|
|
106
115
|
|
|
107
|
-
export const registerPlugin = (
|
|
116
|
+
export const registerPlugin = (
|
|
117
|
+
plugin: (map: GeoloniaMap, target: HTMLElement, atts) => void,
|
|
118
|
+
): void => {
|
|
108
119
|
plugins.push(plugin);
|
|
109
120
|
return void 0;
|
|
110
121
|
};
|
|
@@ -19,21 +19,30 @@ class SimpleStyleVector {
|
|
|
19
19
|
addTo(map) {
|
|
20
20
|
const container = map.getContainer();
|
|
21
21
|
|
|
22
|
-
if (
|
|
22
|
+
if (
|
|
23
|
+
!container.dataset ||
|
|
24
|
+
(!container.dataset.lng && !container.dataset.lat)
|
|
25
|
+
) {
|
|
23
26
|
let initialZoomDone = false;
|
|
24
27
|
map.on('sourcedata', (event) => {
|
|
25
28
|
// skip events for sources that don't concern us
|
|
26
|
-
if (event.sourceId !== this.sourceName) {
|
|
29
|
+
if (event.sourceId !== this.sourceName) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
27
32
|
|
|
28
33
|
const source = map.getSource(event.sourceId);
|
|
29
34
|
// query the map to see if the source is actually loaded or not. We can't trust `isSourceLoaded` in the event
|
|
30
35
|
// because it's unreliable and often incorrect.
|
|
31
36
|
const isLoaded = source && source.loaded();
|
|
32
37
|
|
|
33
|
-
if (isLoaded !== true) {
|
|
38
|
+
if (isLoaded !== true) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
34
41
|
|
|
35
42
|
// Only zoom once.
|
|
36
|
-
if (initialZoomDone) {
|
|
43
|
+
if (initialZoomDone) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
37
46
|
initialZoomDone = true;
|
|
38
47
|
|
|
39
48
|
map.fitBounds(source.bounds, {
|
|
@@ -59,7 +68,11 @@ class SimpleStyleVector {
|
|
|
59
68
|
filter: ['==', '$type', 'Polygon'],
|
|
60
69
|
paint: {
|
|
61
70
|
'text-color': ['string', ['get', 'text-color'], textColor],
|
|
62
|
-
'text-halo-color': [
|
|
71
|
+
'text-halo-color': [
|
|
72
|
+
'string',
|
|
73
|
+
['get', 'text-halo-color'],
|
|
74
|
+
textHaloColor,
|
|
75
|
+
],
|
|
63
76
|
'text-halo-width': 1,
|
|
64
77
|
},
|
|
65
78
|
layout: {
|
|
@@ -79,7 +92,11 @@ class SimpleStyleVector {
|
|
|
79
92
|
filter: ['==', '$type', 'LineString'],
|
|
80
93
|
paint: {
|
|
81
94
|
'text-color': ['string', ['get', 'text-color'], textColor],
|
|
82
|
-
'text-halo-color': [
|
|
95
|
+
'text-halo-color': [
|
|
96
|
+
'string',
|
|
97
|
+
['get', 'text-halo-color'],
|
|
98
|
+
textHaloColor,
|
|
99
|
+
],
|
|
83
100
|
'text-halo-width': 1,
|
|
84
101
|
},
|
|
85
102
|
layout: {
|
|
@@ -158,8 +175,10 @@ class SimpleStyleVector {
|
|
|
158
175
|
paint: {
|
|
159
176
|
'circle-radius': [
|
|
160
177
|
'case',
|
|
161
|
-
['==', 'small', ['get', 'marker-size']],
|
|
162
|
-
|
|
178
|
+
['==', 'small', ['get', 'marker-size']],
|
|
179
|
+
7,
|
|
180
|
+
['==', 'large', ['get', 'marker-size']],
|
|
181
|
+
13,
|
|
163
182
|
9,
|
|
164
183
|
],
|
|
165
184
|
'circle-color': ['string', ['get', 'marker-color'], backgroundColor],
|
|
@@ -178,7 +197,11 @@ class SimpleStyleVector {
|
|
|
178
197
|
filter: ['==', '$type', 'Point'],
|
|
179
198
|
paint: {
|
|
180
199
|
'text-color': ['string', ['get', 'text-color'], textColor],
|
|
181
|
-
'text-halo-color': [
|
|
200
|
+
'text-halo-color': [
|
|
201
|
+
'string',
|
|
202
|
+
['get', 'text-halo-color'],
|
|
203
|
+
textHaloColor,
|
|
204
|
+
],
|
|
182
205
|
'text-halo-width': 1,
|
|
183
206
|
},
|
|
184
207
|
layout: {
|
|
@@ -190,8 +213,10 @@ class SimpleStyleVector {
|
|
|
190
213
|
'text-max-width': 12,
|
|
191
214
|
'text-offset': [
|
|
192
215
|
'case',
|
|
193
|
-
['==', 'small', ['get', 'marker-size']],
|
|
194
|
-
['
|
|
216
|
+
['==', 'small', ['get', 'marker-size']],
|
|
217
|
+
['literal', [0, 1]],
|
|
218
|
+
['==', 'large', ['get', 'marker-size']],
|
|
219
|
+
['literal', [0, 1.6]],
|
|
195
220
|
['literal', [0, 1.2]],
|
|
196
221
|
],
|
|
197
222
|
'text-allow-overlap': false,
|
|
@@ -204,12 +229,16 @@ class SimpleStyleVector {
|
|
|
204
229
|
|
|
205
230
|
async setPopup(map, source) {
|
|
206
231
|
map.on('click', source, async (e) => {
|
|
207
|
-
const center: [
|
|
232
|
+
const center: [number, number] = turfCenter(e.features[0]).geometry
|
|
233
|
+
.coordinates as [number, number];
|
|
208
234
|
const description = e.features[0].properties.description;
|
|
209
235
|
|
|
210
236
|
if (description) {
|
|
211
237
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
212
|
-
new maplibregl.Popup()
|
|
238
|
+
new maplibregl.Popup()
|
|
239
|
+
.setLngLat(center)
|
|
240
|
+
.setHTML(sanitizedDescription)
|
|
241
|
+
.addTo(map);
|
|
213
242
|
}
|
|
214
243
|
});
|
|
215
244
|
|
|
@@ -17,7 +17,10 @@ class Map {
|
|
|
17
17
|
public layers = [];
|
|
18
18
|
public sources = {};
|
|
19
19
|
|
|
20
|
-
constructor(
|
|
20
|
+
constructor(
|
|
21
|
+
private json?,
|
|
22
|
+
private options?,
|
|
23
|
+
) {}
|
|
21
24
|
|
|
22
25
|
addSource(id, source) {
|
|
23
26
|
this.sources[id] = source;
|
|
@@ -27,13 +30,14 @@ class Map {
|
|
|
27
30
|
this.layers.push(layer);
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
on() {
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
+
on() {}
|
|
33
34
|
|
|
34
35
|
getSource(id) {
|
|
35
36
|
class getSource {
|
|
36
|
-
constructor(
|
|
37
|
+
constructor(
|
|
38
|
+
private id,
|
|
39
|
+
private sources,
|
|
40
|
+
) {}
|
|
37
41
|
setData(geojson) {
|
|
38
42
|
this.sources[this.id] = {
|
|
39
43
|
type: 'geojson',
|
|
@@ -56,17 +60,14 @@ class Map {
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
const geojson = {
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
type: 'FeatureCollection',
|
|
64
|
+
features: [
|
|
61
65
|
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
139.77012634277344,
|
|
68
|
-
35.68518697509636,
|
|
69
|
-
],
|
|
66
|
+
type: 'Feature',
|
|
67
|
+
properties: {},
|
|
68
|
+
geometry: {
|
|
69
|
+
type: 'Point',
|
|
70
|
+
coordinates: [139.77012634277344, 35.68518697509636],
|
|
70
71
|
},
|
|
71
72
|
},
|
|
72
73
|
],
|
|
@@ -79,20 +80,36 @@ describe('Tests for simpleStyle()', () => {
|
|
|
79
80
|
const map = new Map();
|
|
80
81
|
new SimpleStyle(geojson).addTo(map).fitBounds();
|
|
81
82
|
|
|
82
|
-
assert.deepEqual(
|
|
83
|
+
assert.deepEqual(
|
|
84
|
+
['geolonia-simple-style', 'geolonia-simple-style-points'],
|
|
85
|
+
Object.keys(map.sources),
|
|
86
|
+
);
|
|
83
87
|
assert.deepEqual(8, map.layers.length);
|
|
84
88
|
assert.deepEqual(true, map.bounds);
|
|
85
|
-
assert.deepEqual(
|
|
86
|
-
|
|
89
|
+
assert.deepEqual(
|
|
90
|
+
true,
|
|
91
|
+
map.layers.find(
|
|
92
|
+
(layer) => layer.id === 'geolonia-simple-style-symbol-points',
|
|
93
|
+
).layout['icon-allow-overlap'],
|
|
94
|
+
);
|
|
95
|
+
assert.deepEqual(
|
|
96
|
+
true,
|
|
97
|
+
map.layers.find(
|
|
98
|
+
(layer) => layer.id === 'geolonia-simple-style-symbol-points',
|
|
99
|
+
).layout['text-allow-overlap'],
|
|
100
|
+
);
|
|
87
101
|
});
|
|
88
102
|
|
|
89
103
|
it('should has sources and layers as expected with custom IDs', async () => {
|
|
90
104
|
const { SimpleStyle } = await import('./simplestyle');
|
|
91
105
|
|
|
92
106
|
const map = new Map();
|
|
93
|
-
new SimpleStyle(geojson, {id: 'hello-world'}).addTo(map).fitBounds();
|
|
107
|
+
new SimpleStyle(geojson, { id: 'hello-world' }).addTo(map).fitBounds();
|
|
94
108
|
|
|
95
|
-
assert.deepEqual(
|
|
109
|
+
assert.deepEqual(
|
|
110
|
+
['hello-world', 'hello-world-points'],
|
|
111
|
+
Object.keys(map.sources),
|
|
112
|
+
);
|
|
96
113
|
assert.deepEqual(8, map.layers.length);
|
|
97
114
|
assert.deepEqual(true, map.bounds);
|
|
98
115
|
});
|
|
@@ -103,13 +120,16 @@ describe('Tests for simpleStyle()', () => {
|
|
|
103
120
|
const map = new Map();
|
|
104
121
|
|
|
105
122
|
const empty = {
|
|
106
|
-
|
|
107
|
-
|
|
123
|
+
type: 'FeatureCollection',
|
|
124
|
+
features: [],
|
|
108
125
|
};
|
|
109
126
|
|
|
110
|
-
new SimpleStyle(empty, {id: 'hello-world'}).addTo(map).fitBounds();
|
|
127
|
+
new SimpleStyle(empty, { id: 'hello-world' }).addTo(map).fitBounds();
|
|
111
128
|
|
|
112
|
-
assert.deepEqual(
|
|
129
|
+
assert.deepEqual(
|
|
130
|
+
['hello-world', 'hello-world-points'],
|
|
131
|
+
Object.keys(map.sources),
|
|
132
|
+
);
|
|
113
133
|
assert.deepEqual(8, map.layers.length);
|
|
114
134
|
assert.deepEqual(false, map.bounds);
|
|
115
135
|
});
|
|
@@ -120,53 +140,52 @@ describe('Tests for simpleStyle()', () => {
|
|
|
120
140
|
const map = new Map();
|
|
121
141
|
|
|
122
142
|
const empty = {
|
|
123
|
-
|
|
124
|
-
|
|
143
|
+
type: 'FeatureCollection',
|
|
144
|
+
features: [],
|
|
125
145
|
};
|
|
126
146
|
|
|
127
147
|
const ss = new SimpleStyle(empty).addTo(map).fitBounds();
|
|
128
148
|
|
|
129
|
-
assert.deepEqual(
|
|
149
|
+
assert.deepEqual(
|
|
150
|
+
['geolonia-simple-style', 'geolonia-simple-style-points'],
|
|
151
|
+
Object.keys(map.sources),
|
|
152
|
+
);
|
|
130
153
|
assert.deepEqual(8, map.layers.length);
|
|
131
154
|
assert.deepEqual(false, map.bounds);
|
|
132
|
-
assert.deepEqual(
|
|
155
|
+
assert.deepEqual(
|
|
156
|
+
0,
|
|
157
|
+
map.sources['geolonia-simple-style-points'].data.features.length,
|
|
158
|
+
);
|
|
133
159
|
|
|
134
160
|
ss.updateData(geojson); // The GeoJSON is not empty.
|
|
135
161
|
assert.deepEqual(false, map.bounds); // `fitBounds()` doesn't fire.
|
|
136
|
-
assert.deepEqual(
|
|
162
|
+
assert.deepEqual(
|
|
163
|
+
1,
|
|
164
|
+
map.sources['geolonia-simple-style-points'].data.features.length,
|
|
165
|
+
);
|
|
137
166
|
});
|
|
138
167
|
|
|
139
168
|
it('should load GeoJSON from url', async () => {
|
|
140
169
|
const { SimpleStyle } = await import('./simplestyle');
|
|
141
170
|
|
|
142
171
|
const map = new Map();
|
|
143
|
-
const geojson =
|
|
172
|
+
const geojson =
|
|
173
|
+
'https://gist.githubusercontent.com/miya0001/56c3dc174f5cdf1d9565cbca0fbd3c48/raw/c13330036d28ef547a8a87cb6df3fa12de19ddb6/test.geojson';
|
|
144
174
|
const ss = new SimpleStyle(geojson);
|
|
145
175
|
ss.addTo(map).fitBounds();
|
|
146
176
|
|
|
147
177
|
await ss._loadingPromise;
|
|
148
178
|
|
|
149
|
-
const geometry =
|
|
179
|
+
const geometry =
|
|
180
|
+
map.sources['geolonia-simple-style'].data.features[0].geometry;
|
|
150
181
|
const coordinates = geometry.coordinates;
|
|
151
182
|
const type = geometry.type;
|
|
152
183
|
|
|
153
184
|
const expectCoordinates = [
|
|
154
|
-
[
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
],
|
|
158
|
-
[
|
|
159
|
-
139.76943969726562,
|
|
160
|
-
35.73425097869431,
|
|
161
|
-
],
|
|
162
|
-
[
|
|
163
|
-
139.73922729492188,
|
|
164
|
-
35.66399091134812,
|
|
165
|
-
],
|
|
166
|
-
[
|
|
167
|
-
139.70352172851562,
|
|
168
|
-
35.698571062054015,
|
|
169
|
-
],
|
|
185
|
+
[139.6870422363281, 35.73425097869431],
|
|
186
|
+
[139.76943969726562, 35.73425097869431],
|
|
187
|
+
[139.73922729492188, 35.66399091134812],
|
|
188
|
+
[139.70352172851562, 35.698571062054015],
|
|
170
189
|
];
|
|
171
190
|
|
|
172
191
|
assert.deepEqual(expectCoordinates, coordinates);
|
|
@@ -184,7 +203,10 @@ describe('Tests for simpleStyle()', () => {
|
|
|
184
203
|
|
|
185
204
|
await ss._loadingPromise;
|
|
186
205
|
|
|
187
|
-
assert.deepEqual(
|
|
206
|
+
assert.deepEqual(
|
|
207
|
+
['geolonia-simple-style', 'geolonia-simple-style-points'],
|
|
208
|
+
Object.keys(map.sources),
|
|
209
|
+
);
|
|
188
210
|
assert.deepEqual(8, map.layers.length);
|
|
189
211
|
assert.deepEqual(false, map.bounds);
|
|
190
212
|
});
|
|
@@ -194,8 +216,8 @@ describe('Tests for simpleStyle()', () => {
|
|
|
194
216
|
|
|
195
217
|
const map = new Map();
|
|
196
218
|
const empty = {
|
|
197
|
-
|
|
198
|
-
|
|
219
|
+
type: 'FeatureCollection',
|
|
220
|
+
features: [],
|
|
199
221
|
};
|
|
200
222
|
|
|
201
223
|
const ss = new SimpleStyle(empty);
|
|
@@ -203,38 +225,27 @@ describe('Tests for simpleStyle()', () => {
|
|
|
203
225
|
|
|
204
226
|
await ss._loadingPromise;
|
|
205
227
|
|
|
206
|
-
const geojson =
|
|
228
|
+
const geojson =
|
|
229
|
+
'https://gist.githubusercontent.com/miya0001/56c3dc174f5cdf1d9565cbca0fbd3c48/raw/c13330036d28ef547a8a87cb6df3fa12de19ddb6/test.geojson';
|
|
207
230
|
|
|
208
231
|
ss.updateData(geojson);
|
|
209
232
|
|
|
210
233
|
await ss._loadingPromise;
|
|
211
234
|
|
|
212
|
-
const geometry =
|
|
235
|
+
const geometry =
|
|
236
|
+
map.sources['geolonia-simple-style'].data.features[0].geometry;
|
|
213
237
|
const coordinates = geometry.coordinates;
|
|
214
238
|
const type = geometry.type;
|
|
215
239
|
|
|
216
240
|
const expectCoordinates = [
|
|
217
|
-
[
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
],
|
|
221
|
-
[
|
|
222
|
-
139.76943969726562,
|
|
223
|
-
35.73425097869431,
|
|
224
|
-
],
|
|
225
|
-
[
|
|
226
|
-
139.73922729492188,
|
|
227
|
-
35.66399091134812,
|
|
228
|
-
],
|
|
229
|
-
[
|
|
230
|
-
139.70352172851562,
|
|
231
|
-
35.698571062054015,
|
|
232
|
-
],
|
|
241
|
+
[139.6870422363281, 35.73425097869431],
|
|
242
|
+
[139.76943969726562, 35.73425097869431],
|
|
243
|
+
[139.73922729492188, 35.66399091134812],
|
|
244
|
+
[139.70352172851562, 35.698571062054015],
|
|
233
245
|
];
|
|
234
246
|
|
|
235
247
|
assert.deepEqual(expectCoordinates, coordinates);
|
|
236
248
|
assert.deepEqual('LineString', type);
|
|
237
249
|
assert.deepEqual(true, map.bounds);
|
|
238
250
|
});
|
|
239
|
-
|
|
240
251
|
});
|