@geolonia/maps-core 0.2.0 → 0.4.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/dist/npm/index.cjs +66 -343
- package/dist/npm/index.d.cts +12 -14
- package/dist/npm/index.d.ts +12 -14
- package/dist/npm/index.js +50 -327
- package/package.json +9 -7
package/dist/npm/index.js
CHANGED
|
@@ -6,296 +6,8 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
6
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
|
|
9
|
-
// node_modules/@mapbox/point-geometry/index.js
|
|
10
|
-
function Point(x, y) {
|
|
11
|
-
this.x = x;
|
|
12
|
-
this.y = y;
|
|
13
|
-
}
|
|
14
|
-
Point.prototype = {
|
|
15
|
-
/**
|
|
16
|
-
* Clone this point, returning a new point that can be modified
|
|
17
|
-
* without affecting the old one.
|
|
18
|
-
* @return {Point} the clone
|
|
19
|
-
*/
|
|
20
|
-
clone() {
|
|
21
|
-
return new Point(this.x, this.y);
|
|
22
|
-
},
|
|
23
|
-
/**
|
|
24
|
-
* Add this point's x & y coordinates to another point,
|
|
25
|
-
* yielding a new point.
|
|
26
|
-
* @param {Point} p the other point
|
|
27
|
-
* @return {Point} output point
|
|
28
|
-
*/
|
|
29
|
-
add(p) {
|
|
30
|
-
return this.clone()._add(p);
|
|
31
|
-
},
|
|
32
|
-
/**
|
|
33
|
-
* Subtract this point's x & y coordinates to from point,
|
|
34
|
-
* yielding a new point.
|
|
35
|
-
* @param {Point} p the other point
|
|
36
|
-
* @return {Point} output point
|
|
37
|
-
*/
|
|
38
|
-
sub(p) {
|
|
39
|
-
return this.clone()._sub(p);
|
|
40
|
-
},
|
|
41
|
-
/**
|
|
42
|
-
* Multiply this point's x & y coordinates by point,
|
|
43
|
-
* yielding a new point.
|
|
44
|
-
* @param {Point} p the other point
|
|
45
|
-
* @return {Point} output point
|
|
46
|
-
*/
|
|
47
|
-
multByPoint(p) {
|
|
48
|
-
return this.clone()._multByPoint(p);
|
|
49
|
-
},
|
|
50
|
-
/**
|
|
51
|
-
* Divide this point's x & y coordinates by point,
|
|
52
|
-
* yielding a new point.
|
|
53
|
-
* @param {Point} p the other point
|
|
54
|
-
* @return {Point} output point
|
|
55
|
-
*/
|
|
56
|
-
divByPoint(p) {
|
|
57
|
-
return this.clone()._divByPoint(p);
|
|
58
|
-
},
|
|
59
|
-
/**
|
|
60
|
-
* Multiply this point's x & y coordinates by a factor,
|
|
61
|
-
* yielding a new point.
|
|
62
|
-
* @param {number} k factor
|
|
63
|
-
* @return {Point} output point
|
|
64
|
-
*/
|
|
65
|
-
mult(k) {
|
|
66
|
-
return this.clone()._mult(k);
|
|
67
|
-
},
|
|
68
|
-
/**
|
|
69
|
-
* Divide this point's x & y coordinates by a factor,
|
|
70
|
-
* yielding a new point.
|
|
71
|
-
* @param {number} k factor
|
|
72
|
-
* @return {Point} output point
|
|
73
|
-
*/
|
|
74
|
-
div(k) {
|
|
75
|
-
return this.clone()._div(k);
|
|
76
|
-
},
|
|
77
|
-
/**
|
|
78
|
-
* Rotate this point around the 0, 0 origin by an angle a,
|
|
79
|
-
* given in radians
|
|
80
|
-
* @param {number} a angle to rotate around, in radians
|
|
81
|
-
* @return {Point} output point
|
|
82
|
-
*/
|
|
83
|
-
rotate(a) {
|
|
84
|
-
return this.clone()._rotate(a);
|
|
85
|
-
},
|
|
86
|
-
/**
|
|
87
|
-
* Rotate this point around p point by an angle a,
|
|
88
|
-
* given in radians
|
|
89
|
-
* @param {number} a angle to rotate around, in radians
|
|
90
|
-
* @param {Point} p Point to rotate around
|
|
91
|
-
* @return {Point} output point
|
|
92
|
-
*/
|
|
93
|
-
rotateAround(a, p) {
|
|
94
|
-
return this.clone()._rotateAround(a, p);
|
|
95
|
-
},
|
|
96
|
-
/**
|
|
97
|
-
* Multiply this point by a 4x1 transformation matrix
|
|
98
|
-
* @param {[number, number, number, number]} m transformation matrix
|
|
99
|
-
* @return {Point} output point
|
|
100
|
-
*/
|
|
101
|
-
matMult(m) {
|
|
102
|
-
return this.clone()._matMult(m);
|
|
103
|
-
},
|
|
104
|
-
/**
|
|
105
|
-
* Calculate this point but as a unit vector from 0, 0, meaning
|
|
106
|
-
* that the distance from the resulting point to the 0, 0
|
|
107
|
-
* coordinate will be equal to 1 and the angle from the resulting
|
|
108
|
-
* point to the 0, 0 coordinate will be the same as before.
|
|
109
|
-
* @return {Point} unit vector point
|
|
110
|
-
*/
|
|
111
|
-
unit() {
|
|
112
|
-
return this.clone()._unit();
|
|
113
|
-
},
|
|
114
|
-
/**
|
|
115
|
-
* Compute a perpendicular point, where the new y coordinate
|
|
116
|
-
* is the old x coordinate and the new x coordinate is the old y
|
|
117
|
-
* coordinate multiplied by -1
|
|
118
|
-
* @return {Point} perpendicular point
|
|
119
|
-
*/
|
|
120
|
-
perp() {
|
|
121
|
-
return this.clone()._perp();
|
|
122
|
-
},
|
|
123
|
-
/**
|
|
124
|
-
* Return a version of this point with the x & y coordinates
|
|
125
|
-
* rounded to integers.
|
|
126
|
-
* @return {Point} rounded point
|
|
127
|
-
*/
|
|
128
|
-
round() {
|
|
129
|
-
return this.clone()._round();
|
|
130
|
-
},
|
|
131
|
-
/**
|
|
132
|
-
* Return the magnitude of this point: this is the Euclidean
|
|
133
|
-
* distance from the 0, 0 coordinate to this point's x and y
|
|
134
|
-
* coordinates.
|
|
135
|
-
* @return {number} magnitude
|
|
136
|
-
*/
|
|
137
|
-
mag() {
|
|
138
|
-
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
139
|
-
},
|
|
140
|
-
/**
|
|
141
|
-
* Judge whether this point is equal to another point, returning
|
|
142
|
-
* true or false.
|
|
143
|
-
* @param {Point} other the other point
|
|
144
|
-
* @return {boolean} whether the points are equal
|
|
145
|
-
*/
|
|
146
|
-
equals(other) {
|
|
147
|
-
return this.x === other.x && this.y === other.y;
|
|
148
|
-
},
|
|
149
|
-
/**
|
|
150
|
-
* Calculate the distance from this point to another point
|
|
151
|
-
* @param {Point} p the other point
|
|
152
|
-
* @return {number} distance
|
|
153
|
-
*/
|
|
154
|
-
dist(p) {
|
|
155
|
-
return Math.sqrt(this.distSqr(p));
|
|
156
|
-
},
|
|
157
|
-
/**
|
|
158
|
-
* Calculate the distance from this point to another point,
|
|
159
|
-
* without the square root step. Useful if you're comparing
|
|
160
|
-
* relative distances.
|
|
161
|
-
* @param {Point} p the other point
|
|
162
|
-
* @return {number} distance
|
|
163
|
-
*/
|
|
164
|
-
distSqr(p) {
|
|
165
|
-
const dx = p.x - this.x, dy = p.y - this.y;
|
|
166
|
-
return dx * dx + dy * dy;
|
|
167
|
-
},
|
|
168
|
-
/**
|
|
169
|
-
* Get the angle from the 0, 0 coordinate to this point, in radians
|
|
170
|
-
* coordinates.
|
|
171
|
-
* @return {number} angle
|
|
172
|
-
*/
|
|
173
|
-
angle() {
|
|
174
|
-
return Math.atan2(this.y, this.x);
|
|
175
|
-
},
|
|
176
|
-
/**
|
|
177
|
-
* Get the angle from this point to another point, in radians
|
|
178
|
-
* @param {Point} b the other point
|
|
179
|
-
* @return {number} angle
|
|
180
|
-
*/
|
|
181
|
-
angleTo(b) {
|
|
182
|
-
return Math.atan2(this.y - b.y, this.x - b.x);
|
|
183
|
-
},
|
|
184
|
-
/**
|
|
185
|
-
* Get the angle between this point and another point, in radians
|
|
186
|
-
* @param {Point} b the other point
|
|
187
|
-
* @return {number} angle
|
|
188
|
-
*/
|
|
189
|
-
angleWith(b) {
|
|
190
|
-
return this.angleWithSep(b.x, b.y);
|
|
191
|
-
},
|
|
192
|
-
/**
|
|
193
|
-
* Find the angle of the two vectors, solving the formula for
|
|
194
|
-
* the cross product a x b = |a||b|sin(θ) for θ.
|
|
195
|
-
* @param {number} x the x-coordinate
|
|
196
|
-
* @param {number} y the y-coordinate
|
|
197
|
-
* @return {number} the angle in radians
|
|
198
|
-
*/
|
|
199
|
-
angleWithSep(x, y) {
|
|
200
|
-
return Math.atan2(
|
|
201
|
-
this.x * y - this.y * x,
|
|
202
|
-
this.x * x + this.y * y
|
|
203
|
-
);
|
|
204
|
-
},
|
|
205
|
-
/** @param {[number, number, number, number]} m */
|
|
206
|
-
_matMult(m) {
|
|
207
|
-
const x = m[0] * this.x + m[1] * this.y, y = m[2] * this.x + m[3] * this.y;
|
|
208
|
-
this.x = x;
|
|
209
|
-
this.y = y;
|
|
210
|
-
return this;
|
|
211
|
-
},
|
|
212
|
-
/** @param {Point} p */
|
|
213
|
-
_add(p) {
|
|
214
|
-
this.x += p.x;
|
|
215
|
-
this.y += p.y;
|
|
216
|
-
return this;
|
|
217
|
-
},
|
|
218
|
-
/** @param {Point} p */
|
|
219
|
-
_sub(p) {
|
|
220
|
-
this.x -= p.x;
|
|
221
|
-
this.y -= p.y;
|
|
222
|
-
return this;
|
|
223
|
-
},
|
|
224
|
-
/** @param {number} k */
|
|
225
|
-
_mult(k) {
|
|
226
|
-
this.x *= k;
|
|
227
|
-
this.y *= k;
|
|
228
|
-
return this;
|
|
229
|
-
},
|
|
230
|
-
/** @param {number} k */
|
|
231
|
-
_div(k) {
|
|
232
|
-
this.x /= k;
|
|
233
|
-
this.y /= k;
|
|
234
|
-
return this;
|
|
235
|
-
},
|
|
236
|
-
/** @param {Point} p */
|
|
237
|
-
_multByPoint(p) {
|
|
238
|
-
this.x *= p.x;
|
|
239
|
-
this.y *= p.y;
|
|
240
|
-
return this;
|
|
241
|
-
},
|
|
242
|
-
/** @param {Point} p */
|
|
243
|
-
_divByPoint(p) {
|
|
244
|
-
this.x /= p.x;
|
|
245
|
-
this.y /= p.y;
|
|
246
|
-
return this;
|
|
247
|
-
},
|
|
248
|
-
_unit() {
|
|
249
|
-
this._div(this.mag());
|
|
250
|
-
return this;
|
|
251
|
-
},
|
|
252
|
-
_perp() {
|
|
253
|
-
const y = this.y;
|
|
254
|
-
this.y = this.x;
|
|
255
|
-
this.x = -y;
|
|
256
|
-
return this;
|
|
257
|
-
},
|
|
258
|
-
/** @param {number} angle */
|
|
259
|
-
_rotate(angle) {
|
|
260
|
-
const cos = Math.cos(angle), sin = Math.sin(angle), x = cos * this.x - sin * this.y, y = sin * this.x + cos * this.y;
|
|
261
|
-
this.x = x;
|
|
262
|
-
this.y = y;
|
|
263
|
-
return this;
|
|
264
|
-
},
|
|
265
|
-
/**
|
|
266
|
-
* @param {number} angle
|
|
267
|
-
* @param {Point} p
|
|
268
|
-
*/
|
|
269
|
-
_rotateAround(angle, p) {
|
|
270
|
-
const cos = Math.cos(angle), sin = Math.sin(angle), x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y), y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
|
|
271
|
-
this.x = x;
|
|
272
|
-
this.y = y;
|
|
273
|
-
return this;
|
|
274
|
-
},
|
|
275
|
-
_round() {
|
|
276
|
-
this.x = Math.round(this.x);
|
|
277
|
-
this.y = Math.round(this.y);
|
|
278
|
-
return this;
|
|
279
|
-
},
|
|
280
|
-
constructor: Point
|
|
281
|
-
};
|
|
282
|
-
Point.convert = function(p) {
|
|
283
|
-
if (p instanceof Point) {
|
|
284
|
-
return (
|
|
285
|
-
/** @type {Point} */
|
|
286
|
-
p
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
if (Array.isArray(p)) {
|
|
290
|
-
return new Point(+p[0], +p[1]);
|
|
291
|
-
}
|
|
292
|
-
if (p.x !== void 0 && p.y !== void 0) {
|
|
293
|
-
return new Point(+p.x, +p.y);
|
|
294
|
-
}
|
|
295
|
-
throw new Error("Expected [x, y] or {x, y} point format");
|
|
296
|
-
};
|
|
297
|
-
|
|
298
9
|
// src/lib/maplibre-util.ts
|
|
10
|
+
import { Point } from "maplibre-gl";
|
|
299
11
|
var _docStyle, _userSelect, _selectProp, _transformProp;
|
|
300
12
|
var _DOM = class _DOM {
|
|
301
13
|
static testProp(props) {
|
|
@@ -516,7 +228,6 @@ var ATTRIBUTION_CSS = `
|
|
|
516
228
|
`;
|
|
517
229
|
var CustomAttributionControl = class {
|
|
518
230
|
constructor(options = {}) {
|
|
519
|
-
this._editLink = null;
|
|
520
231
|
this.options = options;
|
|
521
232
|
bindAll(
|
|
522
233
|
[
|
|
@@ -566,8 +277,8 @@ var CustomAttributionControl = class {
|
|
|
566
277
|
this.printQuery = window.matchMedia("print");
|
|
567
278
|
this.onMediaPrintChange = (e) => {
|
|
568
279
|
if (e.matches) {
|
|
569
|
-
this._shadowContainer
|
|
570
|
-
this._shadowContainer
|
|
280
|
+
this._shadowContainer?.setAttribute("open", "");
|
|
281
|
+
this._shadowContainer?.classList.remove("maplibregl-compact-show");
|
|
571
282
|
}
|
|
572
283
|
};
|
|
573
284
|
this.printQuery.addEventListener("change", this.onMediaPrintChange);
|
|
@@ -615,7 +326,7 @@ var CustomAttributionControl = class {
|
|
|
615
326
|
}
|
|
616
327
|
}
|
|
617
328
|
_updateAttributions() {
|
|
618
|
-
if (!this._map
|
|
329
|
+
if (!this._map?.style) return;
|
|
619
330
|
let attributions = [];
|
|
620
331
|
if (this.options.customAttribution) {
|
|
621
332
|
if (Array.isArray(this.options.customAttribution)) {
|
|
@@ -628,11 +339,6 @@ var CustomAttributionControl = class {
|
|
|
628
339
|
attributions.push(this.options.customAttribution);
|
|
629
340
|
}
|
|
630
341
|
}
|
|
631
|
-
if (this._map.style.stylesheet) {
|
|
632
|
-
const stylesheet = this._map.style.stylesheet;
|
|
633
|
-
this.styleOwner = stylesheet.owner;
|
|
634
|
-
this.styleId = stylesheet.id;
|
|
635
|
-
}
|
|
636
342
|
const sourceCaches = this._map.style.sourceCaches;
|
|
637
343
|
for (const id in sourceCaches) {
|
|
638
344
|
const sourceCache = sourceCaches[id];
|
|
@@ -657,13 +363,12 @@ var CustomAttributionControl = class {
|
|
|
657
363
|
if (attribHTML === this._attribHTML) return;
|
|
658
364
|
this._attribHTML = attribHTML;
|
|
659
365
|
if (attributions.length) {
|
|
660
|
-
this._innerContainer.innerHTML = attribHTML;
|
|
661
|
-
this._shadowContainer
|
|
366
|
+
if (this._innerContainer) this._innerContainer.innerHTML = attribHTML;
|
|
367
|
+
this._shadowContainer?.classList.remove("maplibregl-attrib-empty");
|
|
662
368
|
} else {
|
|
663
|
-
this._shadowContainer
|
|
369
|
+
this._shadowContainer?.classList.add("maplibregl-attrib-empty");
|
|
664
370
|
}
|
|
665
371
|
this._updateCompact();
|
|
666
|
-
this._editLink = null;
|
|
667
372
|
}
|
|
668
373
|
_updateCompact() {
|
|
669
374
|
if (!this._map || !this._shadowContainer) return;
|
|
@@ -775,7 +480,7 @@ var GeoloniaMarker = class extends maplibregl.Marker {
|
|
|
775
480
|
};
|
|
776
481
|
|
|
777
482
|
// src/lib/simplestyle.ts
|
|
778
|
-
import
|
|
483
|
+
import bbox from "@turf/bbox";
|
|
779
484
|
import turfCenter from "@turf/center";
|
|
780
485
|
import maplibregl2 from "maplibre-gl";
|
|
781
486
|
|
|
@@ -823,6 +528,12 @@ var Keyring = class {
|
|
|
823
528
|
if (style.match(/^https?:\/\//)) {
|
|
824
529
|
return false;
|
|
825
530
|
}
|
|
531
|
+
if (style.startsWith("geolonia://")) {
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
if (style.match(/^[a-z][a-z0-9+.-]*:\/\//i)) {
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
826
537
|
if (style.endsWith(".json")) {
|
|
827
538
|
return false;
|
|
828
539
|
}
|
|
@@ -863,7 +574,7 @@ function getStyle(style, options) {
|
|
|
863
574
|
throw new Error("[Geolonia] API key is required to use Geolonia styles.");
|
|
864
575
|
}
|
|
865
576
|
if (!style || style === "") {
|
|
866
|
-
return `https://cdn.geolonia.com/style/geolonia/basic-v2/${lang === "ja" ? "ja" : "en"}.json`;
|
|
577
|
+
return `https://cdn.geolonia.com/style/geolonia/basic-v2/${lang === "ja" || lang === "ja-jp" ? "ja" : "en"}.json`;
|
|
867
578
|
}
|
|
868
579
|
const styleUrl = isURL(style);
|
|
869
580
|
if (styleUrl) {
|
|
@@ -876,7 +587,7 @@ function getStyle(style, options) {
|
|
|
876
587
|
return style;
|
|
877
588
|
}
|
|
878
589
|
}
|
|
879
|
-
return `https://cdn.geolonia.com/style/${style}/${lang === "ja" ? "ja" : "en"}.json`;
|
|
590
|
+
return `https://cdn.geolonia.com/style/${style}/${lang === "ja" || lang === "ja-jp" ? "ja" : "en"}.json`;
|
|
880
591
|
}
|
|
881
592
|
function getLang() {
|
|
882
593
|
if (typeof globalThis.navigator === "undefined") {
|
|
@@ -990,14 +701,16 @@ var SimpleStyle = class {
|
|
|
990
701
|
const points = features.filter(
|
|
991
702
|
(feature) => feature.geometry.type.toLowerCase() === "point"
|
|
992
703
|
);
|
|
993
|
-
this.map.getSource(this.options.id)
|
|
704
|
+
this.map.getSource(this.options.id)?.setData({
|
|
994
705
|
type: "FeatureCollection",
|
|
995
706
|
features: polygonAndLines
|
|
996
707
|
});
|
|
997
|
-
this.map.getSource(`${this.options.id}-points`)
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
708
|
+
this.map.getSource(`${this.options.id}-points`)?.setData(
|
|
709
|
+
{
|
|
710
|
+
type: "FeatureCollection",
|
|
711
|
+
features: points
|
|
712
|
+
}
|
|
713
|
+
);
|
|
1001
714
|
return this;
|
|
1002
715
|
}
|
|
1003
716
|
addTo(map) {
|
|
@@ -1084,7 +797,7 @@ var SimpleStyle = class {
|
|
|
1084
797
|
padding: 30,
|
|
1085
798
|
...options
|
|
1086
799
|
};
|
|
1087
|
-
const bounds =
|
|
800
|
+
const bounds = this.geojson.features.length > 0 ? bbox(this.geojson) : void 0;
|
|
1088
801
|
if (bounds) {
|
|
1089
802
|
window.requestAnimationFrame(() => {
|
|
1090
803
|
this.map.fitBounds(bounds, _options);
|
|
@@ -1193,15 +906,16 @@ var SimpleStyle = class {
|
|
|
1193
906
|
}
|
|
1194
907
|
async setPopup(map, source) {
|
|
1195
908
|
const clickHandler = async (e) => {
|
|
909
|
+
if (!e.features?.[0]) return;
|
|
1196
910
|
const center = turfCenter(e.features[0]).geometry.coordinates;
|
|
1197
|
-
const description = e.features[0].properties
|
|
911
|
+
const description = e.features[0].properties?.description;
|
|
1198
912
|
if (description) {
|
|
1199
913
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
1200
914
|
new maplibregl2.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1201
915
|
}
|
|
1202
916
|
};
|
|
1203
917
|
const mouseEnterHandler = (e) => {
|
|
1204
|
-
if (e.features[0]
|
|
918
|
+
if (e.features?.[0]?.properties?.description) {
|
|
1205
919
|
map.getCanvas().style.cursor = "pointer";
|
|
1206
920
|
}
|
|
1207
921
|
};
|
|
@@ -1248,8 +962,13 @@ var SimpleStyle = class {
|
|
|
1248
962
|
const features = this.map.queryRenderedFeatures(e.point, {
|
|
1249
963
|
layers: [clusterLayer]
|
|
1250
964
|
});
|
|
1251
|
-
|
|
1252
|
-
const
|
|
965
|
+
if (!features[0]) return;
|
|
966
|
+
const clusterId = features[0].properties?.cluster_id;
|
|
967
|
+
if (clusterId === void 0) return;
|
|
968
|
+
const source = this.map.getSource(
|
|
969
|
+
`${this.options.id}-points`
|
|
970
|
+
);
|
|
971
|
+
const zoom = await source.getClusterExpansionZoom(clusterId);
|
|
1253
972
|
this.map.easeTo({
|
|
1254
973
|
center: features[0].geometry.coordinates,
|
|
1255
974
|
zoom
|
|
@@ -1314,7 +1033,7 @@ var SimpleStyle = class {
|
|
|
1314
1033
|
const fetchGeoJSON = async () => {
|
|
1315
1034
|
try {
|
|
1316
1035
|
const response = await window.fetch(geojson);
|
|
1317
|
-
const data = response.ok ? await response.json() :
|
|
1036
|
+
const data = response.ok ? await response.json() : template;
|
|
1318
1037
|
this.geojson = data;
|
|
1319
1038
|
this.updateData(data);
|
|
1320
1039
|
if (this.callFitBounds) {
|
|
@@ -1326,7 +1045,7 @@ var SimpleStyle = class {
|
|
|
1326
1045
|
}
|
|
1327
1046
|
};
|
|
1328
1047
|
this._loadingPromise = fetchGeoJSON();
|
|
1329
|
-
} else {
|
|
1048
|
+
} else if (typeof geojson !== "string") {
|
|
1330
1049
|
this.geojson = geojson;
|
|
1331
1050
|
}
|
|
1332
1051
|
}
|
|
@@ -1344,7 +1063,6 @@ var SimpleStyleVector = class {
|
|
|
1344
1063
|
this.url = url;
|
|
1345
1064
|
this.sourceName = "vt-geolonia-simple-style";
|
|
1346
1065
|
}
|
|
1347
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1348
1066
|
addTo(map) {
|
|
1349
1067
|
const container = map.getContainer();
|
|
1350
1068
|
if (!container.dataset || !container.dataset.lng && !container.dataset.lat) {
|
|
@@ -1354,7 +1072,7 @@ var SimpleStyleVector = class {
|
|
|
1354
1072
|
return;
|
|
1355
1073
|
}
|
|
1356
1074
|
const source = map.getSource(event.sourceId);
|
|
1357
|
-
const isLoaded = source
|
|
1075
|
+
const isLoaded = source?.loaded();
|
|
1358
1076
|
if (isLoaded !== true) {
|
|
1359
1077
|
return;
|
|
1360
1078
|
}
|
|
@@ -1362,10 +1080,13 @@ var SimpleStyleVector = class {
|
|
|
1362
1080
|
return;
|
|
1363
1081
|
}
|
|
1364
1082
|
initialZoomDone = true;
|
|
1365
|
-
map.fitBounds(
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1083
|
+
map.fitBounds(
|
|
1084
|
+
source.bounds,
|
|
1085
|
+
{
|
|
1086
|
+
duration: 0,
|
|
1087
|
+
padding: 30
|
|
1088
|
+
}
|
|
1089
|
+
);
|
|
1369
1090
|
});
|
|
1370
1091
|
}
|
|
1371
1092
|
map.addSource(this.sourceName, {
|
|
@@ -1533,15 +1254,16 @@ var SimpleStyleVector = class {
|
|
|
1533
1254
|
}
|
|
1534
1255
|
async setPopup(map, source) {
|
|
1535
1256
|
map.on("click", source, async (e) => {
|
|
1257
|
+
if (!e.features?.[0]) return;
|
|
1536
1258
|
const center = turfCenter2(e.features[0]).geometry.coordinates;
|
|
1537
|
-
const description = e.features[0].properties
|
|
1259
|
+
const description = e.features[0].properties?.description;
|
|
1538
1260
|
if (description) {
|
|
1539
1261
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
1540
1262
|
new maplibregl3.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1541
1263
|
}
|
|
1542
1264
|
});
|
|
1543
1265
|
map.on("mouseenter", source, (e) => {
|
|
1544
|
-
if (e.features[0]
|
|
1266
|
+
if (e.features?.[0]?.properties?.description) {
|
|
1545
1267
|
map.getCanvas().style.cursor = "pointer";
|
|
1546
1268
|
}
|
|
1547
1269
|
});
|
|
@@ -1561,6 +1283,7 @@ function ensurePMTiles() {
|
|
|
1561
1283
|
maplibregl4.addProtocol("pmtiles", protocol.tile);
|
|
1562
1284
|
}
|
|
1563
1285
|
var GeoloniaMap = class extends maplibregl4.Map {
|
|
1286
|
+
// biome-ignore lint/correctness/noUnreachableSuper: intentional singleton pattern - returns existing map instance before super()
|
|
1564
1287
|
constructor(options) {
|
|
1565
1288
|
ensurePMTiles();
|
|
1566
1289
|
if (options.apiKey) {
|
|
@@ -1717,12 +1440,12 @@ var GeoloniaMap = class extends maplibregl4.Map {
|
|
|
1717
1440
|
}
|
|
1718
1441
|
}
|
|
1719
1442
|
if (options.gestureHandling !== false) {
|
|
1720
|
-
import("@geolonia/
|
|
1443
|
+
import("@geolonia/maplibre-gesture-handling").then(({ default: GestureHandling }) => {
|
|
1721
1444
|
const body = document.body;
|
|
1722
1445
|
const html = document.documentElement;
|
|
1723
1446
|
const isScrollable = body.scrollHeight > body.clientHeight || html.scrollHeight > html.clientHeight;
|
|
1724
1447
|
if (isScrollable) {
|
|
1725
|
-
new GestureHandling({ lang })
|
|
1448
|
+
map.addControl(new GestureHandling({ lang }));
|
|
1726
1449
|
}
|
|
1727
1450
|
}).catch(() => {
|
|
1728
1451
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/maps-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/npm/index.cjs",
|
|
6
6
|
"module": "dist/npm/index.js",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"src/assets/style.css"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@geolonia/
|
|
22
|
-
"@
|
|
23
|
-
"@turf/center": "^
|
|
21
|
+
"@geolonia/maplibre-gesture-handling": "^3.0.0",
|
|
22
|
+
"@turf/bbox": "^7.3.4",
|
|
23
|
+
"@turf/center": "^7.3.4",
|
|
24
24
|
"pmtiles": "^4.4.0",
|
|
25
|
-
"sanitize-html": "^2.
|
|
25
|
+
"sanitize-html": "^2.17.3",
|
|
26
26
|
"tinycolor2": "^1.4.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -33,18 +33,20 @@
|
|
|
33
33
|
"@playwright/test": "^1.58.2",
|
|
34
34
|
"@types/sanitize-html": "^2.16.1",
|
|
35
35
|
"@types/tinycolor2": "^1.4.6",
|
|
36
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
36
37
|
"jsdom": "^29.0.1",
|
|
37
38
|
"maplibre-gl": "5.7.0",
|
|
38
39
|
"tsup": "^8",
|
|
39
40
|
"typescript": "^5.8",
|
|
40
|
-
"vite": "^7.3.
|
|
41
|
-
"vitest": "^
|
|
41
|
+
"vite": "^7.3.2",
|
|
42
|
+
"vitest": "^4.1.2"
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
45
|
"build": "tsup",
|
|
45
46
|
"build:umd": "vite build --config vite.umd.config.ts",
|
|
46
47
|
"test": "vitest run",
|
|
47
48
|
"test:watch": "vitest",
|
|
49
|
+
"test:coverage": "vitest run --coverage",
|
|
48
50
|
"dev": "vite --config vite.config.ts",
|
|
49
51
|
"e2e": "playwright test",
|
|
50
52
|
"lint": "biome check src/ test/ e2e/ example/",
|