@geolonia/maps-core 0.5.1 → 0.6.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/README.md +107 -2
- package/dist/npm/index.d.ts +9 -1
- package/dist/npm/index.js +57 -13
- package/package.json +12 -13
- package/src/assets/style.css +74 -3
- package/dist/npm/index.cjs +0 -2075
- package/dist/npm/index.d.cts +0 -872
package/dist/npm/index.cjs
DELETED
|
@@ -1,2075 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __typeError = (msg) => {
|
|
9
|
-
throw TypeError(msg);
|
|
10
|
-
};
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name in all)
|
|
13
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
33
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
34
|
-
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);
|
|
35
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
36
|
-
|
|
37
|
-
// src/index.ts
|
|
38
|
-
var index_exports = {};
|
|
39
|
-
__export(index_exports, {
|
|
40
|
-
CustomAttributionControl: () => attribution_default,
|
|
41
|
-
DEFAULT_STAGE: () => DEFAULT_STAGE,
|
|
42
|
-
GeoloniaControl: () => GeoloniaControl,
|
|
43
|
-
GeoloniaMap: () => GeoloniaMap,
|
|
44
|
-
GeoloniaMarker: () => GeoloniaMarker,
|
|
45
|
-
SimpleStyle: () => SimpleStyle,
|
|
46
|
-
SimpleStyleVector: () => simplestyle_vector_default,
|
|
47
|
-
coreVersion: () => VERSION,
|
|
48
|
-
getLang: () => getLang,
|
|
49
|
-
getStyle: () => getStyle,
|
|
50
|
-
isGeoloniaTilesHost: () => isGeoloniaTilesHost,
|
|
51
|
-
keyring: () => keyring
|
|
52
|
-
});
|
|
53
|
-
module.exports = __toCommonJS(index_exports);
|
|
54
|
-
|
|
55
|
-
// src/lib/maplibre-util.ts
|
|
56
|
-
var import_maplibre_gl = __toESM(require("maplibre-gl"), 1);
|
|
57
|
-
var _docStyle, _userSelect, _selectProp, _transformProp;
|
|
58
|
-
var _DOM = class _DOM {
|
|
59
|
-
static testProp(props) {
|
|
60
|
-
if (!__privateGet(_DOM, _docStyle)) return props[0];
|
|
61
|
-
for (let i = 0; i < props.length; i++) {
|
|
62
|
-
if (props[i] in __privateGet(_DOM, _docStyle)) {
|
|
63
|
-
return props[i];
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return props[0];
|
|
67
|
-
}
|
|
68
|
-
static create(tagName, className, container) {
|
|
69
|
-
const el = window.document.createElement(tagName);
|
|
70
|
-
if (className !== void 0) el.className = className;
|
|
71
|
-
if (container) container.appendChild(el);
|
|
72
|
-
return el;
|
|
73
|
-
}
|
|
74
|
-
static createNS(namespaceURI, tagName) {
|
|
75
|
-
return window.document.createElementNS(namespaceURI, tagName);
|
|
76
|
-
}
|
|
77
|
-
static disableDrag() {
|
|
78
|
-
if (__privateGet(_DOM, _docStyle) && __privateGet(_DOM, _selectProp)) {
|
|
79
|
-
__privateSet(_DOM, _userSelect, __privateGet(_DOM, _docStyle)[__privateGet(_DOM, _selectProp)]);
|
|
80
|
-
__privateGet(_DOM, _docStyle)[__privateGet(_DOM, _selectProp)] = "none";
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
static enableDrag() {
|
|
84
|
-
if (__privateGet(_DOM, _docStyle) && __privateGet(_DOM, _selectProp)) {
|
|
85
|
-
__privateGet(_DOM, _docStyle)[__privateGet(_DOM, _selectProp)] = __privateGet(_DOM, _userSelect) ?? "";
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
static setTransform(el, value) {
|
|
89
|
-
el.style[__privateGet(_DOM, _transformProp)] = value;
|
|
90
|
-
}
|
|
91
|
-
static addEventListener(target, type, callback, options) {
|
|
92
|
-
if ("passive" in options) {
|
|
93
|
-
target.addEventListener(type, callback, options);
|
|
94
|
-
} else {
|
|
95
|
-
target.addEventListener(type, callback, options.capture);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
static removeEventListener(target, type, callback, options) {
|
|
99
|
-
if ("passive" in options) {
|
|
100
|
-
target.removeEventListener(type, callback, options);
|
|
101
|
-
} else {
|
|
102
|
-
target.removeEventListener(type, callback, options.capture);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
static mousePos(el, e) {
|
|
106
|
-
const rect = el.getBoundingClientRect();
|
|
107
|
-
return new import_maplibre_gl.default.Point(
|
|
108
|
-
e.clientX - rect.left - el.clientLeft,
|
|
109
|
-
e.clientY - rect.top - el.clientTop
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
static touchPos(el, touches) {
|
|
113
|
-
const rect = el.getBoundingClientRect();
|
|
114
|
-
const points = [];
|
|
115
|
-
for (let i = 0; i < touches.length; i++) {
|
|
116
|
-
points.push(
|
|
117
|
-
new import_maplibre_gl.default.Point(
|
|
118
|
-
touches[i].clientX - rect.left - el.clientLeft,
|
|
119
|
-
touches[i].clientY - rect.top - el.clientTop
|
|
120
|
-
)
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
return points;
|
|
124
|
-
}
|
|
125
|
-
static mouseButton(e) {
|
|
126
|
-
return e.button;
|
|
127
|
-
}
|
|
128
|
-
static remove(node) {
|
|
129
|
-
if (node.parentNode) {
|
|
130
|
-
node.parentNode.removeChild(node);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
_docStyle = new WeakMap();
|
|
135
|
-
_userSelect = new WeakMap();
|
|
136
|
-
_selectProp = new WeakMap();
|
|
137
|
-
_transformProp = new WeakMap();
|
|
138
|
-
__privateAdd(_DOM, _docStyle, typeof window !== "undefined" && window.document && window.document.documentElement.style);
|
|
139
|
-
__privateAdd(_DOM, _userSelect);
|
|
140
|
-
__privateAdd(_DOM, _selectProp, _DOM.testProp([
|
|
141
|
-
"userSelect",
|
|
142
|
-
"MozUserSelect",
|
|
143
|
-
"WebkitUserSelect",
|
|
144
|
-
"msUserSelect"
|
|
145
|
-
]));
|
|
146
|
-
__privateAdd(_DOM, _transformProp, _DOM.testProp([
|
|
147
|
-
"transform",
|
|
148
|
-
"WebkitTransform"
|
|
149
|
-
]));
|
|
150
|
-
var DOM = _DOM;
|
|
151
|
-
function bindAll(fns, context) {
|
|
152
|
-
for (const fn of fns) {
|
|
153
|
-
if (typeof context[fn] === "function") {
|
|
154
|
-
context[fn] = context[fn].bind(
|
|
155
|
-
context
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/lib/controls/attribution.ts
|
|
162
|
-
var ATTRIBUTION_CSS = `
|
|
163
|
-
.maplibregl-ctrl {
|
|
164
|
-
font: 12px/20px Helvetica Neue,Arial,Helvetica,sans-serif;
|
|
165
|
-
clear: both;
|
|
166
|
-
pointer-events: auto;
|
|
167
|
-
transform: translate(0);
|
|
168
|
-
}
|
|
169
|
-
.maplibregl-ctrl-attrib-button:focus,.maplibregl-ctrl-group button:focus {
|
|
170
|
-
box-shadow: 0 0 2px 2px #0096ff
|
|
171
|
-
}
|
|
172
|
-
.maplibregl-ctrl.maplibregl-ctrl-attrib {
|
|
173
|
-
background-color: hsla(0,0%,100%,.5);
|
|
174
|
-
margin: 0;
|
|
175
|
-
padding: 0 5px
|
|
176
|
-
}
|
|
177
|
-
@media screen {
|
|
178
|
-
.maplibregl-ctrl-attrib.maplibregl-compact {
|
|
179
|
-
background-color: #fff;
|
|
180
|
-
border-radius: 12px;
|
|
181
|
-
box-sizing: content-box;
|
|
182
|
-
min-height: 20px;
|
|
183
|
-
padding: 2px 24px 2px 0;
|
|
184
|
-
position: relative;
|
|
185
|
-
margin: 10px 10px 10px auto;
|
|
186
|
-
width: 0;
|
|
187
|
-
}
|
|
188
|
-
.maplibregl-ctrl-attrib.maplibregl-compact-show {
|
|
189
|
-
padding: 2px 28px 2px 8px;
|
|
190
|
-
visibility: visible;
|
|
191
|
-
width: auto;
|
|
192
|
-
}
|
|
193
|
-
.maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact-show,
|
|
194
|
-
.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact-show {
|
|
195
|
-
border-radius: 12px;
|
|
196
|
-
padding: 2px 8px 2px 28px
|
|
197
|
-
}
|
|
198
|
-
.maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-inner {
|
|
199
|
-
display: none
|
|
200
|
-
}
|
|
201
|
-
.maplibregl-ctrl-attrib-button {
|
|
202
|
-
background-color: hsla(0,0%,100%,.5);
|
|
203
|
-
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E");
|
|
204
|
-
border: 0;
|
|
205
|
-
border-radius: 12px;
|
|
206
|
-
box-sizing: border-box;
|
|
207
|
-
cursor: pointer;
|
|
208
|
-
display: none;
|
|
209
|
-
height: 24px;
|
|
210
|
-
outline: none;
|
|
211
|
-
position: absolute;
|
|
212
|
-
right: 0;
|
|
213
|
-
top: 0;
|
|
214
|
-
width: 24px
|
|
215
|
-
}
|
|
216
|
-
.maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button {
|
|
217
|
-
appearance: none;
|
|
218
|
-
list-style: none
|
|
219
|
-
}
|
|
220
|
-
.maplibregl-ctrl-attrib summary.maplibregl-ctrl-attrib-button::-webkit-details-marker {
|
|
221
|
-
display: none
|
|
222
|
-
}
|
|
223
|
-
.maplibregl-ctrl-bottom-left .maplibregl-ctrl-attrib-button,
|
|
224
|
-
.maplibregl-ctrl-top-left .maplibregl-ctrl-attrib-button {
|
|
225
|
-
left: 0
|
|
226
|
-
}
|
|
227
|
-
.maplibregl-ctrl-attrib.maplibregl-compact .maplibregl-ctrl-attrib-button,
|
|
228
|
-
.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner {
|
|
229
|
-
display: block
|
|
230
|
-
}
|
|
231
|
-
.maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-button {
|
|
232
|
-
background-color: rgb(0 0 0/5%)
|
|
233
|
-
}
|
|
234
|
-
.maplibregl-ctrl-bottom-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
235
|
-
bottom: 0; right: 0
|
|
236
|
-
}
|
|
237
|
-
.maplibregl-ctrl-top-right>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
238
|
-
right: 0; top: 0
|
|
239
|
-
}
|
|
240
|
-
.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
241
|
-
left: 0; top: 0
|
|
242
|
-
}
|
|
243
|
-
.maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
244
|
-
bottom: 0; left: 0
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
@media screen and (-ms-high-contrast:active) {
|
|
248
|
-
.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
249
|
-
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd' fill='%23fff'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E")
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
@media screen and (-ms-high-contrast:black-on-white) {
|
|
253
|
-
.maplibregl-ctrl-attrib.maplibregl-compact:after {
|
|
254
|
-
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg width='24' height='24' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg' fill-rule='evenodd'%3E%3Cpath d='M4 10a6 6 0 1 0 12 0 6 6 0 1 0-12 0m5-3a1 1 0 1 0 2 0 1 1 0 1 0-2 0m0 3a1 1 0 1 1 2 0v3a1 1 0 1 1-2 0'/%3E%3C/svg%3E")
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
@media print {
|
|
258
|
-
.maplibregl-ctrl-attrib-button {
|
|
259
|
-
display: none !important;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
.maplibregl-ctrl-attrib a {
|
|
263
|
-
color: rgba(0,0,0,.75);
|
|
264
|
-
text-decoration: none;
|
|
265
|
-
white-space: nowrap;
|
|
266
|
-
}
|
|
267
|
-
.maplibregl-ctrl-attrib a:hover {
|
|
268
|
-
color: inherit;
|
|
269
|
-
text-decoration: underline
|
|
270
|
-
}
|
|
271
|
-
.maplibregl-attrib-empty {
|
|
272
|
-
display: none
|
|
273
|
-
}
|
|
274
|
-
`;
|
|
275
|
-
var CustomAttributionControl = class {
|
|
276
|
-
/**
|
|
277
|
-
* コントロールを生成します。
|
|
278
|
-
*
|
|
279
|
-
* @param options 帰属表示の挙動を指定するオプションです。省略した場合は空のオブジェクトが使われます。
|
|
280
|
-
*/
|
|
281
|
-
constructor(options = {}) {
|
|
282
|
-
this.options = options;
|
|
283
|
-
bindAll(
|
|
284
|
-
[
|
|
285
|
-
"_toggleAttribution",
|
|
286
|
-
"_updateData",
|
|
287
|
-
"_updateCompact",
|
|
288
|
-
"_updateCompactMinimize"
|
|
289
|
-
],
|
|
290
|
-
this
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* このコントロールの既定の表示位置を返します。
|
|
295
|
-
*
|
|
296
|
-
* @returns 既定の表示位置である `"bottom-right"` を返します。
|
|
297
|
-
*/
|
|
298
|
-
getDefaultPosition() {
|
|
299
|
-
return "bottom-right";
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* コントロールが地図に追加されるときに呼び出されます。
|
|
303
|
-
*
|
|
304
|
-
* Shadow DOM を持つコンテナ要素を生成し、その内部に帰属表示用の要素と CSS を組み立てます。
|
|
305
|
-
* あわせて帰属表示の内容を初期化し、地図の各種イベント(`styledata`、`sourcedata`、`terrain`、
|
|
306
|
-
* `resize`、`drag`)や印刷メディアクエリの変化を監視するリスナーを登録します。
|
|
307
|
-
*
|
|
308
|
-
* @param map このコントロールを追加する対象の地図です。
|
|
309
|
-
* @returns 地図に挿入するコントロールのルート要素を返します。
|
|
310
|
-
*/
|
|
311
|
-
onAdd(map) {
|
|
312
|
-
this._map = map;
|
|
313
|
-
this._compact = this.options.compact;
|
|
314
|
-
this._container = DOM.create("div");
|
|
315
|
-
const shadow = this._container.attachShadow({ mode: "open" });
|
|
316
|
-
this._shadowContainer = DOM.create(
|
|
317
|
-
"details",
|
|
318
|
-
"maplibregl-ctrl maplibregl-ctrl-attrib"
|
|
319
|
-
);
|
|
320
|
-
this._compactButton = DOM.create(
|
|
321
|
-
"summary",
|
|
322
|
-
"maplibregl-ctrl-attrib-button",
|
|
323
|
-
this._shadowContainer
|
|
324
|
-
);
|
|
325
|
-
this._compactButton.addEventListener("click", this._toggleAttribution);
|
|
326
|
-
this._setElementTitle(this._compactButton, "ToggleAttribution");
|
|
327
|
-
this._innerContainer = DOM.create(
|
|
328
|
-
"div",
|
|
329
|
-
"maplibregl-ctrl-attrib-inner",
|
|
330
|
-
this._shadowContainer
|
|
331
|
-
);
|
|
332
|
-
const style = document.createElement("style");
|
|
333
|
-
style.textContent = ATTRIBUTION_CSS;
|
|
334
|
-
this._updateAttributions();
|
|
335
|
-
this._updateCompact();
|
|
336
|
-
this._map.on("styledata", this._updateData);
|
|
337
|
-
this._map.on("sourcedata", this._updateData);
|
|
338
|
-
this._map.on("terrain", this._updateData);
|
|
339
|
-
this._map.on("resize", this._updateCompact);
|
|
340
|
-
this._map.on("drag", this._updateCompactMinimize);
|
|
341
|
-
shadow.appendChild(style);
|
|
342
|
-
shadow.appendChild(this._shadowContainer);
|
|
343
|
-
this.printQuery = window.matchMedia("print");
|
|
344
|
-
this.onMediaPrintChange = (e) => {
|
|
345
|
-
if (e.matches) {
|
|
346
|
-
this._shadowContainer?.setAttribute("open", "");
|
|
347
|
-
this._shadowContainer?.classList.remove("maplibregl-compact-show");
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
this.printQuery.addEventListener("change", this.onMediaPrintChange);
|
|
351
|
-
return this._container;
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* コントロールが地図から取り除かれるときに呼び出されます。
|
|
355
|
-
*
|
|
356
|
-
* 生成したコンテナ要素を DOM から削除し、`onAdd` で登録した地図のイベントリスナーと
|
|
357
|
-
* 印刷メディアクエリのリスナーを解除したうえで、内部で保持している状態を破棄します。
|
|
358
|
-
*/
|
|
359
|
-
onRemove() {
|
|
360
|
-
if (this._container) {
|
|
361
|
-
DOM.remove(this._container);
|
|
362
|
-
}
|
|
363
|
-
if (this._map) {
|
|
364
|
-
this._map.off("styledata", this._updateData);
|
|
365
|
-
this._map.off("sourcedata", this._updateData);
|
|
366
|
-
this._map.off("terrain", this._updateData);
|
|
367
|
-
this._map.off("resize", this._updateCompact);
|
|
368
|
-
this._map.off("drag", this._updateCompactMinimize);
|
|
369
|
-
}
|
|
370
|
-
if (this.printQuery && this.onMediaPrintChange) {
|
|
371
|
-
this.printQuery.removeEventListener("change", this.onMediaPrintChange);
|
|
372
|
-
}
|
|
373
|
-
this._map = void 0;
|
|
374
|
-
this._compact = void 0;
|
|
375
|
-
this._attribHTML = void 0;
|
|
376
|
-
}
|
|
377
|
-
_setElementTitle(element, title) {
|
|
378
|
-
if (!this._map) return;
|
|
379
|
-
const str = this._map._getUIString(`AttributionControl.${title}`);
|
|
380
|
-
element.title = str;
|
|
381
|
-
element.setAttribute("aria-label", str);
|
|
382
|
-
}
|
|
383
|
-
_toggleAttribution() {
|
|
384
|
-
if (!this._shadowContainer) return;
|
|
385
|
-
if (this._shadowContainer.classList.contains("maplibregl-compact")) {
|
|
386
|
-
if (this._shadowContainer.classList.contains("maplibregl-compact-show")) {
|
|
387
|
-
this._shadowContainer.setAttribute("open", "");
|
|
388
|
-
this._shadowContainer.classList.remove("maplibregl-compact-show");
|
|
389
|
-
} else {
|
|
390
|
-
this._shadowContainer.classList.add("maplibregl-compact-show");
|
|
391
|
-
this._shadowContainer.removeAttribute("open");
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
_updateData(e) {
|
|
396
|
-
if (e && (e.sourceDataType === "metadata" || e.sourceDataType === "visibility" || e.dataType === "style" || e.type === "terrain")) {
|
|
397
|
-
this._updateAttributions();
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
_updateAttributions() {
|
|
401
|
-
if (!this._map?.style) return;
|
|
402
|
-
let attributions = [];
|
|
403
|
-
if (this.options.customAttribution) {
|
|
404
|
-
if (Array.isArray(this.options.customAttribution)) {
|
|
405
|
-
attributions = attributions.concat(
|
|
406
|
-
this.options.customAttribution.filter(
|
|
407
|
-
(attr) => typeof attr === "string"
|
|
408
|
-
)
|
|
409
|
-
);
|
|
410
|
-
} else if (typeof this.options.customAttribution === "string") {
|
|
411
|
-
attributions.push(this.options.customAttribution);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
const tileManagers = this._map.style.tileManagers ?? this._map.style.sourceCaches ?? {};
|
|
415
|
-
for (const id in tileManagers) {
|
|
416
|
-
const tileManager = tileManagers[id];
|
|
417
|
-
if (tileManager.used || tileManager.usedForTerrain) {
|
|
418
|
-
const source = tileManager.getSource();
|
|
419
|
-
if (source.attribution && attributions.indexOf(source.attribution) < 0) {
|
|
420
|
-
attributions.push(source.attribution);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
attributions = attributions.filter((e) => String(e).trim());
|
|
425
|
-
attributions.sort((a, b) => a.length - b.length);
|
|
426
|
-
attributions = attributions.filter((attrib, i) => {
|
|
427
|
-
for (let j = i + 1; j < attributions.length; j++) {
|
|
428
|
-
if (attributions[j].indexOf(attrib) >= 0) {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
return true;
|
|
433
|
-
});
|
|
434
|
-
const attribHTML = attributions.join(" | ");
|
|
435
|
-
if (attribHTML === this._attribHTML) return;
|
|
436
|
-
this._attribHTML = attribHTML;
|
|
437
|
-
if (attributions.length) {
|
|
438
|
-
if (this._innerContainer) this._innerContainer.innerHTML = attribHTML;
|
|
439
|
-
this._shadowContainer?.classList.remove("maplibregl-attrib-empty");
|
|
440
|
-
} else {
|
|
441
|
-
this._shadowContainer?.classList.add("maplibregl-attrib-empty");
|
|
442
|
-
}
|
|
443
|
-
this._updateCompact();
|
|
444
|
-
}
|
|
445
|
-
_updateCompact() {
|
|
446
|
-
if (!this._map || !this._shadowContainer) return;
|
|
447
|
-
if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
|
|
448
|
-
if (this._compact === false) {
|
|
449
|
-
this._shadowContainer.setAttribute("open", "");
|
|
450
|
-
} else if (!this._shadowContainer.classList.contains("maplibregl-compact") && !this._shadowContainer.classList.contains("maplibregl-attrib-empty")) {
|
|
451
|
-
this._shadowContainer.setAttribute("open", "");
|
|
452
|
-
this._shadowContainer.classList.add(
|
|
453
|
-
"maplibregl-compact",
|
|
454
|
-
"maplibregl-compact-show"
|
|
455
|
-
);
|
|
456
|
-
}
|
|
457
|
-
} else {
|
|
458
|
-
this._shadowContainer.setAttribute("open", "");
|
|
459
|
-
if (this._shadowContainer.classList.contains("maplibregl-compact")) {
|
|
460
|
-
this._shadowContainer.classList.remove(
|
|
461
|
-
"maplibregl-compact",
|
|
462
|
-
"maplibregl-compact-show"
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
_updateCompactMinimize() {
|
|
468
|
-
if (!this._shadowContainer) return;
|
|
469
|
-
if (this._shadowContainer.classList.contains("maplibregl-compact")) {
|
|
470
|
-
if (this._shadowContainer.classList.contains("maplibregl-compact-show")) {
|
|
471
|
-
this._shadowContainer.classList.remove("maplibregl-compact-show");
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
var attribution_default = CustomAttributionControl;
|
|
477
|
-
|
|
478
|
-
// src/lib/controls/geolonia-logo.ts
|
|
479
|
-
var GeoloniaControl = class {
|
|
480
|
-
/**
|
|
481
|
-
* コントロールの DOM 要素を生成して返します。
|
|
482
|
-
*
|
|
483
|
-
* `IControl` の実装として、`Map.addControl` で地図に追加された際に MapLibre から呼び出されます。
|
|
484
|
-
* Geolonia のロゴ画像を含み、`https://geolonia.com/` へのリンクが設定された要素を組み立てて返します。
|
|
485
|
-
*
|
|
486
|
-
* @returns このコントロールのコンテナとなる `HTMLDivElement`。
|
|
487
|
-
*/
|
|
488
|
-
onAdd() {
|
|
489
|
-
this.container = document.createElement("div");
|
|
490
|
-
this.container.className = "maplibregl-ctrl";
|
|
491
|
-
const img = document.createElement("img");
|
|
492
|
-
img.src = "https://cdn.geolonia.com/logo/geolonia-symbol_1.png";
|
|
493
|
-
img.style.width = "16px";
|
|
494
|
-
img.style.height = "16px";
|
|
495
|
-
img.style.display = "block";
|
|
496
|
-
img.style.cursor = "pointer";
|
|
497
|
-
img.style.padding = "0";
|
|
498
|
-
img.style.margin = "0";
|
|
499
|
-
img.style.border = "none";
|
|
500
|
-
img.alt = "Geolonia";
|
|
501
|
-
const link = document.createElement("a");
|
|
502
|
-
link.href = "https://geolonia.com/";
|
|
503
|
-
link.appendChild(img);
|
|
504
|
-
link.title = "Powered by Geolonia";
|
|
505
|
-
this.container.appendChild(link);
|
|
506
|
-
return this.container;
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* コントロールの DOM 要素を地図から除去します。
|
|
510
|
-
*
|
|
511
|
-
* `IControl` の実装として、`Map.removeControl` で地図から取り除かれた際に MapLibre から呼び出されます。
|
|
512
|
-
* `onAdd` で生成したコンテナを親ノードから削除します。
|
|
513
|
-
*/
|
|
514
|
-
onRemove() {
|
|
515
|
-
this.container.parentNode?.removeChild(this.container);
|
|
516
|
-
}
|
|
517
|
-
/**
|
|
518
|
-
* このコントロールの既定の表示位置を返します。
|
|
519
|
-
*
|
|
520
|
-
* `Map.addControl` で位置を明示しなかった場合に使用されます。
|
|
521
|
-
*
|
|
522
|
-
* @returns 既定の表示位置 `"bottom-left"`。
|
|
523
|
-
*/
|
|
524
|
-
getDefaultPosition() {
|
|
525
|
-
return "bottom-left";
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
// src/lib/geolonia-map.ts
|
|
530
|
-
var import_maplibre_gl5 = __toESM(require("maplibre-gl"), 1);
|
|
531
|
-
var import_pmtiles = require("pmtiles");
|
|
532
|
-
|
|
533
|
-
// src/lib/geolonia-marker.ts
|
|
534
|
-
var import_maplibre_gl2 = __toESM(require("maplibre-gl"), 1);
|
|
535
|
-
var import_tinycolor2 = __toESM(require("tinycolor2"), 1);
|
|
536
|
-
var MARKER_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 67">
|
|
537
|
-
<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"/>
|
|
538
|
-
<path class="right" d="M26 0c14.336 0 26 11.663 26 26 0 22.14-26 41-26 41V26h0C26 11.663 26 0 26 0z" fill="#C1272D"/>
|
|
539
|
-
<circle cx="26" cy="26" r="9" fill="#FFF"/>
|
|
540
|
-
</svg>`;
|
|
541
|
-
var DEFAULT_COLOR = "#E4402F";
|
|
542
|
-
var GeoloniaMarker = class extends import_maplibre_gl2.default.Marker {
|
|
543
|
-
/**
|
|
544
|
-
* Geolonia マーカーを作成します。
|
|
545
|
-
*
|
|
546
|
-
* `options.element` が指定されていない場合は、Geolonia デフォルトの SVG マーカー
|
|
547
|
-
* 要素を生成して `options.element` に設定し、`options.color`(未指定時は `#E4402F`)で
|
|
548
|
-
* マーカーの色を適用したうえで、`options.offset` を `[0, -15]` に設定します。
|
|
549
|
-
* `options.element` が指定されている場合は、これらの処理を行わず指定された要素を
|
|
550
|
-
* そのまま使用します。
|
|
551
|
-
*
|
|
552
|
-
* @param options `maplibregl.Marker` の `MarkerOptions` です。`element` を省略すると
|
|
553
|
-
* Geolonia デフォルトのマーカーが生成され、`color` でその色を指定できます。
|
|
554
|
-
* 省略した場合は空のオブジェクトが使われます。
|
|
555
|
-
*/
|
|
556
|
-
constructor(options = {}) {
|
|
557
|
-
if (!options.element) {
|
|
558
|
-
const markerElement = document.createElement("div");
|
|
559
|
-
markerElement.className = "geolonia-default-marker";
|
|
560
|
-
markerElement.innerHTML = MARKER_SVG;
|
|
561
|
-
markerElement.style.margin = "0";
|
|
562
|
-
markerElement.style.padding = "0";
|
|
563
|
-
markerElement.style.width = "26px";
|
|
564
|
-
markerElement.style.height = "34px";
|
|
565
|
-
const svg = markerElement.querySelector("svg");
|
|
566
|
-
if (svg) {
|
|
567
|
-
svg.style.width = "100%";
|
|
568
|
-
svg.style.height = "100%";
|
|
569
|
-
}
|
|
570
|
-
options.element = markerElement;
|
|
571
|
-
const color = options.color || DEFAULT_COLOR;
|
|
572
|
-
const left = markerElement.querySelector(".left");
|
|
573
|
-
const right = markerElement.querySelector(".right");
|
|
574
|
-
if (left) left.style.fill = color;
|
|
575
|
-
if (right) right.style.fill = (0, import_tinycolor2.default)(color).darken().toString();
|
|
576
|
-
options.offset = [0, -15];
|
|
577
|
-
}
|
|
578
|
-
super(options);
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
// src/lib/simplestyle.ts
|
|
583
|
-
var import_bbox = __toESM(require("@turf/bbox"), 1);
|
|
584
|
-
var import_center = __toESM(require("@turf/center"), 1);
|
|
585
|
-
var import_maplibre_gl3 = __toESM(require("maplibre-gl"), 1);
|
|
586
|
-
|
|
587
|
-
// src/lib/keyring.ts
|
|
588
|
-
var DEFAULT_STAGE = "v1";
|
|
589
|
-
var _apiKey, _stage, _isGeoloniaStyle;
|
|
590
|
-
var Keyring = class {
|
|
591
|
-
constructor() {
|
|
592
|
-
__privateAdd(this, _apiKey, "");
|
|
593
|
-
__privateAdd(this, _stage, DEFAULT_STAGE);
|
|
594
|
-
__privateAdd(this, _isGeoloniaStyle, true);
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* 現在設定されている API キーを返します。
|
|
598
|
-
*
|
|
599
|
-
* 未設定の場合は空文字列を返します。
|
|
600
|
-
*
|
|
601
|
-
* @returns API キーの文字列を返します。
|
|
602
|
-
*/
|
|
603
|
-
get apiKey() {
|
|
604
|
-
return __privateGet(this, _apiKey);
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* 現在設定されているステージを返します。
|
|
608
|
-
*
|
|
609
|
-
* 初期値は {@link DEFAULT_STAGE}(`"v1"`)です。
|
|
610
|
-
*
|
|
611
|
-
* @returns ステージを表す文字列を返します。
|
|
612
|
-
*/
|
|
613
|
-
get stage() {
|
|
614
|
-
return __privateGet(this, _stage);
|
|
615
|
-
}
|
|
616
|
-
/**
|
|
617
|
-
* 現在のスタイルが Geolonia スタイル(API キーが必要なスタイル)かどうかを返します。
|
|
618
|
-
*
|
|
619
|
-
* @returns Geolonia スタイルの場合は `true`、それ以外の場合は `false` を返します。
|
|
620
|
-
*/
|
|
621
|
-
get isGeoloniaStyle() {
|
|
622
|
-
return __privateGet(this, _isGeoloniaStyle);
|
|
623
|
-
}
|
|
624
|
-
/**
|
|
625
|
-
* 現在のスタイルが Geolonia スタイルかどうかを設定します。
|
|
626
|
-
*
|
|
627
|
-
* @param value Geolonia スタイルとして扱う場合は `true`、それ以外の場合は `false` を指定します。
|
|
628
|
-
*/
|
|
629
|
-
set isGeoloniaStyle(value) {
|
|
630
|
-
__privateSet(this, _isGeoloniaStyle, value);
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* API キーを設定します。
|
|
634
|
-
*
|
|
635
|
-
* @param key 設定する API キーの文字列を指定します。
|
|
636
|
-
*/
|
|
637
|
-
setApiKey(key) {
|
|
638
|
-
__privateSet(this, _apiKey, key);
|
|
639
|
-
}
|
|
640
|
-
/**
|
|
641
|
-
* ステージを設定します。
|
|
642
|
-
*
|
|
643
|
-
* @param stage 設定するステージの文字列を指定します。
|
|
644
|
-
*/
|
|
645
|
-
setStage(stage) {
|
|
646
|
-
__privateSet(this, _stage, stage);
|
|
647
|
-
}
|
|
648
|
-
/**
|
|
649
|
-
* API キー、ステージ、Geolonia スタイル判定をすべて初期状態に戻します。
|
|
650
|
-
*
|
|
651
|
-
* API キーは空文字列、ステージは {@link DEFAULT_STAGE}、Geolonia スタイル判定は `true` にリセットされます。
|
|
652
|
-
*/
|
|
653
|
-
reset() {
|
|
654
|
-
__privateSet(this, _apiKey, "");
|
|
655
|
-
__privateSet(this, _stage, DEFAULT_STAGE);
|
|
656
|
-
__privateSet(this, _isGeoloniaStyle, true);
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* 与えられたスタイルが Geolonia スタイル(API キーが必要なスタイル)かどうかを判定します。
|
|
660
|
-
*
|
|
661
|
-
* 判定は次のロジックで行われます。
|
|
662
|
-
*
|
|
663
|
-
* - 空文字列(未指定)の場合は `true` を返します。
|
|
664
|
-
* - `https://cdn.geolonia.com/style/` または `https://api.geolonia.com/` で始まる URL の場合は `true` を返します。
|
|
665
|
-
* - 上記以外で `http://` または `https://` で始まる外部 URL の場合は `false` を返します。
|
|
666
|
-
* - `geolonia://` で始まる場合は Geolonia 独自プロトコルのため `true` を返します。
|
|
667
|
-
* - それ以外のプロトコル(`xxx://` 形式)で始まる場合は `false` を返します。
|
|
668
|
-
* - `.json` で終わる場合は `false` を返します。
|
|
669
|
-
* - 上記のいずれにも該当しない場合は、`geolonia/basic` のような Geolonia の論理名とみなして `true` を返します。
|
|
670
|
-
*
|
|
671
|
-
* @param style 判定対象のスタイル(URL、プロトコル付き文字列、または論理名)を指定します。
|
|
672
|
-
* @returns Geolonia スタイルの場合は `true`、それ以外の場合は `false` を返します。
|
|
673
|
-
*/
|
|
674
|
-
isGeoloniaStyleCheck(style) {
|
|
675
|
-
if (!style || style === "") {
|
|
676
|
-
return true;
|
|
677
|
-
}
|
|
678
|
-
if (style.startsWith("https://cdn.geolonia.com/style/") || style.startsWith("https://api.geolonia.com/")) {
|
|
679
|
-
return true;
|
|
680
|
-
}
|
|
681
|
-
if (style.match(/^https?:\/\//)) {
|
|
682
|
-
return false;
|
|
683
|
-
}
|
|
684
|
-
if (style.startsWith("geolonia://")) {
|
|
685
|
-
return true;
|
|
686
|
-
}
|
|
687
|
-
if (style.match(/^[a-z][a-z0-9+.-]*:\/\//i)) {
|
|
688
|
-
return false;
|
|
689
|
-
}
|
|
690
|
-
if (style.endsWith(".json")) {
|
|
691
|
-
return false;
|
|
692
|
-
}
|
|
693
|
-
return true;
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
_apiKey = new WeakMap();
|
|
697
|
-
_stage = new WeakMap();
|
|
698
|
-
_isGeoloniaStyle = new WeakMap();
|
|
699
|
-
var keyring = new Keyring();
|
|
700
|
-
|
|
701
|
-
// src/lib/util.ts
|
|
702
|
-
function isURL(str) {
|
|
703
|
-
if (str.match(/^https?:\/\//)) {
|
|
704
|
-
return str;
|
|
705
|
-
}
|
|
706
|
-
if (str.match(/^\//) || str.match(/^\.\.?/)) {
|
|
707
|
-
try {
|
|
708
|
-
return new URL(str, globalThis.location?.href).href;
|
|
709
|
-
} catch {
|
|
710
|
-
return false;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
return false;
|
|
714
|
-
}
|
|
715
|
-
function isGeoloniaTilesHost(url) {
|
|
716
|
-
try {
|
|
717
|
-
const urlObj = typeof url === "string" ? new URL(url) : url;
|
|
718
|
-
return urlObj.hostname === "tileserver.geolonia.com" || urlObj.hostname.endsWith(".tiles.geolonia.com");
|
|
719
|
-
} catch {
|
|
720
|
-
return false;
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
function getStyle(style, options) {
|
|
724
|
-
const lang = options.lang || "en";
|
|
725
|
-
const apiKey = options.apiKey || keyring.apiKey;
|
|
726
|
-
if (keyring.isGeoloniaStyleCheck(style) && !apiKey) {
|
|
727
|
-
throw new Error("[Geolonia] API key is required to use Geolonia styles.");
|
|
728
|
-
}
|
|
729
|
-
if (!style || style === "") {
|
|
730
|
-
return `https://cdn.geolonia.com/style/geolonia/basic-v2/${lang === "ja" || lang === "ja-jp" ? "ja" : "en"}.json`;
|
|
731
|
-
}
|
|
732
|
-
const styleUrl = isURL(style);
|
|
733
|
-
if (styleUrl) {
|
|
734
|
-
return styleUrl;
|
|
735
|
-
}
|
|
736
|
-
if (style.endsWith(".json")) {
|
|
737
|
-
try {
|
|
738
|
-
return new URL(style, globalThis.location?.href).href;
|
|
739
|
-
} catch {
|
|
740
|
-
return style;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
return `https://cdn.geolonia.com/style/${style}/${lang === "ja" || lang === "ja-jp" ? "ja" : "en"}.json`;
|
|
744
|
-
}
|
|
745
|
-
function getLang() {
|
|
746
|
-
if (typeof globalThis.navigator === "undefined") {
|
|
747
|
-
return "en";
|
|
748
|
-
}
|
|
749
|
-
const lang = globalThis.navigator.languages?.[0]?.toLowerCase() || globalThis.navigator.language?.toLowerCase();
|
|
750
|
-
return lang === "ja" || lang === "ja-jp" ? "ja" : "en";
|
|
751
|
-
}
|
|
752
|
-
var sessionId = "";
|
|
753
|
-
function getSessionId(digit) {
|
|
754
|
-
if (sessionId) {
|
|
755
|
-
return sessionId;
|
|
756
|
-
}
|
|
757
|
-
const array = new Uint8Array(digit / 2);
|
|
758
|
-
crypto.getRandomValues(array);
|
|
759
|
-
sessionId = Array.from(
|
|
760
|
-
array,
|
|
761
|
-
(dec) => dec.toString(16).padStart(2, "0")
|
|
762
|
-
).join("");
|
|
763
|
-
return sessionId;
|
|
764
|
-
}
|
|
765
|
-
function parseControlOption(value) {
|
|
766
|
-
if (typeof value === "boolean") {
|
|
767
|
-
return { enabled: value, position: void 0 };
|
|
768
|
-
}
|
|
769
|
-
if (typeof value === "string") {
|
|
770
|
-
const positions = ["top-right", "bottom-right", "bottom-left", "top-left"];
|
|
771
|
-
if (positions.includes(value.toLowerCase())) {
|
|
772
|
-
return { enabled: true, position: value.toLowerCase() };
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
return { enabled: false, position: void 0 };
|
|
776
|
-
}
|
|
777
|
-
function parseSimpleVector(attributeValue) {
|
|
778
|
-
if (/^(https?|geolonia):\/\//.test(attributeValue)) {
|
|
779
|
-
return attributeValue;
|
|
780
|
-
}
|
|
781
|
-
return `geolonia://tiles/custom/${attributeValue}`;
|
|
782
|
-
}
|
|
783
|
-
function handleRestrictedMode(map) {
|
|
784
|
-
if (!map._geolonia_restricted_mode_handled) {
|
|
785
|
-
map._geolonia_restricted_mode_handled = true;
|
|
786
|
-
const container = map.getContainer();
|
|
787
|
-
map.remove();
|
|
788
|
-
container.innerHTML = "";
|
|
789
|
-
container.classList.add("geolonia__restricted-mode-image-container");
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
function handleErrorMode(container) {
|
|
793
|
-
const errorContainer = document.createElement("div");
|
|
794
|
-
errorContainer.classList.add("geolonia__error-container");
|
|
795
|
-
const div = document.createElement("div");
|
|
796
|
-
const h2 = document.createElement("h2");
|
|
797
|
-
h2.textContent = "Geolonia Maps";
|
|
798
|
-
div.appendChild(h2);
|
|
799
|
-
div.classList.add("geolonia__error-message");
|
|
800
|
-
div.innerHTML += '<div class="geolonia__error-message-description">\u5730\u56F3\u306E\u521D\u671F\u5316\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002\u7BA1\u7406\u8005\u306B\u304A\u554F\u3044\u5408\u308F\u305B\u4E0B\u3055\u3044\u3002</div>';
|
|
801
|
-
errorContainer.appendChild(div);
|
|
802
|
-
container.appendChild(errorContainer);
|
|
803
|
-
}
|
|
804
|
-
async function sanitizeDescription(description) {
|
|
805
|
-
const { default: sanitizeHtml } = await import("sanitize-html");
|
|
806
|
-
return sanitizeHtml(description, {
|
|
807
|
-
allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img"]),
|
|
808
|
-
allowedAttributes: {
|
|
809
|
-
...sanitizeHtml.defaults.allowedAttributes,
|
|
810
|
-
"*": ["class"]
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
function loadImageCompatibility(promise, callback) {
|
|
815
|
-
promise.then((response) => {
|
|
816
|
-
callback(null, response.data, {
|
|
817
|
-
cacheControl: response.cacheControl,
|
|
818
|
-
expires: response.expires
|
|
819
|
-
});
|
|
820
|
-
}).catch((error) => {
|
|
821
|
-
callback(error);
|
|
822
|
-
});
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
// src/lib/simplestyle.ts
|
|
826
|
-
var textColor = "#000000";
|
|
827
|
-
var textHaloColor = "#FFFFFF";
|
|
828
|
-
var backgroundColor = "rgba(255, 0, 0, 0.4)";
|
|
829
|
-
var strokeColor = "#FFFFFF";
|
|
830
|
-
var template = {
|
|
831
|
-
type: "FeatureCollection",
|
|
832
|
-
features: []
|
|
833
|
-
};
|
|
834
|
-
var SimpleStyle = class {
|
|
835
|
-
/**
|
|
836
|
-
* SimpleStyle を作成します。
|
|
837
|
-
*
|
|
838
|
-
* `geojson` に URL 文字列を渡した場合は、その URL から GeoJSON を非同期に取得します。
|
|
839
|
-
* 取得の完了は `_loadingPromise` で待つことができます。
|
|
840
|
-
*
|
|
841
|
-
* @param geojson 表示する GeoJSON です。{@link FeatureCollection} または GeoJSON を返す URL 文字列を指定します。
|
|
842
|
-
* @param options 表示オプションです。指定した項目のみが既定値を上書きします。既定値は
|
|
843
|
-
* `id: "geolonia-simple-style"`、`cluster: true`、`heatmap: false`、`clusterColor: "#ff0000"` です。
|
|
844
|
-
*/
|
|
845
|
-
constructor(geojson, options) {
|
|
846
|
-
this.callFitBounds = false;
|
|
847
|
-
this._eventHandlers = [];
|
|
848
|
-
this.setGeoJSON(geojson);
|
|
849
|
-
this.options = {
|
|
850
|
-
id: "geolonia-simple-style",
|
|
851
|
-
cluster: true,
|
|
852
|
-
heatmap: false,
|
|
853
|
-
// TODO: It should support heatmap.
|
|
854
|
-
clusterColor: "#ff0000",
|
|
855
|
-
...options
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* 表示中のデータを新しい GeoJSON で差し替えます。
|
|
860
|
-
*
|
|
861
|
-
* フィーチャーをポイントとそれ以外(ポリゴン、ライン)に振り分け、
|
|
862
|
-
* それぞれ対応するソースの内容を更新します。レイヤー自体の追加は行わないため、
|
|
863
|
-
* あらかじめ {@link SimpleStyle.addTo | addTo} で地図に追加されている必要があります。
|
|
864
|
-
*
|
|
865
|
-
* @param geojson 差し替える {@link FeatureCollection} です。
|
|
866
|
-
* @returns メソッドチェーンのための `this` を返します。
|
|
867
|
-
*/
|
|
868
|
-
updateData(geojson) {
|
|
869
|
-
this.setGeoJSON(geojson);
|
|
870
|
-
const features = this.geojson.features;
|
|
871
|
-
const polygonAndLines = features.filter(
|
|
872
|
-
(feature) => feature.geometry.type.toLowerCase() !== "point"
|
|
873
|
-
);
|
|
874
|
-
const points = features.filter(
|
|
875
|
-
(feature) => feature.geometry.type.toLowerCase() === "point"
|
|
876
|
-
);
|
|
877
|
-
this.map.getSource(this.options.id)?.setData({
|
|
878
|
-
type: "FeatureCollection",
|
|
879
|
-
features: polygonAndLines
|
|
880
|
-
});
|
|
881
|
-
this.map.getSource(`${this.options.id}-points`)?.setData(
|
|
882
|
-
{
|
|
883
|
-
type: "FeatureCollection",
|
|
884
|
-
features: points
|
|
885
|
-
}
|
|
886
|
-
);
|
|
887
|
-
return this;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* 地図にソースとレイヤーを追加して GeoJSON を表示します。
|
|
891
|
-
*
|
|
892
|
-
* ポリゴンとラインのソース、ポイント用のソース(クラスタリング設定付き)を追加し、
|
|
893
|
-
* ポリゴンとラインのラベル用シンボルレイヤーを配置したうえで、
|
|
894
|
-
* {@link SimpleStyle.setPolygonGeometries | setPolygonGeometries}、
|
|
895
|
-
* {@link SimpleStyle.setLineGeometries | setLineGeometries}、
|
|
896
|
-
* {@link SimpleStyle.setPointGeometries | setPointGeometries}、
|
|
897
|
-
* {@link SimpleStyle.setCluster | setCluster} を呼び出して各ジオメトリのレイヤーを設定します。
|
|
898
|
-
*
|
|
899
|
-
* @param map 表示先の地図です。
|
|
900
|
-
* @returns メソッドチェーンのための `this` を返します。
|
|
901
|
-
*
|
|
902
|
-
* @example
|
|
903
|
-
* ```typescript
|
|
904
|
-
* new SimpleStyle(geojson).addTo(map);
|
|
905
|
-
* ```
|
|
906
|
-
*/
|
|
907
|
-
addTo(map) {
|
|
908
|
-
this.map = map;
|
|
909
|
-
const features = this.geojson.features;
|
|
910
|
-
const polygonAndLines = features.filter(
|
|
911
|
-
(feature) => feature.geometry.type.toLowerCase() !== "point"
|
|
912
|
-
);
|
|
913
|
-
const points = features.filter(
|
|
914
|
-
(feature) => feature.geometry.type.toLowerCase() === "point"
|
|
915
|
-
);
|
|
916
|
-
this.map.addSource(this.options.id, {
|
|
917
|
-
type: "geojson",
|
|
918
|
-
data: {
|
|
919
|
-
type: "FeatureCollection",
|
|
920
|
-
features: polygonAndLines
|
|
921
|
-
}
|
|
922
|
-
});
|
|
923
|
-
this.setPolygonGeometries();
|
|
924
|
-
this.setLineGeometries();
|
|
925
|
-
this.map.addSource(`${this.options.id}-points`, {
|
|
926
|
-
type: "geojson",
|
|
927
|
-
data: {
|
|
928
|
-
type: "FeatureCollection",
|
|
929
|
-
features: points
|
|
930
|
-
},
|
|
931
|
-
cluster: this.options.cluster,
|
|
932
|
-
clusterMaxZoom: 14,
|
|
933
|
-
clusterRadius: 50
|
|
934
|
-
});
|
|
935
|
-
this.map.addLayer({
|
|
936
|
-
id: `${this.options.id}-polygon-symbol`,
|
|
937
|
-
type: "symbol",
|
|
938
|
-
source: this.options.id,
|
|
939
|
-
filter: ["==", "$type", "Polygon"],
|
|
940
|
-
paint: {
|
|
941
|
-
"text-color": ["string", ["get", "text-color"], textColor],
|
|
942
|
-
"text-halo-color": [
|
|
943
|
-
"string",
|
|
944
|
-
["get", "text-halo-color"],
|
|
945
|
-
textHaloColor
|
|
946
|
-
],
|
|
947
|
-
"text-halo-width": 1
|
|
948
|
-
},
|
|
949
|
-
layout: {
|
|
950
|
-
"text-field": ["get", "title"],
|
|
951
|
-
"text-font": ["Noto Sans Regular"],
|
|
952
|
-
"text-size": 12,
|
|
953
|
-
"text-max-width": 12,
|
|
954
|
-
"text-allow-overlap": false
|
|
955
|
-
}
|
|
956
|
-
});
|
|
957
|
-
this.map.addLayer({
|
|
958
|
-
id: `${this.options.id}-linestring-symbol`,
|
|
959
|
-
type: "symbol",
|
|
960
|
-
source: this.options.id,
|
|
961
|
-
filter: ["==", "$type", "LineString"],
|
|
962
|
-
paint: {
|
|
963
|
-
"text-color": ["string", ["get", "text-color"], textColor],
|
|
964
|
-
"text-halo-color": [
|
|
965
|
-
"string",
|
|
966
|
-
["get", "text-halo-color"],
|
|
967
|
-
textHaloColor
|
|
968
|
-
],
|
|
969
|
-
"text-halo-width": 1
|
|
970
|
-
},
|
|
971
|
-
layout: {
|
|
972
|
-
"symbol-placement": "line",
|
|
973
|
-
"text-field": ["get", "title"],
|
|
974
|
-
"text-font": ["Noto Sans Regular"],
|
|
975
|
-
"text-size": 12,
|
|
976
|
-
"text-max-width": 12,
|
|
977
|
-
"text-allow-overlap": false
|
|
978
|
-
}
|
|
979
|
-
});
|
|
980
|
-
this.setPointGeometries();
|
|
981
|
-
this.setCluster();
|
|
982
|
-
return this;
|
|
983
|
-
}
|
|
984
|
-
/**
|
|
985
|
-
* データ全体の範囲に地図をフィットさせます。
|
|
986
|
-
*
|
|
987
|
-
* 現在の GeoJSON のフィーチャーからバウンディングボックスを算出し、そこへ地図を移動します。
|
|
988
|
-
* フィーチャーが存在しない場合は何もしません。データを URL から取得中に呼び出した場合は、
|
|
989
|
-
* フィット要求を保持しておき、取得完了後に自動でフィットします。
|
|
990
|
-
*
|
|
991
|
-
* @param options `map.fitBounds` に渡すオプションです。既定値は `duration: 3000`、`padding: 30` で、
|
|
992
|
-
* 指定した項目のみがこれらを上書きします。
|
|
993
|
-
* @returns メソッドチェーンのための `this` を返します。
|
|
994
|
-
*/
|
|
995
|
-
fitBounds(options = {}) {
|
|
996
|
-
this.callFitBounds = true;
|
|
997
|
-
const _options = {
|
|
998
|
-
duration: 3e3,
|
|
999
|
-
padding: 30,
|
|
1000
|
-
...options
|
|
1001
|
-
};
|
|
1002
|
-
const bounds = this.geojson.features.length > 0 ? (0, import_bbox.default)(this.geojson) : void 0;
|
|
1003
|
-
if (bounds) {
|
|
1004
|
-
window.requestAnimationFrame(() => {
|
|
1005
|
-
this.map.fitBounds(bounds, _options);
|
|
1006
|
-
});
|
|
1007
|
-
}
|
|
1008
|
-
return this;
|
|
1009
|
-
}
|
|
1010
|
-
/**
|
|
1011
|
-
* ポリゴンの塗りレイヤーを設定します。
|
|
1012
|
-
*
|
|
1013
|
-
* `$type` が `Polygon` のフィーチャーを対象に塗りレイヤーを追加し、
|
|
1014
|
-
* `fill`、`fill-opacity`、`stroke`(輪郭色)の各 simplestyle プロパティを反映します。
|
|
1015
|
-
* あわせて {@link SimpleStyle.setPopup | setPopup} でこのレイヤーにポップアップを設定します。
|
|
1016
|
-
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
1017
|
-
*/
|
|
1018
|
-
setPolygonGeometries() {
|
|
1019
|
-
this.map.addLayer({
|
|
1020
|
-
id: `${this.options.id}-polygon`,
|
|
1021
|
-
type: "fill",
|
|
1022
|
-
source: this.options.id,
|
|
1023
|
-
filter: ["==", "$type", "Polygon"],
|
|
1024
|
-
paint: {
|
|
1025
|
-
"fill-color": ["string", ["get", "fill"], backgroundColor],
|
|
1026
|
-
"fill-opacity": ["number", ["get", "fill-opacity"], 1],
|
|
1027
|
-
"fill-outline-color": ["string", ["get", "stroke"], strokeColor]
|
|
1028
|
-
}
|
|
1029
|
-
});
|
|
1030
|
-
this.setPopup(this.map, `${this.options.id}-polygon`);
|
|
1031
|
-
}
|
|
1032
|
-
/**
|
|
1033
|
-
* ラインのレイヤーを設定します。
|
|
1034
|
-
*
|
|
1035
|
-
* `$type` が `LineString` のフィーチャーを対象にラインレイヤーを追加し、
|
|
1036
|
-
* `stroke-width`(線幅)、`stroke`(線色)、`stroke-opacity`(不透明度)の各 simplestyle プロパティを反映します。
|
|
1037
|
-
* 線端と結合は丸めて描画します。あわせて {@link SimpleStyle.setPopup | setPopup} でこのレイヤーにポップアップを設定します。
|
|
1038
|
-
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
1039
|
-
*/
|
|
1040
|
-
setLineGeometries() {
|
|
1041
|
-
this.map.addLayer({
|
|
1042
|
-
id: `${this.options.id}-linestring`,
|
|
1043
|
-
type: "line",
|
|
1044
|
-
source: this.options.id,
|
|
1045
|
-
filter: ["==", "$type", "LineString"],
|
|
1046
|
-
paint: {
|
|
1047
|
-
"line-width": ["number", ["get", "stroke-width"], 2],
|
|
1048
|
-
"line-color": ["string", ["get", "stroke"], backgroundColor],
|
|
1049
|
-
"line-opacity": ["number", ["get", "stroke-opacity"], 1]
|
|
1050
|
-
},
|
|
1051
|
-
layout: {
|
|
1052
|
-
"line-cap": "round",
|
|
1053
|
-
"line-join": "round"
|
|
1054
|
-
}
|
|
1055
|
-
});
|
|
1056
|
-
this.setPopup(this.map, `${this.options.id}-linestring`);
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* ポイントのレイヤーを設定します。
|
|
1060
|
-
*
|
|
1061
|
-
* クラスターに属さないポイントを対象に、2 種類のレイヤーを追加します。
|
|
1062
|
-
* `marker-symbol` を持たないポイントには円レイヤーを、
|
|
1063
|
-
* `marker-symbol` を持つポイントにはアイコンとラベルのシンボルレイヤーを使います。
|
|
1064
|
-
* `marker-size`(`small`、`large`、その他)に応じて円の半径やラベルのオフセットを変え、
|
|
1065
|
-
* `marker-color`、`stroke`、`title`、`text-color` などの simplestyle プロパティを反映します。
|
|
1066
|
-
* あわせて円レイヤーとシンボルレイヤーの双方に {@link SimpleStyle.setPopup | setPopup} でポップアップを設定します。
|
|
1067
|
-
* 通常は {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
1068
|
-
*/
|
|
1069
|
-
setPointGeometries() {
|
|
1070
|
-
this.map.addLayer({
|
|
1071
|
-
id: `${this.options.id}-circle-points`,
|
|
1072
|
-
type: "circle",
|
|
1073
|
-
source: `${this.options.id}-points`,
|
|
1074
|
-
filter: ["all", ["!has", "point_count"], ["!has", "marker-symbol"]],
|
|
1075
|
-
paint: {
|
|
1076
|
-
"circle-radius": [
|
|
1077
|
-
"case",
|
|
1078
|
-
["==", "small", ["get", "marker-size"]],
|
|
1079
|
-
7,
|
|
1080
|
-
["==", "large", ["get", "marker-size"]],
|
|
1081
|
-
13,
|
|
1082
|
-
9
|
|
1083
|
-
],
|
|
1084
|
-
"circle-color": ["string", ["get", "marker-color"], backgroundColor],
|
|
1085
|
-
"circle-opacity": ["number", ["get", "fill-opacity"], 1],
|
|
1086
|
-
"circle-stroke-width": ["number", ["get", "stroke-width"], 1],
|
|
1087
|
-
"circle-stroke-color": ["string", ["get", "stroke"], strokeColor],
|
|
1088
|
-
"circle-stroke-opacity": ["number", ["get", "stroke-opacity"], 1]
|
|
1089
|
-
}
|
|
1090
|
-
});
|
|
1091
|
-
this.map.addLayer({
|
|
1092
|
-
id: `${this.options.id}-symbol-points`,
|
|
1093
|
-
type: "symbol",
|
|
1094
|
-
source: `${this.options.id}-points`,
|
|
1095
|
-
filter: ["!", ["has", "point_count"]],
|
|
1096
|
-
paint: {
|
|
1097
|
-
"text-color": ["string", ["get", "text-color"], textColor],
|
|
1098
|
-
"text-halo-color": [
|
|
1099
|
-
"string",
|
|
1100
|
-
["get", "text-halo-color"],
|
|
1101
|
-
textHaloColor
|
|
1102
|
-
],
|
|
1103
|
-
"text-halo-width": 1
|
|
1104
|
-
},
|
|
1105
|
-
layout: {
|
|
1106
|
-
"icon-image": ["get", "marker-symbol"],
|
|
1107
|
-
"text-field": ["get", "title"],
|
|
1108
|
-
"text-font": ["Noto Sans Regular"],
|
|
1109
|
-
"text-size": 12,
|
|
1110
|
-
"text-max-width": 12,
|
|
1111
|
-
"text-allow-overlap": true,
|
|
1112
|
-
"icon-allow-overlap": true,
|
|
1113
|
-
"text-variable-anchor": ["top", "bottom", "left", "right"],
|
|
1114
|
-
"text-radial-offset": [
|
|
1115
|
-
"case",
|
|
1116
|
-
["==", "small", ["get", "marker-size"]],
|
|
1117
|
-
1,
|
|
1118
|
-
["==", "large", ["get", "marker-size"]],
|
|
1119
|
-
1.6,
|
|
1120
|
-
1.2
|
|
1121
|
-
]
|
|
1122
|
-
}
|
|
1123
|
-
});
|
|
1124
|
-
this.setPopup(this.map, `${this.options.id}-circle-points`);
|
|
1125
|
-
this.setPopup(this.map, `${this.options.id}-symbol-points`);
|
|
1126
|
-
}
|
|
1127
|
-
/**
|
|
1128
|
-
* 指定したレイヤーにクリックでポップアップを表示するイベントハンドラーを設定します。
|
|
1129
|
-
*
|
|
1130
|
-
* クリックされたフィーチャーが `description` プロパティを持つ場合、その中心座標に
|
|
1131
|
-
* サニタイズ済みの HTML を表示するポップアップを追加します。あわせてホバー時に
|
|
1132
|
-
* カーソルを変えるハンドラーも設定します。登録したハンドラーは `_eventHandlers` に記録され、
|
|
1133
|
-
* {@link SimpleStyle.remove | remove} でまとめて解除されます。
|
|
1134
|
-
*
|
|
1135
|
-
* @param map ポップアップを表示する地図です。
|
|
1136
|
-
* @param source ハンドラーを設定する対象のレイヤー ID です。
|
|
1137
|
-
*/
|
|
1138
|
-
async setPopup(map, source) {
|
|
1139
|
-
const clickHandler = async (e) => {
|
|
1140
|
-
if (!e.features?.[0]) return;
|
|
1141
|
-
const center = (0, import_center.default)(e.features[0]).geometry.coordinates;
|
|
1142
|
-
const description = e.features[0].properties?.description;
|
|
1143
|
-
if (description) {
|
|
1144
|
-
const sanitizedDescription = await sanitizeDescription(description);
|
|
1145
|
-
new import_maplibre_gl3.default.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
const mouseEnterHandler = (e) => {
|
|
1149
|
-
if (e.features?.[0]?.properties?.description) {
|
|
1150
|
-
map.getCanvas().style.cursor = "pointer";
|
|
1151
|
-
}
|
|
1152
|
-
};
|
|
1153
|
-
const mouseLeaveHandler = () => {
|
|
1154
|
-
map.getCanvas().style.cursor = "";
|
|
1155
|
-
};
|
|
1156
|
-
map.on("click", source, clickHandler);
|
|
1157
|
-
map.on("mouseenter", source, mouseEnterHandler);
|
|
1158
|
-
map.on("mouseleave", source, mouseLeaveHandler);
|
|
1159
|
-
this._eventHandlers.push(
|
|
1160
|
-
{ event: "click", layer: source, handler: clickHandler },
|
|
1161
|
-
{ event: "mouseenter", layer: source, handler: mouseEnterHandler },
|
|
1162
|
-
{ event: "mouseleave", layer: source, handler: mouseLeaveHandler }
|
|
1163
|
-
);
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* クラスタリング用のレイヤーを設定します。
|
|
1167
|
-
*
|
|
1168
|
-
* `point_count` を持つクラスターを対象に、クラスターを表す円レイヤーと、
|
|
1169
|
-
* 件数(`point_count_abbreviated`)を表示するラベルのシンボルレイヤーを追加します。
|
|
1170
|
-
* 円の色は `clusterColor` オプションを使います。クラスターをクリックすると、
|
|
1171
|
-
* そのクラスターが展開するズームレベルまで地図を移動します。あわせてホバー時に
|
|
1172
|
-
* カーソルを変えるハンドラーも設定します。登録したハンドラーは `_eventHandlers` に記録され、
|
|
1173
|
-
* {@link SimpleStyle.remove | remove} でまとめて解除されます。通常は
|
|
1174
|
-
* {@link SimpleStyle.addTo | addTo} から呼び出されます。
|
|
1175
|
-
*/
|
|
1176
|
-
setCluster() {
|
|
1177
|
-
this.map.addLayer({
|
|
1178
|
-
id: `${this.options.id}-clusters`,
|
|
1179
|
-
type: "circle",
|
|
1180
|
-
source: `${this.options.id}-points`,
|
|
1181
|
-
filter: ["has", "point_count"],
|
|
1182
|
-
paint: {
|
|
1183
|
-
"circle-radius": 20,
|
|
1184
|
-
"circle-color": this.options.clusterColor,
|
|
1185
|
-
"circle-opacity": 1
|
|
1186
|
-
}
|
|
1187
|
-
});
|
|
1188
|
-
this.map.addLayer({
|
|
1189
|
-
id: `${this.options.id}-cluster-count`,
|
|
1190
|
-
type: "symbol",
|
|
1191
|
-
source: `${this.options.id}-points`,
|
|
1192
|
-
filter: ["has", "point_count"],
|
|
1193
|
-
layout: {
|
|
1194
|
-
"text-field": "{point_count_abbreviated}",
|
|
1195
|
-
"text-size": 14,
|
|
1196
|
-
"text-font": ["Noto Sans Regular"]
|
|
1197
|
-
}
|
|
1198
|
-
});
|
|
1199
|
-
const clusterLayer = `${this.options.id}-clusters`;
|
|
1200
|
-
const clusterClickHandler = async (e) => {
|
|
1201
|
-
const features = this.map.queryRenderedFeatures(e.point, {
|
|
1202
|
-
layers: [clusterLayer]
|
|
1203
|
-
});
|
|
1204
|
-
if (!features[0]) return;
|
|
1205
|
-
const clusterId = features[0].properties?.cluster_id;
|
|
1206
|
-
if (clusterId === void 0) return;
|
|
1207
|
-
const source = this.map.getSource(
|
|
1208
|
-
`${this.options.id}-points`
|
|
1209
|
-
);
|
|
1210
|
-
const zoom = await source.getClusterExpansionZoom(clusterId);
|
|
1211
|
-
this.map.easeTo({
|
|
1212
|
-
center: features[0].geometry.coordinates,
|
|
1213
|
-
zoom
|
|
1214
|
-
});
|
|
1215
|
-
};
|
|
1216
|
-
const clusterEnterHandler = () => {
|
|
1217
|
-
this.map.getCanvas().style.cursor = "pointer";
|
|
1218
|
-
};
|
|
1219
|
-
const clusterLeaveHandler = () => {
|
|
1220
|
-
this.map.getCanvas().style.cursor = "";
|
|
1221
|
-
};
|
|
1222
|
-
this.map.on("click", clusterLayer, clusterClickHandler);
|
|
1223
|
-
this.map.on("mouseenter", clusterLayer, clusterEnterHandler);
|
|
1224
|
-
this.map.on("mouseleave", clusterLayer, clusterLeaveHandler);
|
|
1225
|
-
this._eventHandlers.push(
|
|
1226
|
-
{ event: "click", layer: clusterLayer, handler: clusterClickHandler },
|
|
1227
|
-
{
|
|
1228
|
-
event: "mouseenter",
|
|
1229
|
-
layer: clusterLayer,
|
|
1230
|
-
handler: clusterEnterHandler
|
|
1231
|
-
},
|
|
1232
|
-
{
|
|
1233
|
-
event: "mouseleave",
|
|
1234
|
-
layer: clusterLayer,
|
|
1235
|
-
handler: clusterLeaveHandler
|
|
1236
|
-
}
|
|
1237
|
-
);
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* 追加したソース、レイヤー、イベントハンドラーを地図から除去します。
|
|
1241
|
-
*
|
|
1242
|
-
* {@link SimpleStyle.setPopup | setPopup} や {@link SimpleStyle.setCluster | setCluster}
|
|
1243
|
-
* で登録したイベントハンドラーをすべて解除し、ポリゴン、ライン、ポイント、クラスターの各レイヤーと、
|
|
1244
|
-
* それらのソースを削除します。カーソルのスタイルも元に戻します。まだ地図に追加されていない場合は何もしません。
|
|
1245
|
-
*
|
|
1246
|
-
* @returns メソッドチェーンのための `this` を返します。
|
|
1247
|
-
*/
|
|
1248
|
-
remove() {
|
|
1249
|
-
if (!this.map) return this;
|
|
1250
|
-
const id = this.options.id;
|
|
1251
|
-
for (const { event, layer, handler } of this._eventHandlers) {
|
|
1252
|
-
this.map.off(event, layer, handler);
|
|
1253
|
-
}
|
|
1254
|
-
this._eventHandlers = [];
|
|
1255
|
-
const layerIds = [
|
|
1256
|
-
`${id}-polygon-symbol`,
|
|
1257
|
-
`${id}-linestring-symbol`,
|
|
1258
|
-
`${id}-circle-points`,
|
|
1259
|
-
`${id}-symbol-points`,
|
|
1260
|
-
`${id}-polygon`,
|
|
1261
|
-
`${id}-linestring`,
|
|
1262
|
-
`${id}-clusters`,
|
|
1263
|
-
`${id}-cluster-count`
|
|
1264
|
-
];
|
|
1265
|
-
for (const layerId of layerIds) {
|
|
1266
|
-
if (this.map.getLayer(layerId)) {
|
|
1267
|
-
this.map.removeLayer(layerId);
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
for (const sourceId of [id, `${id}-points`]) {
|
|
1271
|
-
if (this.map.getSource(sourceId)) {
|
|
1272
|
-
this.map.removeSource(sourceId);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
this.map.getCanvas().style.cursor = "";
|
|
1276
|
-
return this;
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* 内部で保持する GeoJSON を設定します。
|
|
1280
|
-
*
|
|
1281
|
-
* `geojson` が URL 文字列の場合は、いったん空のデータを設定したうえで、その URL から GeoJSON を
|
|
1282
|
-
* 非同期に取得します。取得中の Promise は `_loadingPromise` に保持され、取得完了後に
|
|
1283
|
-
* {@link SimpleStyle.updateData | updateData} で表示を更新します。フィット要求が保留されていれば
|
|
1284
|
-
* あわせてフィットします。応答が 2xx 以外の場合は空のデータとして扱い、通信や JSON の解析で
|
|
1285
|
-
* 例外が発生した場合はエラーをコンソールに出力します。
|
|
1286
|
-
* `geojson` が {@link FeatureCollection} の場合は、そのまま内部データとして設定します。
|
|
1287
|
-
*
|
|
1288
|
-
* @param geojson 設定する {@link FeatureCollection} または GeoJSON を返す URL 文字列です。
|
|
1289
|
-
*/
|
|
1290
|
-
setGeoJSON(geojson) {
|
|
1291
|
-
if (typeof geojson === "string" && isURL(geojson)) {
|
|
1292
|
-
this.geojson = template;
|
|
1293
|
-
const fetchGeoJSON = async () => {
|
|
1294
|
-
try {
|
|
1295
|
-
const response = await window.fetch(geojson);
|
|
1296
|
-
const data = response.ok ? await response.json() : template;
|
|
1297
|
-
this.geojson = data;
|
|
1298
|
-
this.updateData(data);
|
|
1299
|
-
if (this.callFitBounds) {
|
|
1300
|
-
this.fitBounds();
|
|
1301
|
-
this.callFitBounds = false;
|
|
1302
|
-
}
|
|
1303
|
-
} catch (error) {
|
|
1304
|
-
console.error("[Geolonia] Failed to load GeoJSON:", error);
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
|
-
this._loadingPromise = fetchGeoJSON();
|
|
1308
|
-
} else if (typeof geojson !== "string") {
|
|
1309
|
-
this.geojson = geojson;
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
};
|
|
1313
|
-
|
|
1314
|
-
// src/lib/simplestyle-vector.ts
|
|
1315
|
-
var import_center2 = __toESM(require("@turf/center"), 1);
|
|
1316
|
-
var import_maplibre_gl4 = __toESM(require("maplibre-gl"), 1);
|
|
1317
|
-
var textColor2 = "#000000";
|
|
1318
|
-
var textHaloColor2 = "#FFFFFF";
|
|
1319
|
-
var backgroundColor2 = "rgba(255, 0, 0, 0.4)";
|
|
1320
|
-
var strokeColor2 = "#FFFFFF";
|
|
1321
|
-
var SimpleStyleVector = class {
|
|
1322
|
-
/**
|
|
1323
|
-
* @param url 表示するベクトルタイルソースの TileJSON(tiles.json)URL です。
|
|
1324
|
-
*/
|
|
1325
|
-
constructor(url) {
|
|
1326
|
-
this.url = url;
|
|
1327
|
-
this.sourceName = "vt-geolonia-simple-style";
|
|
1328
|
-
}
|
|
1329
|
-
/**
|
|
1330
|
-
* 地図にベクトルタイルソースと各レイヤーを追加し、simplestyle の規約に沿って表示します。
|
|
1331
|
-
*
|
|
1332
|
-
* ソースを追加したうえで、ポリゴン(塗り潰しとラベル)、ライン(線とラベル)、
|
|
1333
|
-
* ポイント(円、アイコン、ラベル)の各レイヤーを設定します。あわせて、ポリゴンの塗り潰し、
|
|
1334
|
-
* ラインの線、ポイントの円とアイコンの各レイヤーにクリック時のポップアップを登録します
|
|
1335
|
-
* (ポリゴンやラインのラベル用シンボルレイヤーには登録しません)。
|
|
1336
|
-
*
|
|
1337
|
-
* 地図コンテナの `data-lng` および `data-lat` 属性がいずれも指定されていない場合は、
|
|
1338
|
-
* ソースの読み込み完了を待って、そのソースの `bounds` に一度だけ地図の表示範囲を合わせます
|
|
1339
|
-
* (`padding` は 30、アニメーションなし)。
|
|
1340
|
-
*
|
|
1341
|
-
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1342
|
-
*
|
|
1343
|
-
* @example
|
|
1344
|
-
* ```typescript
|
|
1345
|
-
* new SimpleStyleVector(url).addTo(map);
|
|
1346
|
-
* ```
|
|
1347
|
-
*/
|
|
1348
|
-
addTo(map) {
|
|
1349
|
-
const container = map.getContainer();
|
|
1350
|
-
if (!container.dataset || !container.dataset.lng && !container.dataset.lat) {
|
|
1351
|
-
let initialZoomDone = false;
|
|
1352
|
-
map.on("sourcedata", (event) => {
|
|
1353
|
-
if (event.sourceId !== this.sourceName) {
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
const source = map.getSource(event.sourceId);
|
|
1357
|
-
const isLoaded = source?.loaded();
|
|
1358
|
-
if (isLoaded !== true) {
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
|
-
if (initialZoomDone) {
|
|
1362
|
-
return;
|
|
1363
|
-
}
|
|
1364
|
-
initialZoomDone = true;
|
|
1365
|
-
map.fitBounds(
|
|
1366
|
-
source.bounds,
|
|
1367
|
-
{
|
|
1368
|
-
duration: 0,
|
|
1369
|
-
padding: 30
|
|
1370
|
-
}
|
|
1371
|
-
);
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
map.addSource(this.sourceName, {
|
|
1375
|
-
type: "vector",
|
|
1376
|
-
url: this.url
|
|
1377
|
-
});
|
|
1378
|
-
this.setPolygonGeometries(map);
|
|
1379
|
-
this.setLineGeometries(map);
|
|
1380
|
-
map.addLayer({
|
|
1381
|
-
id: "vt-geolonia-simple-style-polygon-symbol",
|
|
1382
|
-
type: "symbol",
|
|
1383
|
-
source: this.sourceName,
|
|
1384
|
-
"source-layer": "g-simplestyle-v1",
|
|
1385
|
-
filter: ["==", "$type", "Polygon"],
|
|
1386
|
-
paint: {
|
|
1387
|
-
"text-color": ["string", ["get", "text-color"], textColor2],
|
|
1388
|
-
"text-halo-color": [
|
|
1389
|
-
"string",
|
|
1390
|
-
["get", "text-halo-color"],
|
|
1391
|
-
textHaloColor2
|
|
1392
|
-
],
|
|
1393
|
-
"text-halo-width": 1
|
|
1394
|
-
},
|
|
1395
|
-
layout: {
|
|
1396
|
-
"text-field": ["get", "title"],
|
|
1397
|
-
"text-font": ["Noto Sans Regular"],
|
|
1398
|
-
"text-size": 12,
|
|
1399
|
-
"text-max-width": 12,
|
|
1400
|
-
"text-allow-overlap": false
|
|
1401
|
-
}
|
|
1402
|
-
});
|
|
1403
|
-
map.addLayer({
|
|
1404
|
-
id: "vt-geolonia-simple-style-linestring-symbol",
|
|
1405
|
-
type: "symbol",
|
|
1406
|
-
source: this.sourceName,
|
|
1407
|
-
"source-layer": "g-simplestyle-v1",
|
|
1408
|
-
filter: ["==", "$type", "LineString"],
|
|
1409
|
-
paint: {
|
|
1410
|
-
"text-color": ["string", ["get", "text-color"], textColor2],
|
|
1411
|
-
"text-halo-color": [
|
|
1412
|
-
"string",
|
|
1413
|
-
["get", "text-halo-color"],
|
|
1414
|
-
textHaloColor2
|
|
1415
|
-
],
|
|
1416
|
-
"text-halo-width": 1
|
|
1417
|
-
},
|
|
1418
|
-
layout: {
|
|
1419
|
-
"symbol-placement": "line",
|
|
1420
|
-
"text-field": ["get", "title"],
|
|
1421
|
-
"text-font": ["Noto Sans Regular"],
|
|
1422
|
-
"text-size": 12,
|
|
1423
|
-
"text-max-width": 12,
|
|
1424
|
-
"text-allow-overlap": false
|
|
1425
|
-
}
|
|
1426
|
-
});
|
|
1427
|
-
this.setPointGeometries(map);
|
|
1428
|
-
}
|
|
1429
|
-
/**
|
|
1430
|
-
* ポリゴンジオメトリ用のレイヤーを設定します。
|
|
1431
|
-
*
|
|
1432
|
-
* `$type` が `Polygon` のフィーチャーに対して塗り潰しレイヤー(`fill` タイプ)を追加します。
|
|
1433
|
-
* 塗り色はフィーチャーの `fill` プロパティ、不透明度は `fill-opacity`、
|
|
1434
|
-
* 外周線の色は `stroke` プロパティを用い、いずれも未指定の場合は既定値を適用します。
|
|
1435
|
-
* あわせて、このポリゴンレイヤーにクリック時のポップアップを登録します。
|
|
1436
|
-
*
|
|
1437
|
-
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1438
|
-
*/
|
|
1439
|
-
setPolygonGeometries(map) {
|
|
1440
|
-
map.addLayer({
|
|
1441
|
-
id: "vt-geolonia-simple-style-polygon",
|
|
1442
|
-
type: "fill",
|
|
1443
|
-
source: this.sourceName,
|
|
1444
|
-
"source-layer": "g-simplestyle-v1",
|
|
1445
|
-
filter: ["==", "$type", "Polygon"],
|
|
1446
|
-
paint: {
|
|
1447
|
-
"fill-color": ["string", ["get", "fill"], backgroundColor2],
|
|
1448
|
-
"fill-opacity": ["number", ["get", "fill-opacity"], 1],
|
|
1449
|
-
"fill-outline-color": ["string", ["get", "stroke"], strokeColor2]
|
|
1450
|
-
}
|
|
1451
|
-
});
|
|
1452
|
-
this.setPopup(map, "vt-geolonia-simple-style-polygon");
|
|
1453
|
-
}
|
|
1454
|
-
/**
|
|
1455
|
-
* ラインジオメトリ用のレイヤーを設定します。
|
|
1456
|
-
*
|
|
1457
|
-
* `$type` が `LineString` のフィーチャーに対して線レイヤー(`line` タイプ)を追加します。
|
|
1458
|
-
* 線幅はフィーチャーの `stroke-width` プロパティ、線色は `stroke`、
|
|
1459
|
-
* 不透明度は `stroke-opacity` を用い、いずれも未指定の場合は既定値を適用します。
|
|
1460
|
-
* 線の端点と結合部はいずれも丸め(`round`)で描画します。
|
|
1461
|
-
* あわせて、このラインレイヤーにクリック時のポップアップを登録します。
|
|
1462
|
-
*
|
|
1463
|
-
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1464
|
-
*/
|
|
1465
|
-
setLineGeometries(map) {
|
|
1466
|
-
map.addLayer({
|
|
1467
|
-
id: "vt-geolonia-simple-style-linestring",
|
|
1468
|
-
type: "line",
|
|
1469
|
-
source: this.sourceName,
|
|
1470
|
-
"source-layer": "g-simplestyle-v1",
|
|
1471
|
-
filter: ["==", "$type", "LineString"],
|
|
1472
|
-
paint: {
|
|
1473
|
-
"line-width": ["number", ["get", "stroke-width"], 2],
|
|
1474
|
-
"line-color": ["string", ["get", "stroke"], backgroundColor2],
|
|
1475
|
-
"line-opacity": ["number", ["get", "stroke-opacity"], 1]
|
|
1476
|
-
},
|
|
1477
|
-
layout: {
|
|
1478
|
-
"line-cap": "round",
|
|
1479
|
-
"line-join": "round"
|
|
1480
|
-
}
|
|
1481
|
-
});
|
|
1482
|
-
this.setPopup(map, "vt-geolonia-simple-style-linestring");
|
|
1483
|
-
}
|
|
1484
|
-
/**
|
|
1485
|
-
* ポイントジオメトリ用のレイヤーを設定します。
|
|
1486
|
-
*
|
|
1487
|
-
* 2 つのレイヤーを追加します。1 つは `marker-symbol` を持たないポイント向けの円レイヤー
|
|
1488
|
-
* (`circle` タイプ)で、半径はフィーチャーの `marker-size`(`small` は 7、`large` は 13、
|
|
1489
|
-
* それ以外は 9)に応じて変化し、色は `marker-color`、外周線は `stroke` 系プロパティを用います。
|
|
1490
|
-
* もう 1 つはすべてのポイント向けのシンボルレイヤー(`symbol` タイプ)で、`marker-symbol` を
|
|
1491
|
-
* アイコン画像として、`title` をラベルとして表示します。ラベルの位置は `marker-size` に応じて調整します。
|
|
1492
|
-
* あわせて、円レイヤーとシンボルレイヤーの両方にクリック時のポップアップを登録します。
|
|
1493
|
-
*
|
|
1494
|
-
* @param map レイヤーを追加する対象の地図インスタンスです。
|
|
1495
|
-
*/
|
|
1496
|
-
setPointGeometries(map) {
|
|
1497
|
-
map.addLayer({
|
|
1498
|
-
id: "vt-circle-simple-style-points",
|
|
1499
|
-
type: "circle",
|
|
1500
|
-
source: this.sourceName,
|
|
1501
|
-
"source-layer": "g-simplestyle-v1",
|
|
1502
|
-
filter: ["all", ["==", "$type", "Point"], ["!has", "marker-symbol"]],
|
|
1503
|
-
paint: {
|
|
1504
|
-
"circle-radius": [
|
|
1505
|
-
"case",
|
|
1506
|
-
["==", "small", ["get", "marker-size"]],
|
|
1507
|
-
7,
|
|
1508
|
-
["==", "large", ["get", "marker-size"]],
|
|
1509
|
-
13,
|
|
1510
|
-
9
|
|
1511
|
-
],
|
|
1512
|
-
"circle-color": ["string", ["get", "marker-color"], backgroundColor2],
|
|
1513
|
-
"circle-opacity": ["number", ["get", "fill-opacity"], 1],
|
|
1514
|
-
"circle-stroke-width": ["number", ["get", "stroke-width"], 1],
|
|
1515
|
-
"circle-stroke-color": ["string", ["get", "stroke"], strokeColor2],
|
|
1516
|
-
"circle-stroke-opacity": ["number", ["get", "stroke-opacity"], 1]
|
|
1517
|
-
}
|
|
1518
|
-
});
|
|
1519
|
-
map.addLayer({
|
|
1520
|
-
id: "vt-geolonia-simple-style-points",
|
|
1521
|
-
type: "symbol",
|
|
1522
|
-
source: this.sourceName,
|
|
1523
|
-
"source-layer": "g-simplestyle-v1",
|
|
1524
|
-
filter: ["==", "$type", "Point"],
|
|
1525
|
-
paint: {
|
|
1526
|
-
"text-color": ["string", ["get", "text-color"], textColor2],
|
|
1527
|
-
"text-halo-color": [
|
|
1528
|
-
"string",
|
|
1529
|
-
["get", "text-halo-color"],
|
|
1530
|
-
textHaloColor2
|
|
1531
|
-
],
|
|
1532
|
-
"text-halo-width": 1
|
|
1533
|
-
},
|
|
1534
|
-
layout: {
|
|
1535
|
-
"icon-image": ["get", "marker-symbol"],
|
|
1536
|
-
"text-field": ["get", "title"],
|
|
1537
|
-
"text-font": ["Noto Sans Regular"],
|
|
1538
|
-
"text-size": 12,
|
|
1539
|
-
"text-anchor": "top",
|
|
1540
|
-
"text-max-width": 12,
|
|
1541
|
-
"text-offset": [
|
|
1542
|
-
"case",
|
|
1543
|
-
["==", "small", ["get", "marker-size"]],
|
|
1544
|
-
["literal", [0, 1]],
|
|
1545
|
-
["==", "large", ["get", "marker-size"]],
|
|
1546
|
-
["literal", [0, 1.6]],
|
|
1547
|
-
["literal", [0, 1.2]]
|
|
1548
|
-
],
|
|
1549
|
-
"text-allow-overlap": false
|
|
1550
|
-
}
|
|
1551
|
-
});
|
|
1552
|
-
this.setPopup(map, "vt-circle-simple-style-points");
|
|
1553
|
-
this.setPopup(map, "vt-geolonia-simple-style-points");
|
|
1554
|
-
}
|
|
1555
|
-
/**
|
|
1556
|
-
* 指定したレイヤーにクリック時のポップアップ表示を設定します。
|
|
1557
|
-
*
|
|
1558
|
-
* 対象レイヤーのフィーチャーがクリックされると、そのフィーチャーの中心座標
|
|
1559
|
-
* (`@turf/center` で算出)にポップアップを表示します。ポップアップの内容は、
|
|
1560
|
-
* フィーチャーの `description` プロパティをサニタイズした HTML です。`description` を
|
|
1561
|
-
* 持たないフィーチャーではポップアップを表示しません。あわせて、`description` を持つ
|
|
1562
|
-
* フィーチャーにマウスが乗ったときはカーソルをポインターに変更し、離れたときに元へ戻します。
|
|
1563
|
-
*
|
|
1564
|
-
* @param map イベントを登録する対象の地図インスタンスです。
|
|
1565
|
-
* @param source ポップアップを設定する対象のレイヤー ID です。
|
|
1566
|
-
* @returns イベントリスナーの登録が完了すると解決する Promise です。
|
|
1567
|
-
*/
|
|
1568
|
-
async setPopup(map, source) {
|
|
1569
|
-
map.on("click", source, async (e) => {
|
|
1570
|
-
if (!e.features?.[0]) return;
|
|
1571
|
-
const center = (0, import_center2.default)(e.features[0]).geometry.coordinates;
|
|
1572
|
-
const description = e.features[0].properties?.description;
|
|
1573
|
-
if (description) {
|
|
1574
|
-
const sanitizedDescription = await sanitizeDescription(description);
|
|
1575
|
-
new import_maplibre_gl4.default.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
map.on("mouseenter", source, (e) => {
|
|
1579
|
-
if (e.features?.[0]?.properties?.description) {
|
|
1580
|
-
map.getCanvas().style.cursor = "pointer";
|
|
1581
|
-
}
|
|
1582
|
-
});
|
|
1583
|
-
map.on("mouseleave", source, () => {
|
|
1584
|
-
map.getCanvas().style.cursor = "";
|
|
1585
|
-
});
|
|
1586
|
-
}
|
|
1587
|
-
};
|
|
1588
|
-
var simplestyle_vector_default = SimpleStyleVector;
|
|
1589
|
-
|
|
1590
|
-
// src/lib/legacy-options.ts
|
|
1591
|
-
var CONTROL_POSITIONS = [
|
|
1592
|
-
"top-right",
|
|
1593
|
-
"bottom-right",
|
|
1594
|
-
"bottom-left",
|
|
1595
|
-
"top-left"
|
|
1596
|
-
];
|
|
1597
|
-
function toControlAttr(value) {
|
|
1598
|
-
const v = value.toLowerCase();
|
|
1599
|
-
if (CONTROL_POSITIONS.includes(v)) {
|
|
1600
|
-
return v;
|
|
1601
|
-
}
|
|
1602
|
-
return v === "on";
|
|
1603
|
-
}
|
|
1604
|
-
function isCssSelector(value) {
|
|
1605
|
-
if (/^https?:\/\//.test(value) || /^\.?\.?\//.test(value)) {
|
|
1606
|
-
return null;
|
|
1607
|
-
}
|
|
1608
|
-
try {
|
|
1609
|
-
return document.querySelector(value);
|
|
1610
|
-
} catch {
|
|
1611
|
-
return null;
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
function resolveGeojson(value) {
|
|
1615
|
-
const el = isCssSelector(value);
|
|
1616
|
-
if (el?.textContent) {
|
|
1617
|
-
return JSON.parse(el.textContent);
|
|
1618
|
-
}
|
|
1619
|
-
return value;
|
|
1620
|
-
}
|
|
1621
|
-
function isDomElement(o) {
|
|
1622
|
-
return typeof HTMLElement !== "undefined" ? o instanceof HTMLElement : !!o && typeof o === "object" && o.nodeType === 1;
|
|
1623
|
-
}
|
|
1624
|
-
function optionsFromContainer(container) {
|
|
1625
|
-
const ds = container.dataset;
|
|
1626
|
-
const options = {
|
|
1627
|
-
container,
|
|
1628
|
-
bearing: Number.parseFloat(ds.bearing ?? "") || 0,
|
|
1629
|
-
pitch: Number.parseFloat(ds.pitch ?? "") || 0,
|
|
1630
|
-
zoom: Number.parseFloat(ds.zoom ?? "") || 0,
|
|
1631
|
-
hash: ds.hash === "on",
|
|
1632
|
-
marker: (ds.marker ?? "on") === "on",
|
|
1633
|
-
markerColor: ds.markerColor ?? "#E4402F",
|
|
1634
|
-
openPopup: ds.openPopup === "on",
|
|
1635
|
-
loader: ds.loader !== "off",
|
|
1636
|
-
gestureHandling: ds.gestureHandling !== "off",
|
|
1637
|
-
navigationControl: toControlAttr(ds.navigationControl ?? "on"),
|
|
1638
|
-
geolocateControl: toControlAttr(ds.geolocateControl ?? "off"),
|
|
1639
|
-
fullscreenControl: toControlAttr(ds.fullscreenControl ?? "off"),
|
|
1640
|
-
scaleControl: toControlAttr(ds.scaleControl ?? "off"),
|
|
1641
|
-
geoloniaControl: toControlAttr(ds.geoloniaControl ?? "on"),
|
|
1642
|
-
cluster: (ds.cluster ?? "on") === "on",
|
|
1643
|
-
clusterColor: ds.clusterColor ?? "#ff0000",
|
|
1644
|
-
"3d": ds["3d"] === "on"
|
|
1645
|
-
};
|
|
1646
|
-
if (ds.style) options.style = ds.style;
|
|
1647
|
-
if (ds.lang !== void 0) {
|
|
1648
|
-
options.lang = ds.lang;
|
|
1649
|
-
}
|
|
1650
|
-
if (ds.key) options.apiKey = ds.key;
|
|
1651
|
-
if (ds.stage) options.stage = ds.stage;
|
|
1652
|
-
const hasLat = ds.lat !== void 0 && ds.lat !== "";
|
|
1653
|
-
const hasLng = ds.lng !== void 0 && ds.lng !== "";
|
|
1654
|
-
if (hasLat && hasLng) {
|
|
1655
|
-
options.center = [
|
|
1656
|
-
Number.parseFloat(ds.lng),
|
|
1657
|
-
Number.parseFloat(ds.lat)
|
|
1658
|
-
];
|
|
1659
|
-
}
|
|
1660
|
-
if (ds.customMarker) options.customMarker = ds.customMarker;
|
|
1661
|
-
if (ds.customMarkerOffset) {
|
|
1662
|
-
const [x, y] = ds.customMarkerOffset.split(",").map((n) => Number(n.trim()));
|
|
1663
|
-
options.customMarkerOffset = [x || 0, y || 0];
|
|
1664
|
-
}
|
|
1665
|
-
if (ds.geojson) options.geojson = resolveGeojson(ds.geojson);
|
|
1666
|
-
if (ds.simpleVector) options.simpleVector = ds.simpleVector;
|
|
1667
|
-
if (ds.minZoom !== void 0 && ds.minZoom !== "" && (Number(ds.minZoom) === 0 || Number(ds.minZoom))) {
|
|
1668
|
-
options.minZoom = Number(ds.minZoom);
|
|
1669
|
-
}
|
|
1670
|
-
if (ds.maxZoom !== void 0 && ds.maxZoom !== "" && (Number(ds.maxZoom) === 0 || Number(ds.maxZoom))) {
|
|
1671
|
-
options.maxZoom = Number(ds.maxZoom);
|
|
1672
|
-
}
|
|
1673
|
-
return options;
|
|
1674
|
-
}
|
|
1675
|
-
function normalizeConstructorArg(arg) {
|
|
1676
|
-
if (typeof arg === "string") {
|
|
1677
|
-
const el = document.querySelector(arg) || document.getElementById(arg);
|
|
1678
|
-
if (!el) {
|
|
1679
|
-
throw new Error(
|
|
1680
|
-
`[Geolonia] No HTML elements found matching \`${arg}\`. Please ensure the map container element exists.`
|
|
1681
|
-
);
|
|
1682
|
-
}
|
|
1683
|
-
return optionsFromContainer(el);
|
|
1684
|
-
}
|
|
1685
|
-
if (isDomElement(arg)) {
|
|
1686
|
-
return optionsFromContainer(arg);
|
|
1687
|
-
}
|
|
1688
|
-
return arg;
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
// src/lib/geolonia-map.ts
|
|
1692
|
-
var pmtilesRegistered = false;
|
|
1693
|
-
function ensurePMTiles() {
|
|
1694
|
-
if (pmtilesRegistered) return;
|
|
1695
|
-
pmtilesRegistered = true;
|
|
1696
|
-
const protocol = new import_pmtiles.Protocol();
|
|
1697
|
-
import_maplibre_gl5.default.addProtocol("pmtiles", protocol.tile);
|
|
1698
|
-
}
|
|
1699
|
-
var GeoloniaMap = class extends import_maplibre_gl5.default.Map {
|
|
1700
|
-
/**
|
|
1701
|
-
* 地図を生成します。
|
|
1702
|
-
*
|
|
1703
|
-
* `apiKey` や `stage` が指定されていればキーリングに設定し、スタイル
|
|
1704
|
-
* (既定は `"geolonia/basic-v2"`)を実際の style.json の URL に解決してから
|
|
1705
|
-
* MapLibre GL JS の `Map` を初期化します。あわせて Geolonia のロゴ、出典表示、
|
|
1706
|
-
* ナビゲーションなどのコントロールを追加し、読み込み完了後にはローディング表示の
|
|
1707
|
-
* 除去、デフォルトマーカーの配置、ジェスチャ操作やスタイル拡張の適用を行います。
|
|
1708
|
-
*
|
|
1709
|
-
* `arg` にコンテナを直接指定する後方互換の形式では、そのコンテナの `data-*`
|
|
1710
|
-
* 属性から設定を読み込みます。指定したコンテナに既に地図が生成済みの場合は、
|
|
1711
|
-
* 新規生成せず既存のインスタンスを返します。
|
|
1712
|
-
*
|
|
1713
|
-
* @param arg 地図の設定です。{@link GeoloniaMapOptions} オブジェクトのほか、
|
|
1714
|
-
* 後方互換としてコンテナを指す CSS セレクタ文字列や `HTMLElement` も指定できます。
|
|
1715
|
-
* @throws コンテナ要素が見つからない場合に `Error` を投げます。
|
|
1716
|
-
* @throws Geolonia のスタイルを API キーなしで使おうとした場合に `Error` を投げます。
|
|
1717
|
-
* @throws MapLibre GL JS の `Map` の初期化に失敗した場合、コンテナにエラー表示を
|
|
1718
|
-
* 行ったうえで、その例外を再スローします。
|
|
1719
|
-
*
|
|
1720
|
-
* @example
|
|
1721
|
-
* ```typescript
|
|
1722
|
-
* const map = new GeoloniaMap({
|
|
1723
|
-
* container: "#map",
|
|
1724
|
-
* apiKey: "YOUR-API-KEY",
|
|
1725
|
-
* center: [139.7671, 35.6812],
|
|
1726
|
-
* zoom: 14,
|
|
1727
|
-
* });
|
|
1728
|
-
* ```
|
|
1729
|
-
*/
|
|
1730
|
-
// biome-ignore lint/correctness/noUnreachableSuper: intentional singleton pattern - returns existing map instance before super()
|
|
1731
|
-
constructor(arg) {
|
|
1732
|
-
const options = normalizeConstructorArg(arg);
|
|
1733
|
-
ensurePMTiles();
|
|
1734
|
-
if (options.apiKey) {
|
|
1735
|
-
keyring.setApiKey(options.apiKey);
|
|
1736
|
-
}
|
|
1737
|
-
if (options.stage) {
|
|
1738
|
-
keyring.setStage(options.stage);
|
|
1739
|
-
}
|
|
1740
|
-
const lang = options.lang === "auto" || !options.lang ? getLang() : options.lang;
|
|
1741
|
-
const styleName = options.style || "geolonia/basic-v2";
|
|
1742
|
-
keyring.isGeoloniaStyle = keyring.isGeoloniaStyleCheck(styleName);
|
|
1743
|
-
const resolvedStyle = getStyle(styleName, {
|
|
1744
|
-
lang,
|
|
1745
|
-
apiKey: options.apiKey || keyring.apiKey
|
|
1746
|
-
});
|
|
1747
|
-
const container = typeof options.container === "string" ? document.querySelector(options.container) || document.getElementById(options.container) : options.container;
|
|
1748
|
-
if (!container) {
|
|
1749
|
-
throw new Error(
|
|
1750
|
-
`[Geolonia] No HTML elements found. Please ensure the map container element exists.`
|
|
1751
|
-
);
|
|
1752
|
-
}
|
|
1753
|
-
if (container.geoloniaMap) {
|
|
1754
|
-
return container.geoloniaMap;
|
|
1755
|
-
}
|
|
1756
|
-
const apiKey = options.apiKey || keyring.apiKey;
|
|
1757
|
-
const stage = options.stage || keyring.stage;
|
|
1758
|
-
const apiUrl = `https://api.geolonia.com/${stage}`;
|
|
1759
|
-
const sessionId2 = getSessionId(40);
|
|
1760
|
-
const sourcesUrl = new URL(`${apiUrl}/sources`);
|
|
1761
|
-
sourcesUrl.searchParams.set("key", apiKey);
|
|
1762
|
-
sourcesUrl.searchParams.set("sessionId", sessionId2);
|
|
1763
|
-
const userTransformRequest = options.transformRequest;
|
|
1764
|
-
const transformRequest = (url, resourceType) => {
|
|
1765
|
-
if (resourceType === "Source" && url.startsWith("https://api.geolonia.com")) {
|
|
1766
|
-
return { url: sourcesUrl.toString() };
|
|
1767
|
-
}
|
|
1768
|
-
let transformedUrl = url;
|
|
1769
|
-
if (url.startsWith("geolonia://")) {
|
|
1770
|
-
const tilesMatch = url.match(
|
|
1771
|
-
/^geolonia:\/\/tiles\/(?<username>.+)\/(?<customtileId>.+)/
|
|
1772
|
-
);
|
|
1773
|
-
if (tilesMatch?.groups) {
|
|
1774
|
-
transformedUrl = `https://tileserver.geolonia.com/customtiles/${tilesMatch.groups.customtileId}/tiles.json`;
|
|
1775
|
-
}
|
|
1776
|
-
}
|
|
1777
|
-
const transformedUrlObj = new URL(transformedUrl);
|
|
1778
|
-
const geoloniaTilesHost = isGeoloniaTilesHost(transformedUrlObj);
|
|
1779
|
-
if (resourceType === "Source" && geoloniaTilesHost) {
|
|
1780
|
-
if (stage === "dev" && transformedUrlObj.hostname === "tileserver.geolonia.com") {
|
|
1781
|
-
transformedUrlObj.hostname = "tileserver-dev.geolonia.com";
|
|
1782
|
-
}
|
|
1783
|
-
transformedUrlObj.searchParams.set("sessionId", sessionId2);
|
|
1784
|
-
transformedUrlObj.searchParams.set("key", apiKey);
|
|
1785
|
-
return { url: transformedUrlObj.toString() };
|
|
1786
|
-
}
|
|
1787
|
-
if ((resourceType === "SpriteJSON" || resourceType === "SpriteImage") && transformedUrl.match(
|
|
1788
|
-
/^https:\/\/api\.geolonia\.com\/(dev|v1)\/sprites\//
|
|
1789
|
-
)) {
|
|
1790
|
-
const pathParts = transformedUrlObj.pathname.split("/");
|
|
1791
|
-
pathParts[1] = stage;
|
|
1792
|
-
transformedUrlObj.pathname = pathParts.join("/");
|
|
1793
|
-
transformedUrlObj.searchParams.set("key", apiKey);
|
|
1794
|
-
return { url: transformedUrlObj.toString() };
|
|
1795
|
-
}
|
|
1796
|
-
if (typeof userTransformRequest === "function") {
|
|
1797
|
-
return userTransformRequest(transformedUrl, resourceType);
|
|
1798
|
-
}
|
|
1799
|
-
return void 0;
|
|
1800
|
-
};
|
|
1801
|
-
let loading;
|
|
1802
|
-
const showLoader = options.loader !== false;
|
|
1803
|
-
if (showLoader) {
|
|
1804
|
-
loading = document.createElement("div");
|
|
1805
|
-
loading.className = "loading-geolonia-map";
|
|
1806
|
-
loading.innerHTML = `<div class="lds-grid"><div></div><div></div><div></div>
|
|
1807
|
-
<div></div><div></div><div></div><div></div><div></div><div></div></div>`;
|
|
1808
|
-
container.appendChild(loading);
|
|
1809
|
-
}
|
|
1810
|
-
const mapOptions = {
|
|
1811
|
-
...options,
|
|
1812
|
-
container,
|
|
1813
|
-
style: resolvedStyle,
|
|
1814
|
-
hash: options.hash ?? false,
|
|
1815
|
-
localIdeographFontFamily: options.localIdeographFontFamily ?? "sans-serif",
|
|
1816
|
-
attributionControl: false,
|
|
1817
|
-
transformRequest
|
|
1818
|
-
};
|
|
1819
|
-
for (const key of [
|
|
1820
|
-
"apiKey",
|
|
1821
|
-
"stage",
|
|
1822
|
-
"lang",
|
|
1823
|
-
"marker",
|
|
1824
|
-
"markerColor",
|
|
1825
|
-
"openPopup",
|
|
1826
|
-
"customMarker",
|
|
1827
|
-
"customMarkerOffset",
|
|
1828
|
-
"loader",
|
|
1829
|
-
"gestureHandling",
|
|
1830
|
-
"navigationControl",
|
|
1831
|
-
"geolocateControl",
|
|
1832
|
-
"fullscreenControl",
|
|
1833
|
-
"scaleControl",
|
|
1834
|
-
"geoloniaControl",
|
|
1835
|
-
"geojson",
|
|
1836
|
-
"cluster",
|
|
1837
|
-
"clusterColor",
|
|
1838
|
-
"simpleVector",
|
|
1839
|
-
"3d"
|
|
1840
|
-
]) {
|
|
1841
|
-
delete mapOptions[key];
|
|
1842
|
-
}
|
|
1843
|
-
try {
|
|
1844
|
-
super(mapOptions);
|
|
1845
|
-
} catch (error) {
|
|
1846
|
-
handleErrorMode(container);
|
|
1847
|
-
throw error;
|
|
1848
|
-
}
|
|
1849
|
-
this.geoloniaSourcesUrl = sourcesUrl;
|
|
1850
|
-
this.__styleExtensionLoadRequired = true;
|
|
1851
|
-
const geoloniaCtrl = parseControlOption(options.geoloniaControl ?? true);
|
|
1852
|
-
this.addControl(
|
|
1853
|
-
new GeoloniaControl(),
|
|
1854
|
-
geoloniaCtrl.position
|
|
1855
|
-
);
|
|
1856
|
-
this.addControl(new attribution_default(), "bottom-right");
|
|
1857
|
-
const fullscreen = parseControlOption(options.fullscreenControl ?? false);
|
|
1858
|
-
if (fullscreen.enabled) {
|
|
1859
|
-
this.addControl(
|
|
1860
|
-
new import_maplibre_gl5.default.FullscreenControl(),
|
|
1861
|
-
fullscreen.position
|
|
1862
|
-
);
|
|
1863
|
-
}
|
|
1864
|
-
const nav = parseControlOption(options.navigationControl ?? true);
|
|
1865
|
-
if (nav.enabled) {
|
|
1866
|
-
this.addControl(
|
|
1867
|
-
new import_maplibre_gl5.default.NavigationControl(),
|
|
1868
|
-
nav.position
|
|
1869
|
-
);
|
|
1870
|
-
}
|
|
1871
|
-
const geolocate = parseControlOption(options.geolocateControl ?? false);
|
|
1872
|
-
if (geolocate.enabled) {
|
|
1873
|
-
this.addControl(
|
|
1874
|
-
new import_maplibre_gl5.default.GeolocateControl({}),
|
|
1875
|
-
geolocate.position
|
|
1876
|
-
);
|
|
1877
|
-
}
|
|
1878
|
-
const scale = parseControlOption(options.scaleControl ?? false);
|
|
1879
|
-
if (scale.enabled) {
|
|
1880
|
-
this.addControl(
|
|
1881
|
-
new import_maplibre_gl5.default.ScaleControl({}),
|
|
1882
|
-
scale.position
|
|
1883
|
-
);
|
|
1884
|
-
}
|
|
1885
|
-
this.on("load", (event) => {
|
|
1886
|
-
const map = event.target;
|
|
1887
|
-
if (loading) {
|
|
1888
|
-
try {
|
|
1889
|
-
container.removeChild(loading);
|
|
1890
|
-
} catch {
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
if (options.gestureHandling !== false) {
|
|
1894
|
-
import("@geolonia/maplibre-gesture-handling").then(({ default: GestureHandling }) => {
|
|
1895
|
-
const body = document.body;
|
|
1896
|
-
const html = document.documentElement;
|
|
1897
|
-
const isScrollable = body.scrollHeight > body.clientHeight || html.scrollHeight > html.clientHeight;
|
|
1898
|
-
if (isScrollable) {
|
|
1899
|
-
map.addControl(new GestureHandling({ lang }));
|
|
1900
|
-
}
|
|
1901
|
-
}).catch(() => {
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
if (options.marker && options.center) {
|
|
1905
|
-
const c = options.center;
|
|
1906
|
-
const center = Array.isArray(c) ? [c[0], c[1]] : "lng" in c ? [c.lng, c.lat] : [c.lon, c.lat];
|
|
1907
|
-
let marker;
|
|
1908
|
-
if (options.customMarker) {
|
|
1909
|
-
const customEl = document.querySelector(
|
|
1910
|
-
options.customMarker
|
|
1911
|
-
);
|
|
1912
|
-
if (customEl) {
|
|
1913
|
-
customEl.style.display = "block";
|
|
1914
|
-
marker = new GeoloniaMarker({
|
|
1915
|
-
element: customEl,
|
|
1916
|
-
offset: options.customMarkerOffset || [0, 0]
|
|
1917
|
-
}).setLngLat(center).addTo(map);
|
|
1918
|
-
} else {
|
|
1919
|
-
marker = new GeoloniaMarker({ color: options.markerColor }).setLngLat(center).addTo(map);
|
|
1920
|
-
}
|
|
1921
|
-
} else {
|
|
1922
|
-
marker = new GeoloniaMarker({ color: options.markerColor }).setLngLat(center).addTo(map);
|
|
1923
|
-
}
|
|
1924
|
-
const content = container.dataset?.popupContent;
|
|
1925
|
-
if (content) {
|
|
1926
|
-
const popup = new import_maplibre_gl5.default.Popup({ offset: [0, -25] }).setHTML(
|
|
1927
|
-
content
|
|
1928
|
-
);
|
|
1929
|
-
marker.setPopup(popup);
|
|
1930
|
-
if (options.openPopup) {
|
|
1931
|
-
marker.togglePopup();
|
|
1932
|
-
}
|
|
1933
|
-
} else if (options.openPopup) {
|
|
1934
|
-
}
|
|
1935
|
-
marker.getElement().classList.add("geolonia-clickable-marker");
|
|
1936
|
-
}
|
|
1937
|
-
});
|
|
1938
|
-
this.on("styledata", async () => {
|
|
1939
|
-
if (!this.__styleExtensionLoadRequired) {
|
|
1940
|
-
return;
|
|
1941
|
-
}
|
|
1942
|
-
this.__styleExtensionLoadRequired = false;
|
|
1943
|
-
if (options.simpleVector) {
|
|
1944
|
-
const url = parseSimpleVector(options.simpleVector);
|
|
1945
|
-
new simplestyle_vector_default(url).addTo(this);
|
|
1946
|
-
}
|
|
1947
|
-
if (options.geojson) {
|
|
1948
|
-
const ss = new SimpleStyle(options.geojson, {
|
|
1949
|
-
cluster: options.cluster !== false,
|
|
1950
|
-
clusterColor: options.clusterColor || "#ff0000"
|
|
1951
|
-
});
|
|
1952
|
-
ss.addTo(this);
|
|
1953
|
-
if (!options.center) {
|
|
1954
|
-
ss.fitBounds();
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
if (options["3d"] === true) {
|
|
1958
|
-
const style = this.getStyle();
|
|
1959
|
-
if (style?.layers) {
|
|
1960
|
-
for (const layer of style.layers) {
|
|
1961
|
-
const metadata = layer.metadata;
|
|
1962
|
-
if (metadata?.["visible-on-3d"]) {
|
|
1963
|
-
this.setLayoutProperty(layer.id, "visibility", "visible");
|
|
1964
|
-
}
|
|
1965
|
-
if (metadata?.["hide-on-3d"]) {
|
|
1966
|
-
this.setLayoutProperty(layer.id, "visibility", "none");
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
});
|
|
1972
|
-
this.on("error", async (error) => {
|
|
1973
|
-
if (error.error && error.error.status === 402) {
|
|
1974
|
-
handleRestrictedMode(this);
|
|
1975
|
-
}
|
|
1976
|
-
});
|
|
1977
|
-
container.geoloniaMap = this;
|
|
1978
|
-
return this;
|
|
1979
|
-
}
|
|
1980
|
-
/**
|
|
1981
|
-
* 地図のスタイルを差し替えます。
|
|
1982
|
-
*
|
|
1983
|
-
* `style` が文字列の場合は、Geolonia のスタイル論理名(`"geolonia/basic-v2"`
|
|
1984
|
-
* など)、style.json の URL、相対パスのいずれかとして解釈し、実際の URL に
|
|
1985
|
-
* 解決してから適用します。解決の際の言語はブラウザ言語に従い、API キーは
|
|
1986
|
-
* キーリングに設定済みの値を使います。`StyleSpecification` オブジェクトを
|
|
1987
|
-
* 直接渡した場合はそのまま適用します。
|
|
1988
|
-
*
|
|
1989
|
-
* @param style 新しいスタイルです。スタイル論理名や URL などの文字列、または
|
|
1990
|
-
* `StyleSpecification` オブジェクトを指定します。
|
|
1991
|
-
* @param options MapLibre GL JS に渡すスタイル差し替えオプションです。
|
|
1992
|
-
* 既定は空のオブジェクトです。
|
|
1993
|
-
* @returns メソッドチェーンのために自身を返します。
|
|
1994
|
-
* @throws Geolonia のスタイルを API キーなしで使おうとした場合に `Error` を投げます。
|
|
1995
|
-
*
|
|
1996
|
-
* @example
|
|
1997
|
-
* ```typescript
|
|
1998
|
-
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
1999
|
-
* map.setStyle("geolonia/gsi");
|
|
2000
|
-
* ```
|
|
2001
|
-
*/
|
|
2002
|
-
setStyle(style, options = {}) {
|
|
2003
|
-
if (style !== null && typeof style === "string") {
|
|
2004
|
-
style = getStyle(style, { lang: getLang(), apiKey: keyring.apiKey });
|
|
2005
|
-
}
|
|
2006
|
-
this.__styleExtensionLoadRequired = true;
|
|
2007
|
-
super.setStyle.call(this, style, options);
|
|
2008
|
-
return this;
|
|
2009
|
-
}
|
|
2010
|
-
/**
|
|
2011
|
-
* 地図を破棄し、関連するリソースやイベントリスナーを解放します。
|
|
2012
|
-
*
|
|
2013
|
-
* MapLibre GL JS の破棄処理に加えて、コンテナ要素に保持している地図インスタンスへの
|
|
2014
|
-
* 参照(`geoloniaMap`)も削除します。これにより、同じコンテナで再度
|
|
2015
|
-
* {@link GeoloniaMap} を生成した際に、破棄済みのインスタンスが返されることを防ぎます。
|
|
2016
|
-
*
|
|
2017
|
-
* @example
|
|
2018
|
-
* ```typescript
|
|
2019
|
-
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
2020
|
-
* // 不要になったら破棄します
|
|
2021
|
-
* map.remove();
|
|
2022
|
-
* ```
|
|
2023
|
-
*/
|
|
2024
|
-
remove() {
|
|
2025
|
-
const container = this.getContainer();
|
|
2026
|
-
super.remove.call(this);
|
|
2027
|
-
delete container.geoloniaMap;
|
|
2028
|
-
}
|
|
2029
|
-
/**
|
|
2030
|
-
* 画像を読み込みます。
|
|
2031
|
-
*
|
|
2032
|
-
* `callback` を渡した場合は後方互換のコールバック形式で結果を受け取り、戻り値は
|
|
2033
|
-
* `undefined` になります。`callback` を省略した場合は `Promise` を返します。
|
|
2034
|
-
*
|
|
2035
|
-
* @param url 読み込む画像の URL です。
|
|
2036
|
-
* @param callback 省略可能です。指定した場合はコールバック形式で結果を受け取ります。
|
|
2037
|
-
* @returns `callback` を省略した場合は、読み込んだ画像を含むレスポンスに解決される
|
|
2038
|
-
* `Promise` を返します。`callback` を指定した場合は `undefined` を返します。
|
|
2039
|
-
*
|
|
2040
|
-
* @example
|
|
2041
|
-
* ```typescript
|
|
2042
|
-
* const map = new GeoloniaMap({ container: "#map", apiKey: "YOUR-API-KEY" });
|
|
2043
|
-
* map.on("load", async () => {
|
|
2044
|
-
* const image = await map.loadImage("https://example.com/marker.png");
|
|
2045
|
-
* map.addImage("custom-marker", image.data);
|
|
2046
|
-
* });
|
|
2047
|
-
* ```
|
|
2048
|
-
*/
|
|
2049
|
-
loadImage(url, callback) {
|
|
2050
|
-
const promise = super.loadImage(url);
|
|
2051
|
-
if (callback) {
|
|
2052
|
-
loadImageCompatibility(promise, callback);
|
|
2053
|
-
} else {
|
|
2054
|
-
return promise;
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
};
|
|
2058
|
-
|
|
2059
|
-
// src/version.ts
|
|
2060
|
-
var VERSION = "0.5.1";
|
|
2061
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2062
|
-
0 && (module.exports = {
|
|
2063
|
-
CustomAttributionControl,
|
|
2064
|
-
DEFAULT_STAGE,
|
|
2065
|
-
GeoloniaControl,
|
|
2066
|
-
GeoloniaMap,
|
|
2067
|
-
GeoloniaMarker,
|
|
2068
|
-
SimpleStyle,
|
|
2069
|
-
SimpleStyleVector,
|
|
2070
|
-
coreVersion,
|
|
2071
|
-
getLang,
|
|
2072
|
-
getStyle,
|
|
2073
|
-
isGeoloniaTilesHost,
|
|
2074
|
-
keyring
|
|
2075
|
-
});
|