@geolonia/maps-core 0.3.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 +64 -341
- package/dist/npm/index.d.cts +12 -14
- package/dist/npm/index.d.ts +12 -14
- package/dist/npm/index.js +48 -325
- package/package.json +3 -3
package/dist/npm/index.cjs
CHANGED
|
@@ -51,296 +51,8 @@ __export(index_exports, {
|
|
|
51
51
|
});
|
|
52
52
|
module.exports = __toCommonJS(index_exports);
|
|
53
53
|
|
|
54
|
-
// node_modules/@mapbox/point-geometry/index.js
|
|
55
|
-
function Point(x, y) {
|
|
56
|
-
this.x = x;
|
|
57
|
-
this.y = y;
|
|
58
|
-
}
|
|
59
|
-
Point.prototype = {
|
|
60
|
-
/**
|
|
61
|
-
* Clone this point, returning a new point that can be modified
|
|
62
|
-
* without affecting the old one.
|
|
63
|
-
* @return {Point} the clone
|
|
64
|
-
*/
|
|
65
|
-
clone() {
|
|
66
|
-
return new Point(this.x, this.y);
|
|
67
|
-
},
|
|
68
|
-
/**
|
|
69
|
-
* Add this point's x & y coordinates to another point,
|
|
70
|
-
* yielding a new point.
|
|
71
|
-
* @param {Point} p the other point
|
|
72
|
-
* @return {Point} output point
|
|
73
|
-
*/
|
|
74
|
-
add(p) {
|
|
75
|
-
return this.clone()._add(p);
|
|
76
|
-
},
|
|
77
|
-
/**
|
|
78
|
-
* Subtract this point's x & y coordinates to from point,
|
|
79
|
-
* yielding a new point.
|
|
80
|
-
* @param {Point} p the other point
|
|
81
|
-
* @return {Point} output point
|
|
82
|
-
*/
|
|
83
|
-
sub(p) {
|
|
84
|
-
return this.clone()._sub(p);
|
|
85
|
-
},
|
|
86
|
-
/**
|
|
87
|
-
* Multiply this point's x & y coordinates by point,
|
|
88
|
-
* yielding a new point.
|
|
89
|
-
* @param {Point} p the other point
|
|
90
|
-
* @return {Point} output point
|
|
91
|
-
*/
|
|
92
|
-
multByPoint(p) {
|
|
93
|
-
return this.clone()._multByPoint(p);
|
|
94
|
-
},
|
|
95
|
-
/**
|
|
96
|
-
* Divide this point's x & y coordinates by point,
|
|
97
|
-
* yielding a new point.
|
|
98
|
-
* @param {Point} p the other point
|
|
99
|
-
* @return {Point} output point
|
|
100
|
-
*/
|
|
101
|
-
divByPoint(p) {
|
|
102
|
-
return this.clone()._divByPoint(p);
|
|
103
|
-
},
|
|
104
|
-
/**
|
|
105
|
-
* Multiply this point's x & y coordinates by a factor,
|
|
106
|
-
* yielding a new point.
|
|
107
|
-
* @param {number} k factor
|
|
108
|
-
* @return {Point} output point
|
|
109
|
-
*/
|
|
110
|
-
mult(k) {
|
|
111
|
-
return this.clone()._mult(k);
|
|
112
|
-
},
|
|
113
|
-
/**
|
|
114
|
-
* Divide this point's x & y coordinates by a factor,
|
|
115
|
-
* yielding a new point.
|
|
116
|
-
* @param {number} k factor
|
|
117
|
-
* @return {Point} output point
|
|
118
|
-
*/
|
|
119
|
-
div(k) {
|
|
120
|
-
return this.clone()._div(k);
|
|
121
|
-
},
|
|
122
|
-
/**
|
|
123
|
-
* Rotate this point around the 0, 0 origin by an angle a,
|
|
124
|
-
* given in radians
|
|
125
|
-
* @param {number} a angle to rotate around, in radians
|
|
126
|
-
* @return {Point} output point
|
|
127
|
-
*/
|
|
128
|
-
rotate(a) {
|
|
129
|
-
return this.clone()._rotate(a);
|
|
130
|
-
},
|
|
131
|
-
/**
|
|
132
|
-
* Rotate this point around p point by an angle a,
|
|
133
|
-
* given in radians
|
|
134
|
-
* @param {number} a angle to rotate around, in radians
|
|
135
|
-
* @param {Point} p Point to rotate around
|
|
136
|
-
* @return {Point} output point
|
|
137
|
-
*/
|
|
138
|
-
rotateAround(a, p) {
|
|
139
|
-
return this.clone()._rotateAround(a, p);
|
|
140
|
-
},
|
|
141
|
-
/**
|
|
142
|
-
* Multiply this point by a 4x1 transformation matrix
|
|
143
|
-
* @param {[number, number, number, number]} m transformation matrix
|
|
144
|
-
* @return {Point} output point
|
|
145
|
-
*/
|
|
146
|
-
matMult(m) {
|
|
147
|
-
return this.clone()._matMult(m);
|
|
148
|
-
},
|
|
149
|
-
/**
|
|
150
|
-
* Calculate this point but as a unit vector from 0, 0, meaning
|
|
151
|
-
* that the distance from the resulting point to the 0, 0
|
|
152
|
-
* coordinate will be equal to 1 and the angle from the resulting
|
|
153
|
-
* point to the 0, 0 coordinate will be the same as before.
|
|
154
|
-
* @return {Point} unit vector point
|
|
155
|
-
*/
|
|
156
|
-
unit() {
|
|
157
|
-
return this.clone()._unit();
|
|
158
|
-
},
|
|
159
|
-
/**
|
|
160
|
-
* Compute a perpendicular point, where the new y coordinate
|
|
161
|
-
* is the old x coordinate and the new x coordinate is the old y
|
|
162
|
-
* coordinate multiplied by -1
|
|
163
|
-
* @return {Point} perpendicular point
|
|
164
|
-
*/
|
|
165
|
-
perp() {
|
|
166
|
-
return this.clone()._perp();
|
|
167
|
-
},
|
|
168
|
-
/**
|
|
169
|
-
* Return a version of this point with the x & y coordinates
|
|
170
|
-
* rounded to integers.
|
|
171
|
-
* @return {Point} rounded point
|
|
172
|
-
*/
|
|
173
|
-
round() {
|
|
174
|
-
return this.clone()._round();
|
|
175
|
-
},
|
|
176
|
-
/**
|
|
177
|
-
* Return the magnitude of this point: this is the Euclidean
|
|
178
|
-
* distance from the 0, 0 coordinate to this point's x and y
|
|
179
|
-
* coordinates.
|
|
180
|
-
* @return {number} magnitude
|
|
181
|
-
*/
|
|
182
|
-
mag() {
|
|
183
|
-
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
184
|
-
},
|
|
185
|
-
/**
|
|
186
|
-
* Judge whether this point is equal to another point, returning
|
|
187
|
-
* true or false.
|
|
188
|
-
* @param {Point} other the other point
|
|
189
|
-
* @return {boolean} whether the points are equal
|
|
190
|
-
*/
|
|
191
|
-
equals(other) {
|
|
192
|
-
return this.x === other.x && this.y === other.y;
|
|
193
|
-
},
|
|
194
|
-
/**
|
|
195
|
-
* Calculate the distance from this point to another point
|
|
196
|
-
* @param {Point} p the other point
|
|
197
|
-
* @return {number} distance
|
|
198
|
-
*/
|
|
199
|
-
dist(p) {
|
|
200
|
-
return Math.sqrt(this.distSqr(p));
|
|
201
|
-
},
|
|
202
|
-
/**
|
|
203
|
-
* Calculate the distance from this point to another point,
|
|
204
|
-
* without the square root step. Useful if you're comparing
|
|
205
|
-
* relative distances.
|
|
206
|
-
* @param {Point} p the other point
|
|
207
|
-
* @return {number} distance
|
|
208
|
-
*/
|
|
209
|
-
distSqr(p) {
|
|
210
|
-
const dx = p.x - this.x, dy = p.y - this.y;
|
|
211
|
-
return dx * dx + dy * dy;
|
|
212
|
-
},
|
|
213
|
-
/**
|
|
214
|
-
* Get the angle from the 0, 0 coordinate to this point, in radians
|
|
215
|
-
* coordinates.
|
|
216
|
-
* @return {number} angle
|
|
217
|
-
*/
|
|
218
|
-
angle() {
|
|
219
|
-
return Math.atan2(this.y, this.x);
|
|
220
|
-
},
|
|
221
|
-
/**
|
|
222
|
-
* Get the angle from this point to another point, in radians
|
|
223
|
-
* @param {Point} b the other point
|
|
224
|
-
* @return {number} angle
|
|
225
|
-
*/
|
|
226
|
-
angleTo(b) {
|
|
227
|
-
return Math.atan2(this.y - b.y, this.x - b.x);
|
|
228
|
-
},
|
|
229
|
-
/**
|
|
230
|
-
* Get the angle between this point and another point, in radians
|
|
231
|
-
* @param {Point} b the other point
|
|
232
|
-
* @return {number} angle
|
|
233
|
-
*/
|
|
234
|
-
angleWith(b) {
|
|
235
|
-
return this.angleWithSep(b.x, b.y);
|
|
236
|
-
},
|
|
237
|
-
/**
|
|
238
|
-
* Find the angle of the two vectors, solving the formula for
|
|
239
|
-
* the cross product a x b = |a||b|sin(θ) for θ.
|
|
240
|
-
* @param {number} x the x-coordinate
|
|
241
|
-
* @param {number} y the y-coordinate
|
|
242
|
-
* @return {number} the angle in radians
|
|
243
|
-
*/
|
|
244
|
-
angleWithSep(x, y) {
|
|
245
|
-
return Math.atan2(
|
|
246
|
-
this.x * y - this.y * x,
|
|
247
|
-
this.x * x + this.y * y
|
|
248
|
-
);
|
|
249
|
-
},
|
|
250
|
-
/** @param {[number, number, number, number]} m */
|
|
251
|
-
_matMult(m) {
|
|
252
|
-
const x = m[0] * this.x + m[1] * this.y, y = m[2] * this.x + m[3] * this.y;
|
|
253
|
-
this.x = x;
|
|
254
|
-
this.y = y;
|
|
255
|
-
return this;
|
|
256
|
-
},
|
|
257
|
-
/** @param {Point} p */
|
|
258
|
-
_add(p) {
|
|
259
|
-
this.x += p.x;
|
|
260
|
-
this.y += p.y;
|
|
261
|
-
return this;
|
|
262
|
-
},
|
|
263
|
-
/** @param {Point} p */
|
|
264
|
-
_sub(p) {
|
|
265
|
-
this.x -= p.x;
|
|
266
|
-
this.y -= p.y;
|
|
267
|
-
return this;
|
|
268
|
-
},
|
|
269
|
-
/** @param {number} k */
|
|
270
|
-
_mult(k) {
|
|
271
|
-
this.x *= k;
|
|
272
|
-
this.y *= k;
|
|
273
|
-
return this;
|
|
274
|
-
},
|
|
275
|
-
/** @param {number} k */
|
|
276
|
-
_div(k) {
|
|
277
|
-
this.x /= k;
|
|
278
|
-
this.y /= k;
|
|
279
|
-
return this;
|
|
280
|
-
},
|
|
281
|
-
/** @param {Point} p */
|
|
282
|
-
_multByPoint(p) {
|
|
283
|
-
this.x *= p.x;
|
|
284
|
-
this.y *= p.y;
|
|
285
|
-
return this;
|
|
286
|
-
},
|
|
287
|
-
/** @param {Point} p */
|
|
288
|
-
_divByPoint(p) {
|
|
289
|
-
this.x /= p.x;
|
|
290
|
-
this.y /= p.y;
|
|
291
|
-
return this;
|
|
292
|
-
},
|
|
293
|
-
_unit() {
|
|
294
|
-
this._div(this.mag());
|
|
295
|
-
return this;
|
|
296
|
-
},
|
|
297
|
-
_perp() {
|
|
298
|
-
const y = this.y;
|
|
299
|
-
this.y = this.x;
|
|
300
|
-
this.x = -y;
|
|
301
|
-
return this;
|
|
302
|
-
},
|
|
303
|
-
/** @param {number} angle */
|
|
304
|
-
_rotate(angle) {
|
|
305
|
-
const cos = Math.cos(angle), sin = Math.sin(angle), x = cos * this.x - sin * this.y, y = sin * this.x + cos * this.y;
|
|
306
|
-
this.x = x;
|
|
307
|
-
this.y = y;
|
|
308
|
-
return this;
|
|
309
|
-
},
|
|
310
|
-
/**
|
|
311
|
-
* @param {number} angle
|
|
312
|
-
* @param {Point} p
|
|
313
|
-
*/
|
|
314
|
-
_rotateAround(angle, p) {
|
|
315
|
-
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);
|
|
316
|
-
this.x = x;
|
|
317
|
-
this.y = y;
|
|
318
|
-
return this;
|
|
319
|
-
},
|
|
320
|
-
_round() {
|
|
321
|
-
this.x = Math.round(this.x);
|
|
322
|
-
this.y = Math.round(this.y);
|
|
323
|
-
return this;
|
|
324
|
-
},
|
|
325
|
-
constructor: Point
|
|
326
|
-
};
|
|
327
|
-
Point.convert = function(p) {
|
|
328
|
-
if (p instanceof Point) {
|
|
329
|
-
return (
|
|
330
|
-
/** @type {Point} */
|
|
331
|
-
p
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
if (Array.isArray(p)) {
|
|
335
|
-
return new Point(+p[0], +p[1]);
|
|
336
|
-
}
|
|
337
|
-
if (p.x !== void 0 && p.y !== void 0) {
|
|
338
|
-
return new Point(+p.x, +p.y);
|
|
339
|
-
}
|
|
340
|
-
throw new Error("Expected [x, y] or {x, y} point format");
|
|
341
|
-
};
|
|
342
|
-
|
|
343
54
|
// src/lib/maplibre-util.ts
|
|
55
|
+
var import_maplibre_gl = require("maplibre-gl");
|
|
344
56
|
var _docStyle, _userSelect, _selectProp, _transformProp;
|
|
345
57
|
var _DOM = class _DOM {
|
|
346
58
|
static testProp(props) {
|
|
@@ -391,7 +103,7 @@ var _DOM = class _DOM {
|
|
|
391
103
|
}
|
|
392
104
|
static mousePos(el, e) {
|
|
393
105
|
const rect = el.getBoundingClientRect();
|
|
394
|
-
return new Point(
|
|
106
|
+
return new import_maplibre_gl.Point(
|
|
395
107
|
e.clientX - rect.left - el.clientLeft,
|
|
396
108
|
e.clientY - rect.top - el.clientTop
|
|
397
109
|
);
|
|
@@ -401,7 +113,7 @@ var _DOM = class _DOM {
|
|
|
401
113
|
const points = [];
|
|
402
114
|
for (let i = 0; i < touches.length; i++) {
|
|
403
115
|
points.push(
|
|
404
|
-
new Point(
|
|
116
|
+
new import_maplibre_gl.Point(
|
|
405
117
|
touches[i].clientX - rect.left - el.clientLeft,
|
|
406
118
|
touches[i].clientY - rect.top - el.clientTop
|
|
407
119
|
)
|
|
@@ -561,7 +273,6 @@ var ATTRIBUTION_CSS = `
|
|
|
561
273
|
`;
|
|
562
274
|
var CustomAttributionControl = class {
|
|
563
275
|
constructor(options = {}) {
|
|
564
|
-
this._editLink = null;
|
|
565
276
|
this.options = options;
|
|
566
277
|
bindAll(
|
|
567
278
|
[
|
|
@@ -611,8 +322,8 @@ var CustomAttributionControl = class {
|
|
|
611
322
|
this.printQuery = window.matchMedia("print");
|
|
612
323
|
this.onMediaPrintChange = (e) => {
|
|
613
324
|
if (e.matches) {
|
|
614
|
-
this._shadowContainer
|
|
615
|
-
this._shadowContainer
|
|
325
|
+
this._shadowContainer?.setAttribute("open", "");
|
|
326
|
+
this._shadowContainer?.classList.remove("maplibregl-compact-show");
|
|
616
327
|
}
|
|
617
328
|
};
|
|
618
329
|
this.printQuery.addEventListener("change", this.onMediaPrintChange);
|
|
@@ -660,7 +371,7 @@ var CustomAttributionControl = class {
|
|
|
660
371
|
}
|
|
661
372
|
}
|
|
662
373
|
_updateAttributions() {
|
|
663
|
-
if (!this._map
|
|
374
|
+
if (!this._map?.style) return;
|
|
664
375
|
let attributions = [];
|
|
665
376
|
if (this.options.customAttribution) {
|
|
666
377
|
if (Array.isArray(this.options.customAttribution)) {
|
|
@@ -673,11 +384,6 @@ var CustomAttributionControl = class {
|
|
|
673
384
|
attributions.push(this.options.customAttribution);
|
|
674
385
|
}
|
|
675
386
|
}
|
|
676
|
-
if (this._map.style.stylesheet) {
|
|
677
|
-
const stylesheet = this._map.style.stylesheet;
|
|
678
|
-
this.styleOwner = stylesheet.owner;
|
|
679
|
-
this.styleId = stylesheet.id;
|
|
680
|
-
}
|
|
681
387
|
const sourceCaches = this._map.style.sourceCaches;
|
|
682
388
|
for (const id in sourceCaches) {
|
|
683
389
|
const sourceCache = sourceCaches[id];
|
|
@@ -702,13 +408,12 @@ var CustomAttributionControl = class {
|
|
|
702
408
|
if (attribHTML === this._attribHTML) return;
|
|
703
409
|
this._attribHTML = attribHTML;
|
|
704
410
|
if (attributions.length) {
|
|
705
|
-
this._innerContainer.innerHTML = attribHTML;
|
|
706
|
-
this._shadowContainer
|
|
411
|
+
if (this._innerContainer) this._innerContainer.innerHTML = attribHTML;
|
|
412
|
+
this._shadowContainer?.classList.remove("maplibregl-attrib-empty");
|
|
707
413
|
} else {
|
|
708
|
-
this._shadowContainer
|
|
414
|
+
this._shadowContainer?.classList.add("maplibregl-attrib-empty");
|
|
709
415
|
}
|
|
710
416
|
this._updateCompact();
|
|
711
|
-
this._editLink = null;
|
|
712
417
|
}
|
|
713
418
|
_updateCompact() {
|
|
714
419
|
if (!this._map || !this._shadowContainer) return;
|
|
@@ -774,11 +479,11 @@ var GeoloniaControl = class {
|
|
|
774
479
|
};
|
|
775
480
|
|
|
776
481
|
// src/lib/geolonia-map.ts
|
|
777
|
-
var
|
|
482
|
+
var import_maplibre_gl5 = __toESM(require("maplibre-gl"), 1);
|
|
778
483
|
var import_pmtiles = require("pmtiles");
|
|
779
484
|
|
|
780
485
|
// src/lib/geolonia-marker.ts
|
|
781
|
-
var
|
|
486
|
+
var import_maplibre_gl2 = __toESM(require("maplibre-gl"), 1);
|
|
782
487
|
var import_tinycolor2 = __toESM(require("tinycolor2"), 1);
|
|
783
488
|
var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
784
489
|
<path class="left" d="M26 0C11.664 0 0 11.663 0 26c0 22.14 26 41 26 41V26h0C26 11.663 26 0 26 0z" fill="#E4402F"/>
|
|
@@ -786,7 +491,7 @@ var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
|
786
491
|
<circle cx="26" cy="26" r="9" fill="#FFF"/>
|
|
787
492
|
</svg>`;
|
|
788
493
|
var DEFAULT_COLOR = "#E4402F";
|
|
789
|
-
var GeoloniaMarker = class extends
|
|
494
|
+
var GeoloniaMarker = class extends import_maplibre_gl2.default.Marker {
|
|
790
495
|
constructor(options = {}) {
|
|
791
496
|
if (!options.element) {
|
|
792
497
|
const markerElement = document.createElement("div");
|
|
@@ -816,7 +521,7 @@ var GeoloniaMarker = class extends import_maplibre_gl.default.Marker {
|
|
|
816
521
|
// src/lib/simplestyle.ts
|
|
817
522
|
var import_bbox = __toESM(require("@turf/bbox"), 1);
|
|
818
523
|
var import_center = __toESM(require("@turf/center"), 1);
|
|
819
|
-
var
|
|
524
|
+
var import_maplibre_gl3 = __toESM(require("maplibre-gl"), 1);
|
|
820
525
|
|
|
821
526
|
// src/lib/keyring.ts
|
|
822
527
|
var _apiKey, _stage, _isGeoloniaStyle;
|
|
@@ -862,6 +567,12 @@ var Keyring = class {
|
|
|
862
567
|
if (style.match(/^https?:\/\//)) {
|
|
863
568
|
return false;
|
|
864
569
|
}
|
|
570
|
+
if (style.startsWith("geolonia://")) {
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
if (style.match(/^[a-z][a-z0-9+.-]*:\/\//i)) {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
865
576
|
if (style.endsWith(".json")) {
|
|
866
577
|
return false;
|
|
867
578
|
}
|
|
@@ -902,7 +613,7 @@ function getStyle(style, options) {
|
|
|
902
613
|
throw new Error("[Geolonia] API key is required to use Geolonia styles.");
|
|
903
614
|
}
|
|
904
615
|
if (!style || style === "") {
|
|
905
|
-
return `https://cdn.geolonia.com/style/geolonia/basic-v2/${lang === "ja" ? "ja" : "en"}.json`;
|
|
616
|
+
return `https://cdn.geolonia.com/style/geolonia/basic-v2/${lang === "ja" || lang === "ja-jp" ? "ja" : "en"}.json`;
|
|
906
617
|
}
|
|
907
618
|
const styleUrl = isURL(style);
|
|
908
619
|
if (styleUrl) {
|
|
@@ -915,7 +626,7 @@ function getStyle(style, options) {
|
|
|
915
626
|
return style;
|
|
916
627
|
}
|
|
917
628
|
}
|
|
918
|
-
return `https://cdn.geolonia.com/style/${style}/${lang === "ja" ? "ja" : "en"}.json`;
|
|
629
|
+
return `https://cdn.geolonia.com/style/${style}/${lang === "ja" || lang === "ja-jp" ? "ja" : "en"}.json`;
|
|
919
630
|
}
|
|
920
631
|
function getLang() {
|
|
921
632
|
if (typeof globalThis.navigator === "undefined") {
|
|
@@ -1029,14 +740,16 @@ var SimpleStyle = class {
|
|
|
1029
740
|
const points = features.filter(
|
|
1030
741
|
(feature) => feature.geometry.type.toLowerCase() === "point"
|
|
1031
742
|
);
|
|
1032
|
-
this.map.getSource(this.options.id)
|
|
743
|
+
this.map.getSource(this.options.id)?.setData({
|
|
1033
744
|
type: "FeatureCollection",
|
|
1034
745
|
features: polygonAndLines
|
|
1035
746
|
});
|
|
1036
|
-
this.map.getSource(`${this.options.id}-points`)
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
747
|
+
this.map.getSource(`${this.options.id}-points`)?.setData(
|
|
748
|
+
{
|
|
749
|
+
type: "FeatureCollection",
|
|
750
|
+
features: points
|
|
751
|
+
}
|
|
752
|
+
);
|
|
1040
753
|
return this;
|
|
1041
754
|
}
|
|
1042
755
|
addTo(map) {
|
|
@@ -1232,15 +945,16 @@ var SimpleStyle = class {
|
|
|
1232
945
|
}
|
|
1233
946
|
async setPopup(map, source) {
|
|
1234
947
|
const clickHandler = async (e) => {
|
|
948
|
+
if (!e.features?.[0]) return;
|
|
1235
949
|
const center = (0, import_center.default)(e.features[0]).geometry.coordinates;
|
|
1236
|
-
const description = e.features[0].properties
|
|
950
|
+
const description = e.features[0].properties?.description;
|
|
1237
951
|
if (description) {
|
|
1238
952
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
1239
|
-
new
|
|
953
|
+
new import_maplibre_gl3.default.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1240
954
|
}
|
|
1241
955
|
};
|
|
1242
956
|
const mouseEnterHandler = (e) => {
|
|
1243
|
-
if (e.features[0]
|
|
957
|
+
if (e.features?.[0]?.properties?.description) {
|
|
1244
958
|
map.getCanvas().style.cursor = "pointer";
|
|
1245
959
|
}
|
|
1246
960
|
};
|
|
@@ -1287,8 +1001,13 @@ var SimpleStyle = class {
|
|
|
1287
1001
|
const features = this.map.queryRenderedFeatures(e.point, {
|
|
1288
1002
|
layers: [clusterLayer]
|
|
1289
1003
|
});
|
|
1290
|
-
|
|
1291
|
-
const
|
|
1004
|
+
if (!features[0]) return;
|
|
1005
|
+
const clusterId = features[0].properties?.cluster_id;
|
|
1006
|
+
if (clusterId === void 0) return;
|
|
1007
|
+
const source = this.map.getSource(
|
|
1008
|
+
`${this.options.id}-points`
|
|
1009
|
+
);
|
|
1010
|
+
const zoom = await source.getClusterExpansionZoom(clusterId);
|
|
1292
1011
|
this.map.easeTo({
|
|
1293
1012
|
center: features[0].geometry.coordinates,
|
|
1294
1013
|
zoom
|
|
@@ -1353,7 +1072,7 @@ var SimpleStyle = class {
|
|
|
1353
1072
|
const fetchGeoJSON = async () => {
|
|
1354
1073
|
try {
|
|
1355
1074
|
const response = await window.fetch(geojson);
|
|
1356
|
-
const data = response.ok ? await response.json() :
|
|
1075
|
+
const data = response.ok ? await response.json() : template;
|
|
1357
1076
|
this.geojson = data;
|
|
1358
1077
|
this.updateData(data);
|
|
1359
1078
|
if (this.callFitBounds) {
|
|
@@ -1365,7 +1084,7 @@ var SimpleStyle = class {
|
|
|
1365
1084
|
}
|
|
1366
1085
|
};
|
|
1367
1086
|
this._loadingPromise = fetchGeoJSON();
|
|
1368
|
-
} else {
|
|
1087
|
+
} else if (typeof geojson !== "string") {
|
|
1369
1088
|
this.geojson = geojson;
|
|
1370
1089
|
}
|
|
1371
1090
|
}
|
|
@@ -1373,7 +1092,7 @@ var SimpleStyle = class {
|
|
|
1373
1092
|
|
|
1374
1093
|
// src/lib/simplestyle-vector.ts
|
|
1375
1094
|
var import_center2 = __toESM(require("@turf/center"), 1);
|
|
1376
|
-
var
|
|
1095
|
+
var import_maplibre_gl4 = __toESM(require("maplibre-gl"), 1);
|
|
1377
1096
|
var textColor2 = "#000000";
|
|
1378
1097
|
var textHaloColor2 = "#FFFFFF";
|
|
1379
1098
|
var backgroundColor2 = "rgba(255, 0, 0, 0.4)";
|
|
@@ -1383,7 +1102,6 @@ var SimpleStyleVector = class {
|
|
|
1383
1102
|
this.url = url;
|
|
1384
1103
|
this.sourceName = "vt-geolonia-simple-style";
|
|
1385
1104
|
}
|
|
1386
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1387
1105
|
addTo(map) {
|
|
1388
1106
|
const container = map.getContainer();
|
|
1389
1107
|
if (!container.dataset || !container.dataset.lng && !container.dataset.lat) {
|
|
@@ -1393,7 +1111,7 @@ var SimpleStyleVector = class {
|
|
|
1393
1111
|
return;
|
|
1394
1112
|
}
|
|
1395
1113
|
const source = map.getSource(event.sourceId);
|
|
1396
|
-
const isLoaded = source
|
|
1114
|
+
const isLoaded = source?.loaded();
|
|
1397
1115
|
if (isLoaded !== true) {
|
|
1398
1116
|
return;
|
|
1399
1117
|
}
|
|
@@ -1401,10 +1119,13 @@ var SimpleStyleVector = class {
|
|
|
1401
1119
|
return;
|
|
1402
1120
|
}
|
|
1403
1121
|
initialZoomDone = true;
|
|
1404
|
-
map.fitBounds(
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1122
|
+
map.fitBounds(
|
|
1123
|
+
source.bounds,
|
|
1124
|
+
{
|
|
1125
|
+
duration: 0,
|
|
1126
|
+
padding: 30
|
|
1127
|
+
}
|
|
1128
|
+
);
|
|
1408
1129
|
});
|
|
1409
1130
|
}
|
|
1410
1131
|
map.addSource(this.sourceName, {
|
|
@@ -1572,15 +1293,16 @@ var SimpleStyleVector = class {
|
|
|
1572
1293
|
}
|
|
1573
1294
|
async setPopup(map, source) {
|
|
1574
1295
|
map.on("click", source, async (e) => {
|
|
1296
|
+
if (!e.features?.[0]) return;
|
|
1575
1297
|
const center = (0, import_center2.default)(e.features[0]).geometry.coordinates;
|
|
1576
|
-
const description = e.features[0].properties
|
|
1298
|
+
const description = e.features[0].properties?.description;
|
|
1577
1299
|
if (description) {
|
|
1578
1300
|
const sanitizedDescription = await sanitizeDescription(description);
|
|
1579
|
-
new
|
|
1301
|
+
new import_maplibre_gl4.default.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1580
1302
|
}
|
|
1581
1303
|
});
|
|
1582
1304
|
map.on("mouseenter", source, (e) => {
|
|
1583
|
-
if (e.features[0]
|
|
1305
|
+
if (e.features?.[0]?.properties?.description) {
|
|
1584
1306
|
map.getCanvas().style.cursor = "pointer";
|
|
1585
1307
|
}
|
|
1586
1308
|
});
|
|
@@ -1597,9 +1319,10 @@ function ensurePMTiles() {
|
|
|
1597
1319
|
if (pmtilesRegistered) return;
|
|
1598
1320
|
pmtilesRegistered = true;
|
|
1599
1321
|
const protocol = new import_pmtiles.Protocol();
|
|
1600
|
-
|
|
1322
|
+
import_maplibre_gl5.default.addProtocol("pmtiles", protocol.tile);
|
|
1601
1323
|
}
|
|
1602
|
-
var GeoloniaMap = class extends
|
|
1324
|
+
var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
1325
|
+
// biome-ignore lint/correctness/noUnreachableSuper: intentional singleton pattern - returns existing map instance before super()
|
|
1603
1326
|
constructor(options) {
|
|
1604
1327
|
ensurePMTiles();
|
|
1605
1328
|
if (options.apiKey) {
|
|
@@ -1728,24 +1451,24 @@ var GeoloniaMap = class extends import_maplibre_gl4.default.Map {
|
|
|
1728
1451
|
const fullscreen = parseControlOption(options.fullscreenControl ?? false);
|
|
1729
1452
|
if (fullscreen.enabled) {
|
|
1730
1453
|
this.addControl(
|
|
1731
|
-
new
|
|
1454
|
+
new import_maplibre_gl5.FullscreenControl(),
|
|
1732
1455
|
fullscreen.position
|
|
1733
1456
|
);
|
|
1734
1457
|
}
|
|
1735
1458
|
const nav = parseControlOption(options.navigationControl ?? true);
|
|
1736
1459
|
if (nav.enabled) {
|
|
1737
|
-
this.addControl(new
|
|
1460
|
+
this.addControl(new import_maplibre_gl5.NavigationControl(), nav.position);
|
|
1738
1461
|
}
|
|
1739
1462
|
const geolocate = parseControlOption(options.geolocateControl ?? false);
|
|
1740
1463
|
if (geolocate.enabled) {
|
|
1741
1464
|
this.addControl(
|
|
1742
|
-
new
|
|
1465
|
+
new import_maplibre_gl5.GeolocateControl({}),
|
|
1743
1466
|
geolocate.position
|
|
1744
1467
|
);
|
|
1745
1468
|
}
|
|
1746
1469
|
const scale = parseControlOption(options.scaleControl ?? false);
|
|
1747
1470
|
if (scale.enabled) {
|
|
1748
|
-
this.addControl(new
|
|
1471
|
+
this.addControl(new import_maplibre_gl5.ScaleControl({}), scale.position);
|
|
1749
1472
|
}
|
|
1750
1473
|
this.on("load", (event) => {
|
|
1751
1474
|
const map = event.target;
|
|
@@ -1756,12 +1479,12 @@ var GeoloniaMap = class extends import_maplibre_gl4.default.Map {
|
|
|
1756
1479
|
}
|
|
1757
1480
|
}
|
|
1758
1481
|
if (options.gestureHandling !== false) {
|
|
1759
|
-
import("@geolonia/
|
|
1482
|
+
import("@geolonia/maplibre-gesture-handling").then(({ default: GestureHandling }) => {
|
|
1760
1483
|
const body = document.body;
|
|
1761
1484
|
const html = document.documentElement;
|
|
1762
1485
|
const isScrollable = body.scrollHeight > body.clientHeight || html.scrollHeight > html.clientHeight;
|
|
1763
1486
|
if (isScrollable) {
|
|
1764
|
-
new GestureHandling({ lang })
|
|
1487
|
+
map.addControl(new GestureHandling({ lang }));
|
|
1765
1488
|
}
|
|
1766
1489
|
}).catch(() => {
|
|
1767
1490
|
});
|
|
@@ -1788,7 +1511,7 @@ var GeoloniaMap = class extends import_maplibre_gl4.default.Map {
|
|
|
1788
1511
|
}
|
|
1789
1512
|
const content = container.dataset?.popupContent;
|
|
1790
1513
|
if (content) {
|
|
1791
|
-
const popup = new
|
|
1514
|
+
const popup = new import_maplibre_gl5.Popup({ offset: [0, -25] }).setHTML(content);
|
|
1792
1515
|
marker.setPopup(popup);
|
|
1793
1516
|
if (options.openPopup) {
|
|
1794
1517
|
marker.togglePopup();
|
package/dist/npm/index.d.cts
CHANGED
|
@@ -25,10 +25,7 @@ declare class CustomAttributionControl implements IControl {
|
|
|
25
25
|
private _shadowContainer;
|
|
26
26
|
private _innerContainer;
|
|
27
27
|
private _compactButton;
|
|
28
|
-
private _editLink;
|
|
29
28
|
private _attribHTML;
|
|
30
|
-
private styleId;
|
|
31
|
-
private styleOwner;
|
|
32
29
|
private printQuery;
|
|
33
30
|
private onMediaPrintChange;
|
|
34
31
|
constructor(options?: CustomAttributionControlOptions);
|
|
@@ -84,7 +81,7 @@ type GeoloniaMapOptions = MapOptions & {
|
|
|
84
81
|
/** Geolonia logo control */
|
|
85
82
|
geoloniaControl?: boolean | ControlPosition;
|
|
86
83
|
/** GeoJSON URL or object for SimpleStyle */
|
|
87
|
-
geojson?: string | GeoJSON.
|
|
84
|
+
geojson?: string | GeoJSON.FeatureCollection;
|
|
88
85
|
/** Enable clustering for GeoJSON points */
|
|
89
86
|
cluster?: boolean;
|
|
90
87
|
/** Cluster marker color */
|
|
@@ -143,6 +140,7 @@ declare class Keyring {
|
|
|
143
140
|
}
|
|
144
141
|
declare const keyring: Keyring;
|
|
145
142
|
|
|
143
|
+
type FeatureCollection = GeoJSON.FeatureCollection;
|
|
146
144
|
declare class SimpleStyle {
|
|
147
145
|
_loadingPromise: Promise<unknown> | undefined;
|
|
148
146
|
private callFitBounds;
|
|
@@ -150,9 +148,9 @@ declare class SimpleStyle {
|
|
|
150
148
|
private map;
|
|
151
149
|
private options;
|
|
152
150
|
private _eventHandlers;
|
|
153
|
-
constructor(geojson: string |
|
|
154
|
-
updateData(geojson:
|
|
155
|
-
addTo(map:
|
|
151
|
+
constructor(geojson: string | FeatureCollection, options?: Record<string, unknown>);
|
|
152
|
+
updateData(geojson: FeatureCollection): this;
|
|
153
|
+
addTo(map: Map): this;
|
|
156
154
|
fitBounds(options?: {}): this;
|
|
157
155
|
/**
|
|
158
156
|
* Set polygon geometries.
|
|
@@ -166,39 +164,39 @@ declare class SimpleStyle {
|
|
|
166
164
|
* Setup point geometries.
|
|
167
165
|
*/
|
|
168
166
|
setPointGeometries(): void;
|
|
169
|
-
setPopup(map:
|
|
167
|
+
setPopup(map: Map, source: string): Promise<void>;
|
|
170
168
|
/**
|
|
171
169
|
* Setup cluster markers
|
|
172
170
|
*/
|
|
173
171
|
setCluster(): void;
|
|
174
172
|
remove(): this;
|
|
175
|
-
setGeoJSON(geojson: string |
|
|
173
|
+
setGeoJSON(geojson: string | FeatureCollection): void;
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
declare class SimpleStyleVector {
|
|
179
177
|
private url;
|
|
180
178
|
private sourceName;
|
|
181
179
|
constructor(url: string);
|
|
182
|
-
addTo(map:
|
|
180
|
+
addTo(map: Map): void;
|
|
183
181
|
/**
|
|
184
182
|
* Set polygon geometries.
|
|
185
183
|
*
|
|
186
184
|
* @param map
|
|
187
185
|
*/
|
|
188
|
-
setPolygonGeometries(map:
|
|
186
|
+
setPolygonGeometries(map: Map): void;
|
|
189
187
|
/**
|
|
190
188
|
* Set line geometries.
|
|
191
189
|
*
|
|
192
190
|
* @param map
|
|
193
191
|
*/
|
|
194
|
-
setLineGeometries(map:
|
|
192
|
+
setLineGeometries(map: Map): void;
|
|
195
193
|
/**
|
|
196
194
|
* Setup point geometries.
|
|
197
195
|
*
|
|
198
196
|
* @param map
|
|
199
197
|
*/
|
|
200
|
-
setPointGeometries(map:
|
|
201
|
-
setPopup(map:
|
|
198
|
+
setPointGeometries(map: Map): void;
|
|
199
|
+
setPopup(map: Map, source: string): Promise<void>;
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
declare const VERSION = "0.1.0";
|
package/dist/npm/index.d.ts
CHANGED
|
@@ -25,10 +25,7 @@ declare class CustomAttributionControl implements IControl {
|
|
|
25
25
|
private _shadowContainer;
|
|
26
26
|
private _innerContainer;
|
|
27
27
|
private _compactButton;
|
|
28
|
-
private _editLink;
|
|
29
28
|
private _attribHTML;
|
|
30
|
-
private styleId;
|
|
31
|
-
private styleOwner;
|
|
32
29
|
private printQuery;
|
|
33
30
|
private onMediaPrintChange;
|
|
34
31
|
constructor(options?: CustomAttributionControlOptions);
|
|
@@ -84,7 +81,7 @@ type GeoloniaMapOptions = MapOptions & {
|
|
|
84
81
|
/** Geolonia logo control */
|
|
85
82
|
geoloniaControl?: boolean | ControlPosition;
|
|
86
83
|
/** GeoJSON URL or object for SimpleStyle */
|
|
87
|
-
geojson?: string | GeoJSON.
|
|
84
|
+
geojson?: string | GeoJSON.FeatureCollection;
|
|
88
85
|
/** Enable clustering for GeoJSON points */
|
|
89
86
|
cluster?: boolean;
|
|
90
87
|
/** Cluster marker color */
|
|
@@ -143,6 +140,7 @@ declare class Keyring {
|
|
|
143
140
|
}
|
|
144
141
|
declare const keyring: Keyring;
|
|
145
142
|
|
|
143
|
+
type FeatureCollection = GeoJSON.FeatureCollection;
|
|
146
144
|
declare class SimpleStyle {
|
|
147
145
|
_loadingPromise: Promise<unknown> | undefined;
|
|
148
146
|
private callFitBounds;
|
|
@@ -150,9 +148,9 @@ declare class SimpleStyle {
|
|
|
150
148
|
private map;
|
|
151
149
|
private options;
|
|
152
150
|
private _eventHandlers;
|
|
153
|
-
constructor(geojson: string |
|
|
154
|
-
updateData(geojson:
|
|
155
|
-
addTo(map:
|
|
151
|
+
constructor(geojson: string | FeatureCollection, options?: Record<string, unknown>);
|
|
152
|
+
updateData(geojson: FeatureCollection): this;
|
|
153
|
+
addTo(map: Map): this;
|
|
156
154
|
fitBounds(options?: {}): this;
|
|
157
155
|
/**
|
|
158
156
|
* Set polygon geometries.
|
|
@@ -166,39 +164,39 @@ declare class SimpleStyle {
|
|
|
166
164
|
* Setup point geometries.
|
|
167
165
|
*/
|
|
168
166
|
setPointGeometries(): void;
|
|
169
|
-
setPopup(map:
|
|
167
|
+
setPopup(map: Map, source: string): Promise<void>;
|
|
170
168
|
/**
|
|
171
169
|
* Setup cluster markers
|
|
172
170
|
*/
|
|
173
171
|
setCluster(): void;
|
|
174
172
|
remove(): this;
|
|
175
|
-
setGeoJSON(geojson: string |
|
|
173
|
+
setGeoJSON(geojson: string | FeatureCollection): void;
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
declare class SimpleStyleVector {
|
|
179
177
|
private url;
|
|
180
178
|
private sourceName;
|
|
181
179
|
constructor(url: string);
|
|
182
|
-
addTo(map:
|
|
180
|
+
addTo(map: Map): void;
|
|
183
181
|
/**
|
|
184
182
|
* Set polygon geometries.
|
|
185
183
|
*
|
|
186
184
|
* @param map
|
|
187
185
|
*/
|
|
188
|
-
setPolygonGeometries(map:
|
|
186
|
+
setPolygonGeometries(map: Map): void;
|
|
189
187
|
/**
|
|
190
188
|
* Set line geometries.
|
|
191
189
|
*
|
|
192
190
|
* @param map
|
|
193
191
|
*/
|
|
194
|
-
setLineGeometries(map:
|
|
192
|
+
setLineGeometries(map: Map): void;
|
|
195
193
|
/**
|
|
196
194
|
* Setup point geometries.
|
|
197
195
|
*
|
|
198
196
|
* @param map
|
|
199
197
|
*/
|
|
200
|
-
setPointGeometries(map:
|
|
201
|
-
setPopup(map:
|
|
198
|
+
setPointGeometries(map: Map): void;
|
|
199
|
+
setPopup(map: Map, source: string): Promise<void>;
|
|
202
200
|
}
|
|
203
201
|
|
|
204
202
|
declare const VERSION = "0.1.0";
|
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;
|
|
@@ -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) {
|
|
@@ -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/
|
|
21
|
+
"@geolonia/maplibre-gesture-handling": "^3.0.0",
|
|
22
22
|
"@turf/bbox": "^7.3.4",
|
|
23
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": {
|