mapicgc-gl-js 1.0.7 → 1.0.8
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 +2 -4
- package/dist/array-utils-flat-DeB-J5jn.mjs +1523 -0
- package/dist/assets/maplibre-gl-worker-HMCkgiD4.js +10 -0
- package/dist/buffer-transform-CH0poqqn.mjs +941 -0
- package/dist/expression-CtaQKvTZ.mjs +3444 -0
- package/dist/get-attribute-from-layouts-DqvACIaG.mjs +936 -0
- package/dist/{html2canvas-DhrjCa5K-6_3CwS_m.mjs → html2canvas-Cgp0Hyhk-HIw4n-A9.mjs} +105 -109
- package/dist/{index.es-D_FsJY9H-CO3QIBGM.mjs → index.es-lgdlL0gw-Bl7I-U5B.mjs} +176 -176
- package/dist/mapicgc-gl-js.css +1 -1
- package/dist/mapicgc-gl.css +199 -0
- package/dist/mapicgc-gl.js +5079 -856
- package/dist/mapicgc-gl.mjs +85573 -61841
- package/dist/purify.es-DNpVkA56-DxzGf9c8.mjs +769 -0
- package/dist/{chunk-efA98nb6-Dfm7IivL.mjs → rolldown-runtime-3b4jIN3o-CmciV3xi.mjs} +2 -2
- package/dist/{typeof-CTd55yxz-BxqQpTq1.mjs → typeof-C3azmBUr-9LkZMuan.mjs} +1 -1
- package/dist/webgl-Cep-x0-T.mjs +784 -0
- package/package.json +20 -15
- package/public/mapicgc-gl.css +199 -0
- package/src/controls/ApiTerritorialControl.js +222 -0
- package/src/index.js +18 -1
- package/src/map/Map.js +245 -144
- package/src/mapicgc-config.json +1303 -8
- package/src/plugins/CompareMaps.js +2 -1
- package/src/territorial/ApiTerritorialControl.js +1 -0
- package/src/territorial/mostraPanellInfo.js +250 -0
- package/src/territorial/searchApiTerritorialICGC.js +250 -0
- package/test/exemples/addApiTerritorialICGC.html +113 -0
- package/test/exemples/addBasemap.html +4 -4
- package/test/exemples/addCompare.html +7 -6
- package/test/exemples/addControl.html +12 -6
- package/test/exemples/addFeatureQuery.html +5 -4
- package/test/exemples/addGeocoderICGC.html +5 -4
- package/test/exemples/addICGCTerrain.html +5 -4
- package/test/exemples/addICGCTerrainCustomStyle.html +5 -4
- package/test/exemples/addImageLayerICGC.html +5 -4
- package/test/exemples/addLayerGeojson.html +5 -4
- package/test/exemples/addLayerTree.html +5 -4
- package/test/exemples/addLogo.html +5 -3
- package/test/exemples/addMapStyle.html +5 -4
- package/test/exemples/addMarker.html +5 -4
- package/test/exemples/addMouseCoordinateControl.html +5 -4
- package/test/exemples/addReliefStyle.html +6 -5
- package/test/exemples/addVectorLayerICGC.html +5 -4
- package/test/exemples/advancedExemple.html +5 -4
- package/test/exemples/fetchData.html +6 -5
- package/test/exemples/fetchDataAndMenu.html +5 -4
- package/test/exemples/styleOrto3D.html +8 -4
- package/test/vitest/ApiTerritorialControl.test.js +76 -0
- package/vite.config.mjs +16 -5
- package/dist/purify.es-DVGU85zV-CJOZ7ABI.mjs +0 -549
- package/dist/webgl-device-B1jTrfKA.mjs +0 -6880
- package/dist/webgl-device-D8jkwRzb.mjs +0 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapicgc-gl-js",
|
|
3
3
|
"homepage": "https://openicgc.github.io/mapicgc-doc/",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"description": "mapicgc-gl-js library",
|
|
6
6
|
"author": "Institut Cartogràfic i Geològic de Catalunya",
|
|
7
7
|
"license": "BSD-3-Clause",
|
|
@@ -33,44 +33,49 @@
|
|
|
33
33
|
"require": "./dist/mapicgc-gl.mjs"
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
+
"overrides": {
|
|
37
|
+
"maplibre-gl": "^6.10.0"
|
|
38
|
+
},
|
|
36
39
|
"scripts": {
|
|
37
40
|
"dev": "vite",
|
|
38
41
|
"build-all": "npm-run-all build && node nodeDeploy.js",
|
|
39
42
|
"build": "vite build",
|
|
40
43
|
"preview": "vite preview",
|
|
41
|
-
"publish": "npm publish --access public",
|
|
44
|
+
"publish": "npm publish --access public --tag latest",
|
|
42
45
|
"setConfig": "node nodeSetConfig.js",
|
|
46
|
+
"publishBeta": "npm publish --tag beta --access public",
|
|
43
47
|
"test": "vitest"
|
|
44
48
|
},
|
|
45
49
|
"devDependencies": {
|
|
46
|
-
"@babel/core": "^7.29.
|
|
50
|
+
"@babel/core": "^7.29.7",
|
|
47
51
|
"@babel/preset-env": "^7.29.2",
|
|
48
|
-
"@rollup/plugin-babel": "^7.
|
|
49
|
-
"axios": "^1.
|
|
52
|
+
"@rollup/plugin-babel": "^7.1.0",
|
|
53
|
+
"axios": "^1.20.0",
|
|
50
54
|
"dotenv": "^17.4.2",
|
|
51
|
-
"jest": "30.
|
|
55
|
+
"jest": "30.5.1",
|
|
52
56
|
"jsdoc": "^4.0.5",
|
|
53
|
-
"jsdom": "^
|
|
57
|
+
"jsdom": "^30.1.0",
|
|
54
58
|
"npm-run-all": "^4.1.5",
|
|
55
59
|
"package-json-versionify": "^1.0.4",
|
|
56
60
|
"path": "^0.12.7",
|
|
57
61
|
"rollup-plugin-polyfill": "^4.2.0",
|
|
58
62
|
"ssh2-sftp-client": "^12.1.1",
|
|
59
|
-
"vite": "^8.0
|
|
63
|
+
"vite": "^8.3.0",
|
|
60
64
|
"vite-plugin-node-polyfills": "^0.2.0",
|
|
61
|
-
"vitest": "^
|
|
65
|
+
"vitest": "^5.0.1",
|
|
62
66
|
"xml2js": "^0.6.2"
|
|
63
67
|
},
|
|
64
68
|
"dependencies": {
|
|
65
|
-
"@deck.gl/core": "^9.
|
|
66
|
-
"@deck.gl/geo-layers": "^9.3.
|
|
67
|
-
"@deck.gl/
|
|
68
|
-
"@loaders.gl/3d-tiles": "
|
|
69
|
+
"@deck.gl/core": "^9.4.0",
|
|
70
|
+
"@deck.gl/geo-layers": "^9.3.7",
|
|
71
|
+
"@deck.gl/maplibre": "^9.4.0",
|
|
72
|
+
"@loaders.gl/3d-tiles": "^4.1.4",
|
|
69
73
|
"@maplibre/maplibre-gl-compare": "^0.5.0",
|
|
70
74
|
"@maplibre/maplibre-gl-geocoder": "^1.9.4",
|
|
71
|
-
"@watergis/maplibre-gl-export": "^
|
|
75
|
+
"@watergis/maplibre-gl-export": "^5.0.0",
|
|
72
76
|
"flatgeobuf": "^4.4.0",
|
|
73
|
-
"maplibre-gl": "^
|
|
77
|
+
"maplibre-gl": "^6.10.0",
|
|
78
|
+
"proj4": "^2.20.9",
|
|
74
79
|
"utm-latlng": "^1.0.8"
|
|
75
80
|
}
|
|
76
81
|
}
|
package/public/mapicgc-gl.css
CHANGED
|
@@ -234,6 +234,205 @@
|
|
|
234
234
|
.maplibregl-ctrl button.maplibregl-ctrl-terrain-enabled .maplibregl-ctrl-icon {
|
|
235
235
|
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' fill='%2333b5e5' viewBox='0 0 22 22'%3E%3Cpath d='m1.754 13.406 4.453-4.851 3.09 3.09 3.281 3.277.969-.969-3.309-3.312 3.844-4.121 6.148 6.886h1.082v-.855l-7.207-8.07-4.84 5.187L6.169 6.57l-5.48 5.965v.871ZM.688 16.844h20.625v1.375H.688Zm0 0'/%3E%3C/svg%3E");
|
|
236
236
|
}
|
|
237
|
+
.mapicgc-api-territorial-control-button {
|
|
238
|
+
align-items: center;
|
|
239
|
+
background: transparent;
|
|
240
|
+
border: 0;
|
|
241
|
+
box-shadow: none;
|
|
242
|
+
color: inherit;
|
|
243
|
+
display: flex;
|
|
244
|
+
font-size: 0;
|
|
245
|
+
font-weight: 700;
|
|
246
|
+
justify-content: center;
|
|
247
|
+
line-height: 1;
|
|
248
|
+
width: 45px;
|
|
249
|
+
height: 45px;
|
|
250
|
+
padding: 0;
|
|
251
|
+
position: relative;
|
|
252
|
+
transition: transform 0.15s ease;
|
|
253
|
+
}
|
|
254
|
+
.mapicgc-api-territorial-control {
|
|
255
|
+
background: transparent;
|
|
256
|
+
border: 0;
|
|
257
|
+
box-shadow: none;
|
|
258
|
+
}
|
|
259
|
+
.mapicgc-api-territorial-control.maplibregl-ctrl-group:not(:empty) {
|
|
260
|
+
box-shadow: none;
|
|
261
|
+
}
|
|
262
|
+
.mapicgc-api-territorial-control-button svg {
|
|
263
|
+
display: block;
|
|
264
|
+
width: 45px;
|
|
265
|
+
height: 45px;
|
|
266
|
+
}
|
|
267
|
+
.mapicgc-api-territorial-control-icon-image {
|
|
268
|
+
display: block;
|
|
269
|
+
height: 45px;
|
|
270
|
+
object-fit: contain;
|
|
271
|
+
pointer-events: none;
|
|
272
|
+
width: 45px;
|
|
273
|
+
}
|
|
274
|
+
.mapicgc-api-territorial-control-button.is-active {
|
|
275
|
+
background: transparent;
|
|
276
|
+
box-shadow: none;
|
|
277
|
+
}
|
|
278
|
+
.mapicgc-api-territorial-control-button.is-active::after {
|
|
279
|
+
align-items: center;
|
|
280
|
+
background: #3bb273;
|
|
281
|
+
border: 2px solid #ffffff;
|
|
282
|
+
border-radius: 999px;
|
|
283
|
+
color: #ffffff;
|
|
284
|
+
content: "✓";
|
|
285
|
+
display: inline-flex;
|
|
286
|
+
font-size: 12px;
|
|
287
|
+
font-weight: 700;
|
|
288
|
+
height: 18px;
|
|
289
|
+
justify-content: center;
|
|
290
|
+
line-height: 1;
|
|
291
|
+
pointer-events: none;
|
|
292
|
+
position: absolute;
|
|
293
|
+
right: -3px;
|
|
294
|
+
top: -3px;
|
|
295
|
+
width: 18px;
|
|
296
|
+
}
|
|
297
|
+
.mapicgc-api-territorial-control.mapicgc-api-territorial-control-floating {
|
|
298
|
+
margin: 0;
|
|
299
|
+
position: absolute;
|
|
300
|
+
z-index: 4;
|
|
301
|
+
}
|
|
302
|
+
.mapicgc-api-territorial-control-hidden {
|
|
303
|
+
height: 0;
|
|
304
|
+
overflow: hidden;
|
|
305
|
+
pointer-events: none;
|
|
306
|
+
width: 0;
|
|
307
|
+
}
|
|
308
|
+
.mapicgc-api-territorial-panel {
|
|
309
|
+
background: #fffaf4;
|
|
310
|
+
border: 1px solid rgba(211, 124, 29, 0.25);
|
|
311
|
+
border-radius: 14px;
|
|
312
|
+
bottom: 12px;
|
|
313
|
+
box-shadow: 0 18px 48px rgba(34, 17, 6, 0.24);
|
|
314
|
+
color: #2e261d;
|
|
315
|
+
display: flex;
|
|
316
|
+
flex-direction: column;
|
|
317
|
+
max-height: calc(100% - 24px);
|
|
318
|
+
min-height: 260px;
|
|
319
|
+
overflow: hidden;
|
|
320
|
+
position: absolute;
|
|
321
|
+
right: 12px;
|
|
322
|
+
top: 12px;
|
|
323
|
+
width: min(380px, calc(100vw - 24px));
|
|
324
|
+
z-index: 3;
|
|
325
|
+
}
|
|
326
|
+
.mapicgc-api-territorial-panel.is-hidden {
|
|
327
|
+
display: none;
|
|
328
|
+
}
|
|
329
|
+
.mapicgc-api-territorial-panel-header {
|
|
330
|
+
align-items: center;
|
|
331
|
+
background: linear-gradient(180deg, #ff9c2f 0%, #f57c00 100%);
|
|
332
|
+
color: #fff;
|
|
333
|
+
display: flex;
|
|
334
|
+
justify-content: space-between;
|
|
335
|
+
padding: 12px 14px;
|
|
336
|
+
}
|
|
337
|
+
.mapicgc-api-territorial-panel-title-wrap {
|
|
338
|
+
align-items: center;
|
|
339
|
+
display: flex;
|
|
340
|
+
gap: 8px;
|
|
341
|
+
min-width: 0;
|
|
342
|
+
}
|
|
343
|
+
.mapicgc-api-territorial-panel-title-icon {
|
|
344
|
+
font-size: 18px;
|
|
345
|
+
line-height: 1;
|
|
346
|
+
}
|
|
347
|
+
.mapicgc-api-territorial-panel-title {
|
|
348
|
+
font-size: 15px;
|
|
349
|
+
font-weight: 700;
|
|
350
|
+
letter-spacing: 0.01em;
|
|
351
|
+
}
|
|
352
|
+
.mapicgc-api-territorial-panel-close {
|
|
353
|
+
align-items: center;
|
|
354
|
+
background: rgba(255, 255, 255, 0.18);
|
|
355
|
+
border: 0;
|
|
356
|
+
border-radius: 999px;
|
|
357
|
+
color: #fff;
|
|
358
|
+
cursor: pointer;
|
|
359
|
+
display: inline-flex;
|
|
360
|
+
height: 28px;
|
|
361
|
+
justify-content: center;
|
|
362
|
+
width: 28px;
|
|
363
|
+
}
|
|
364
|
+
.mapicgc-api-territorial-panel-close:hover {
|
|
365
|
+
background: rgba(255, 255, 255, 0.28);
|
|
366
|
+
}
|
|
367
|
+
.mapicgc-api-territorial-panel-content {
|
|
368
|
+
display: grid;
|
|
369
|
+
gap: 10px;
|
|
370
|
+
overflow: auto;
|
|
371
|
+
padding: 14px;
|
|
372
|
+
}
|
|
373
|
+
.mapicgc-api-territorial-panel-row {
|
|
374
|
+
background: #fff;
|
|
375
|
+
border: 1px solid #ead9c6;
|
|
376
|
+
border-radius: 12px;
|
|
377
|
+
display: grid;
|
|
378
|
+
gap: 6px;
|
|
379
|
+
padding: 11px 12px;
|
|
380
|
+
}
|
|
381
|
+
.mapicgc-api-territorial-panel-row-parcela {
|
|
382
|
+
gap: 8px;
|
|
383
|
+
}
|
|
384
|
+
.mapicgc-api-territorial-panel-label {
|
|
385
|
+
color: #86502a;
|
|
386
|
+
font-size: 11px;
|
|
387
|
+
font-weight: 700;
|
|
388
|
+
letter-spacing: 0.08em;
|
|
389
|
+
text-transform: uppercase;
|
|
390
|
+
}
|
|
391
|
+
.mapicgc-api-territorial-panel-value {
|
|
392
|
+
color: #241d15;
|
|
393
|
+
font-size: 14px;
|
|
394
|
+
font-weight: 600;
|
|
395
|
+
line-height: 1.35;
|
|
396
|
+
word-break: break-word;
|
|
397
|
+
}
|
|
398
|
+
.mapicgc-api-territorial-panel-actions {
|
|
399
|
+
display: flex;
|
|
400
|
+
flex-wrap: wrap;
|
|
401
|
+
gap: 8px;
|
|
402
|
+
}
|
|
403
|
+
.mapicgc-api-territorial-panel-copy,
|
|
404
|
+
.mapicgc-api-territorial-panel-link {
|
|
405
|
+
align-items: center;
|
|
406
|
+
border-radius: 999px;
|
|
407
|
+
display: inline-flex;
|
|
408
|
+
font-size: 12px;
|
|
409
|
+
font-weight: 700;
|
|
410
|
+
justify-content: center;
|
|
411
|
+
line-height: 1;
|
|
412
|
+
padding: 8px 11px;
|
|
413
|
+
text-decoration: none;
|
|
414
|
+
}
|
|
415
|
+
.mapicgc-api-territorial-panel-copy {
|
|
416
|
+
background: #fff1dd;
|
|
417
|
+
border: 1px solid #f0c79b;
|
|
418
|
+
color: #9c4d00;
|
|
419
|
+
cursor: pointer;
|
|
420
|
+
}
|
|
421
|
+
.mapicgc-api-territorial-panel-copy:disabled {
|
|
422
|
+
cursor: not-allowed;
|
|
423
|
+
opacity: 0.55;
|
|
424
|
+
}
|
|
425
|
+
.mapicgc-api-territorial-panel-link {
|
|
426
|
+
background: #fff7ef;
|
|
427
|
+
border: 1px solid #efc6a5;
|
|
428
|
+
color: #8a4300;
|
|
429
|
+
}
|
|
430
|
+
@media (max-width: 720px) {
|
|
431
|
+
.mapicgc-api-territorial-panel {
|
|
432
|
+
left: 12px;
|
|
433
|
+
width: auto;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
237
436
|
.maplibregl-ctrl button.maplibregl-ctrl-geolocate .maplibregl-ctrl-icon {
|
|
238
437
|
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='29' height='29' fill='%23333' viewBox='0 0 20 20'%3E%3Cpath d='M10 4C9 4 9 5 9 5v.1A5 5 0 0 0 5.1 9H5s-1 0-1 1 1 1 1 1h.1A5 5 0 0 0 9 14.9v.1s0 1 1 1 1-1 1-1v-.1a5 5 0 0 0 3.9-3.9h.1s1 0 1-1-1-1-1-1h-.1A5 5 0 0 0 11 5.1V5s0-1-1-1zm0 2.5a3.5 3.5 0 1 1 0 7 3.5 3.5 0 1 1 0-7z'/%3E%3Ccircle cx='10' cy='10' r='2'/%3E%3C/svg%3E");
|
|
239
438
|
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { searchApiTerritorialICGC } from "../territorial/searchApiTerritorialICGC";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_ICON_SVG = `
|
|
4
|
+
<svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false">
|
|
5
|
+
<circle cx="12" cy="12" r="7" fill="none" stroke="currentColor" stroke-width="1.8"></circle>
|
|
6
|
+
<path d="M12 3v3M12 18v3M3 12h3M18 12h3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"></path>
|
|
7
|
+
<circle cx="12" cy="12" r="1.9" fill="currentColor"></circle>
|
|
8
|
+
</svg>`;
|
|
9
|
+
|
|
10
|
+
export default class ApiTerritorialControl {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.options = {
|
|
13
|
+
position: "top-right",
|
|
14
|
+
collections: undefined,
|
|
15
|
+
onResult: undefined,
|
|
16
|
+
skipGeometry: true,
|
|
17
|
+
title: "Informació territorial",
|
|
18
|
+
icon: DEFAULT_ICON_SVG,
|
|
19
|
+
customPosition: undefined,
|
|
20
|
+
iconClassName: "",
|
|
21
|
+
IconButton: true,
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
this._active = false;
|
|
26
|
+
this._map = null;
|
|
27
|
+
this._button = null;
|
|
28
|
+
this._container = null;
|
|
29
|
+
this._handleMapClick = this._handleMapClick.bind(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onAdd(map) {
|
|
33
|
+
this._map = map;
|
|
34
|
+
|
|
35
|
+
this._container = document.createElement("div");
|
|
36
|
+
const showIconButton = this.options.IconButton !== false;
|
|
37
|
+
|
|
38
|
+
if (!showIconButton) {
|
|
39
|
+
this._container.className = "mapicgc-api-territorial-control-hidden";
|
|
40
|
+
this.setActive(true);
|
|
41
|
+
return this._container;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
this._container.className = "maplibregl-ctrl maplibregl-ctrl-group mapicgc-api-territorial-control";
|
|
45
|
+
|
|
46
|
+
this._button = document.createElement("button");
|
|
47
|
+
this._button.type = "button";
|
|
48
|
+
this._button.className = "mapicgc-api-territorial-control-button";
|
|
49
|
+
this._button.title = this.options.title;
|
|
50
|
+
this._button.setAttribute("aria-label", this.options.title);
|
|
51
|
+
this._button.setAttribute("aria-pressed", "false");
|
|
52
|
+
|
|
53
|
+
if (this.options.iconClassName) {
|
|
54
|
+
this._button.classList.add(this.options.iconClassName);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this._setButtonIcon(this.options.icon);
|
|
58
|
+
|
|
59
|
+
this._button.addEventListener("click", () => {
|
|
60
|
+
this.setActive(!this._active);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
this._container.appendChild(this._button);
|
|
64
|
+
|
|
65
|
+
if (this.options.customPosition && this._map?.getContainer) {
|
|
66
|
+
const mapContainer = this._map.getContainer();
|
|
67
|
+
window.requestAnimationFrame(() => {
|
|
68
|
+
if (!this._container) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
mapContainer.appendChild(this._container);
|
|
73
|
+
this._applyCustomPosition();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return this._container;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
onRemove() {
|
|
81
|
+
this.setActive(false);
|
|
82
|
+
|
|
83
|
+
if (this._container?.parentNode) {
|
|
84
|
+
this._container.parentNode.removeChild(this._container);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this._map = null;
|
|
88
|
+
this._container = null;
|
|
89
|
+
this._button = null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_setButtonIcon(icon) {
|
|
93
|
+
if (!this._button) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
this._button.replaceChildren();
|
|
98
|
+
|
|
99
|
+
if (icon && typeof icon === "object" && typeof icon.src === "string") {
|
|
100
|
+
const image = document.createElement("img");
|
|
101
|
+
image.className = "mapicgc-api-territorial-control-icon-image";
|
|
102
|
+
image.src = icon.src;
|
|
103
|
+
image.alt = icon.alt || "";
|
|
104
|
+
this._button.appendChild(image);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (typeof icon === "string" && icon.trim().startsWith("<")) {
|
|
109
|
+
this._button.innerHTML = icon;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (typeof icon === "string" && this._looksLikeImageSrc(icon)) {
|
|
114
|
+
const image = document.createElement("img");
|
|
115
|
+
image.className = "mapicgc-api-territorial-control-icon-image";
|
|
116
|
+
image.src = icon;
|
|
117
|
+
image.alt = "";
|
|
118
|
+
this._button.appendChild(image);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof icon === "string" && icon.trim().length > 0) {
|
|
123
|
+
this._button.textContent = icon;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this._button.innerHTML = DEFAULT_ICON_SVG;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
_applyCustomPosition() {
|
|
131
|
+
if (!this._container || !this.options.customPosition) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const { top, right, bottom, left, zIndex } = this.options.customPosition;
|
|
136
|
+
|
|
137
|
+
this._container.classList.add("mapicgc-api-territorial-control-floating");
|
|
138
|
+
this._container.style.top = top !== undefined ? this._toCssUnit(top) : "";
|
|
139
|
+
this._container.style.right = right !== undefined ? this._toCssUnit(right) : "";
|
|
140
|
+
this._container.style.bottom = bottom !== undefined ? this._toCssUnit(bottom) : "";
|
|
141
|
+
this._container.style.left = left !== undefined ? this._toCssUnit(left) : "";
|
|
142
|
+
|
|
143
|
+
if (zIndex !== undefined && zIndex !== null) {
|
|
144
|
+
this._container.style.zIndex = String(zIndex);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_toCssUnit(value) {
|
|
149
|
+
if (typeof value === "number") {
|
|
150
|
+
return `${value}px`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return String(value);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
_looksLikeImageSrc(icon) {
|
|
157
|
+
const value = String(icon || "").trim();
|
|
158
|
+
if (!value) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (value.startsWith("data:image/")) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (/^https?:\/\//i.test(value)) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return /\.(svg|png|jpg|jpeg|webp|gif)(\?.*)?$/i.test(value);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
setActive(active) {
|
|
174
|
+
this._active = Boolean(active);
|
|
175
|
+
|
|
176
|
+
if (this._button) {
|
|
177
|
+
this._button.setAttribute("aria-pressed", String(this._active));
|
|
178
|
+
this._button.classList.toggle("is-active", this._active);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!this._map) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const canvasContainer = this._map.getCanvasContainer();
|
|
186
|
+
|
|
187
|
+
if (this._active) {
|
|
188
|
+
this._map.on("click", this._handleMapClick);
|
|
189
|
+
if (canvasContainer) {
|
|
190
|
+
canvasContainer.style.cursor = "crosshair";
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
this._map.off("click", this._handleMapClick);
|
|
194
|
+
if (canvasContainer) {
|
|
195
|
+
canvasContainer.style.cursor = "";
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async _handleMapClick(event) {
|
|
201
|
+
const lng = event?.lngLat?.lng;
|
|
202
|
+
const lat = event?.lngLat?.lat;
|
|
203
|
+
|
|
204
|
+
if (typeof lng !== "number" || typeof lat !== "number") {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const resultat = await searchApiTerritorialICGC(
|
|
209
|
+
lng,
|
|
210
|
+
lat,
|
|
211
|
+
{
|
|
212
|
+
collections: this.options.collections,
|
|
213
|
+
fields: this.options.fields,
|
|
214
|
+
skipGeometry: this.options.skipGeometry,
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
if (typeof this.options.onResult === "function") {
|
|
219
|
+
this.options.onResult.call(this._map, resultat, event.lngLat);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
import { setWorkerUrl } from "maplibre-gl";
|
|
2
|
+
import maplibreWorkerUrl from "maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url";
|
|
1
3
|
import Map from "./map/Map";
|
|
2
4
|
import CompareMaps from "./plugins/CompareMaps";
|
|
3
5
|
import Config from "./constants/ConfigICGC";
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
// maplibre-gl v6 és ESM-only. Quan es distribueix a través d'un bundler
|
|
8
|
+
// (com aquí, amb `vite build`), `import.meta.url` no resol fiablement la
|
|
9
|
+
// ubicació del worker dins del graf de mòduls del bundle final, així que
|
|
10
|
+
// cal indicar-li explícitament la URL abans de crear cap mapa. Sense
|
|
11
|
+
// això, `new maplibregl.Map(...)` es crea "bé" (canvas, WebGL...) però
|
|
12
|
+
// es queda penjat esperant el worker per sempre i "load" no es dispara
|
|
13
|
+
// mai, sense llançar cap error visible.
|
|
14
|
+
setWorkerUrl(maplibreWorkerUrl);
|
|
15
|
+
|
|
16
|
+
export { Map, CompareMaps, Config };
|
|
17
|
+
// maplibre-gl v6 és ESM-only i ja no publica cap bundle UMD amb un global
|
|
18
|
+
// `maplibregl`. Reexportem el seu namespace perquè qualsevol consumidor
|
|
19
|
+
// (via import ES module o via el global que exposi el vostre build)
|
|
20
|
+
// pugui seguir fent `new maplibregl.NavigationControl()`, etc. sense haver
|
|
21
|
+
// de carregar maplibre-gl per separat amb un <script> clàssic.
|
|
22
|
+
export * as maplibregl from "maplibre-gl";
|