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.
Files changed (52) hide show
  1. package/README.md +2 -4
  2. package/dist/array-utils-flat-DeB-J5jn.mjs +1523 -0
  3. package/dist/assets/maplibre-gl-worker-HMCkgiD4.js +10 -0
  4. package/dist/buffer-transform-CH0poqqn.mjs +941 -0
  5. package/dist/expression-CtaQKvTZ.mjs +3444 -0
  6. package/dist/get-attribute-from-layouts-DqvACIaG.mjs +936 -0
  7. package/dist/{html2canvas-DhrjCa5K-6_3CwS_m.mjs → html2canvas-Cgp0Hyhk-HIw4n-A9.mjs} +105 -109
  8. package/dist/{index.es-D_FsJY9H-CO3QIBGM.mjs → index.es-lgdlL0gw-Bl7I-U5B.mjs} +176 -176
  9. package/dist/mapicgc-gl-js.css +1 -1
  10. package/dist/mapicgc-gl.css +199 -0
  11. package/dist/mapicgc-gl.js +5079 -856
  12. package/dist/mapicgc-gl.mjs +85573 -61841
  13. package/dist/purify.es-DNpVkA56-DxzGf9c8.mjs +769 -0
  14. package/dist/{chunk-efA98nb6-Dfm7IivL.mjs → rolldown-runtime-3b4jIN3o-CmciV3xi.mjs} +2 -2
  15. package/dist/{typeof-CTd55yxz-BxqQpTq1.mjs → typeof-C3azmBUr-9LkZMuan.mjs} +1 -1
  16. package/dist/webgl-Cep-x0-T.mjs +784 -0
  17. package/package.json +20 -15
  18. package/public/mapicgc-gl.css +199 -0
  19. package/src/controls/ApiTerritorialControl.js +222 -0
  20. package/src/index.js +18 -1
  21. package/src/map/Map.js +245 -144
  22. package/src/mapicgc-config.json +1303 -8
  23. package/src/plugins/CompareMaps.js +2 -1
  24. package/src/territorial/ApiTerritorialControl.js +1 -0
  25. package/src/territorial/mostraPanellInfo.js +250 -0
  26. package/src/territorial/searchApiTerritorialICGC.js +250 -0
  27. package/test/exemples/addApiTerritorialICGC.html +113 -0
  28. package/test/exemples/addBasemap.html +4 -4
  29. package/test/exemples/addCompare.html +7 -6
  30. package/test/exemples/addControl.html +12 -6
  31. package/test/exemples/addFeatureQuery.html +5 -4
  32. package/test/exemples/addGeocoderICGC.html +5 -4
  33. package/test/exemples/addICGCTerrain.html +5 -4
  34. package/test/exemples/addICGCTerrainCustomStyle.html +5 -4
  35. package/test/exemples/addImageLayerICGC.html +5 -4
  36. package/test/exemples/addLayerGeojson.html +5 -4
  37. package/test/exemples/addLayerTree.html +5 -4
  38. package/test/exemples/addLogo.html +5 -3
  39. package/test/exemples/addMapStyle.html +5 -4
  40. package/test/exemples/addMarker.html +5 -4
  41. package/test/exemples/addMouseCoordinateControl.html +5 -4
  42. package/test/exemples/addReliefStyle.html +6 -5
  43. package/test/exemples/addVectorLayerICGC.html +5 -4
  44. package/test/exemples/advancedExemple.html +5 -4
  45. package/test/exemples/fetchData.html +6 -5
  46. package/test/exemples/fetchDataAndMenu.html +5 -4
  47. package/test/exemples/styleOrto3D.html +8 -4
  48. package/test/vitest/ApiTerritorialControl.test.js +76 -0
  49. package/vite.config.mjs +16 -5
  50. package/dist/purify.es-DVGU85zV-CJOZ7ABI.mjs +0 -549
  51. package/dist/webgl-device-B1jTrfKA.mjs +0 -6880
  52. package/dist/webgl-device-D8jkwRzb.mjs +0 -2
@@ -1,4 +1,5 @@
1
- import maplibregl from "maplibre-gl";
1
+
2
+ import * as maplibregl from "maplibre-gl";
2
3
  import Compare from "@maplibre/maplibre-gl-compare";
3
4
 
4
5
  /**
@@ -0,0 +1 @@
1
+ export { default } from "../controls/ApiTerritorialControl";
@@ -0,0 +1,250 @@
1
+ import proj4 from "proj4";
2
+
3
+ const PANEL_ID = "mapicgc-api-territorial-panel";
4
+ const PANEL_CONTENT_ID = "mapicgc-api-territorial-panel-content";
5
+ const CADASTRE_URL =
6
+ "https://www1.sedecatastro.gob.es/CYCBienInmueble/OVCListaBienes.aspx";
7
+
8
+ proj4.defs(
9
+ "EPSG:25831",
10
+ "+proj=utm +zone=31 +ellps=GRS80 +units=m +no_defs +type=crs"
11
+ );
12
+
13
+ function formatNumber(value, decimals = 2) {
14
+ return Number(value).toFixed(decimals);
15
+ }
16
+
17
+ function buildValueLine(label, valueText, copyText) {
18
+ const row = document.createElement("div");
19
+ row.className = "mapicgc-api-territorial-panel-row";
20
+
21
+ const labelNode = document.createElement("div");
22
+ labelNode.className = "mapicgc-api-territorial-panel-label";
23
+ labelNode.textContent = label;
24
+
25
+ const valueNode = document.createElement("div");
26
+ valueNode.className = "mapicgc-api-territorial-panel-value";
27
+ valueNode.textContent = valueText;
28
+
29
+ const actionsNode = document.createElement("div");
30
+ actionsNode.className = "mapicgc-api-territorial-panel-actions";
31
+
32
+ if (copyText) {
33
+ const copyButton = document.createElement("button");
34
+ copyButton.type = "button";
35
+ copyButton.className = "mapicgc-api-territorial-panel-copy";
36
+ copyButton.textContent = "Copiar";
37
+ copyButton.addEventListener("click", async () => {
38
+ try {
39
+ await navigator.clipboard.writeText(copyText);
40
+ copyButton.textContent = "Copiat";
41
+ setTimeout(() => {
42
+ copyButton.textContent = "Copiar";
43
+ }, 1200);
44
+ } catch (error) {
45
+ copyButton.textContent = "Error";
46
+ setTimeout(() => {
47
+ copyButton.textContent = "Copiar";
48
+ }, 1200);
49
+ }
50
+ });
51
+ actionsNode.appendChild(copyButton);
52
+ }
53
+
54
+ row.appendChild(labelNode);
55
+ row.appendChild(valueNode);
56
+ row.appendChild(actionsNode);
57
+
58
+ return row;
59
+ }
60
+
61
+ function formatCollectionTitle(collectionId) {
62
+ const titles = {
63
+ comarques: "Comarca",
64
+ municipis: "Municipi",
65
+ provincies: "Província",
66
+ "arees-basiques-salut": "Àrea bàsica de salut",
67
+ "arees-basiques-policials": "Àrea bàsica policial",
68
+ "arees-basiques-serveis-socials": "Àrea bàsica de serveis socials",
69
+ "parcelles-cadastre": "Parcel·la cadastral",
70
+ };
71
+
72
+ if (titles[collectionId]) {
73
+ return titles[collectionId];
74
+ }
75
+
76
+ return collectionId
77
+ .replace(/[-_]+/g, " ")
78
+ .replace(/\b\w/g, (match) => match.toUpperCase());
79
+ }
80
+
81
+ function formatFieldLabel(fieldName) {
82
+ return String(fieldName)
83
+ .replace(/[_-]+/g, " ")
84
+ .replace(/\s+/g, " ")
85
+ .trim()
86
+ .replace(/\b\w/g, (match) => match.toUpperCase());
87
+ }
88
+
89
+ function ensurePanel(map) {
90
+ const mapContainer =
91
+ map?.getContainer?.() || document.getElementById("map") || document.body;
92
+
93
+ let panel = document.getElementById(PANEL_ID);
94
+ if (!panel) {
95
+ panel = document.createElement("aside");
96
+ panel.id = PANEL_ID;
97
+ panel.className = "mapicgc-api-territorial-panel is-hidden";
98
+
99
+ const header = document.createElement("header");
100
+ header.className = "mapicgc-api-territorial-panel-header";
101
+
102
+ const titleWrap = document.createElement("div");
103
+ titleWrap.className = "mapicgc-api-territorial-panel-title-wrap";
104
+
105
+ const icon = document.createElement("span");
106
+ icon.className = "mapicgc-api-territorial-panel-title-icon";
107
+ icon.textContent = "ⓘ";
108
+
109
+ const title = document.createElement("span");
110
+ title.className = "mapicgc-api-territorial-panel-title";
111
+ title.textContent = "Informació del punt";
112
+
113
+ titleWrap.appendChild(icon);
114
+ titleWrap.appendChild(title);
115
+
116
+ const closeButton = document.createElement("button");
117
+ closeButton.type = "button";
118
+ closeButton.className = "mapicgc-api-territorial-panel-close";
119
+ closeButton.textContent = "✕";
120
+ closeButton.setAttribute("aria-label", "Tancar panell");
121
+ closeButton.addEventListener("click", () => {
122
+ panel.classList.add("is-hidden");
123
+ });
124
+
125
+ header.appendChild(titleWrap);
126
+ header.appendChild(closeButton);
127
+
128
+ const content = document.createElement("div");
129
+ content.id = PANEL_CONTENT_ID;
130
+ content.className = "mapicgc-api-territorial-panel-content";
131
+
132
+ panel.appendChild(header);
133
+ panel.appendChild(content);
134
+ mapContainer.appendChild(panel);
135
+ }
136
+
137
+ return panel;
138
+ }
139
+
140
+ export default function mostraPanellInfo(resultat, lngLat) {
141
+ const map = this?.map || this;
142
+ const panel = ensurePanel(map);
143
+ const content = document.getElementById(PANEL_CONTENT_ID);
144
+
145
+ if (!content) {
146
+ return null;
147
+ }
148
+
149
+ content.replaceChildren();
150
+
151
+ const coordinates = lngLat || {
152
+ lng: resultat?.lng,
153
+ lat: resultat?.lat,
154
+ };
155
+
156
+ const lng = Number(coordinates?.lng);
157
+ const lat = Number(coordinates?.lat);
158
+ const [utmX, utmY] = proj4("EPSG:4326", "EPSG:25831", [lng, lat]);
159
+ const utmText = `ETRS89 UTM 31N X ${formatNumber(utmX, 2)} Y ${formatNumber(utmY, 2)}`;
160
+ const wgs84Text = `WGS84 Lon ${formatNumber(lng, 6)} Lat ${formatNumber(lat, 6)}`;
161
+ content.appendChild(buildValueLine("Coordenades UTM", utmText, utmText));
162
+ content.appendChild(buildValueLine("Coordenades WGS84", wgs84Text, wgs84Text));
163
+
164
+ const resultats = resultat?.resultats || {};
165
+
166
+ Object.entries(resultats).forEach(([collectionId, value]) => {
167
+ if (!value || (typeof value === "object" && Object.keys(value).length === 0)) {
168
+ return;
169
+ }
170
+
171
+ const collectionTitle = formatCollectionTitle(collectionId);
172
+
173
+ if (typeof value !== "object") {
174
+ const valueText = String(value);
175
+ content.appendChild(buildValueLine(collectionTitle, valueText, valueText));
176
+ return;
177
+ }
178
+
179
+ Object.entries(value).forEach(([propertyKey, propertyValue]) => {
180
+ if (propertyValue === undefined || propertyValue === null || propertyValue === "") {
181
+ return;
182
+ }
183
+
184
+ const label = `${collectionTitle} · ${formatFieldLabel(propertyKey)}`;
185
+ const valueText =
186
+ typeof propertyValue === "object"
187
+ ? JSON.stringify(propertyValue)
188
+ : String(propertyValue);
189
+ content.appendChild(buildValueLine(label, valueText, valueText));
190
+ });
191
+ });
192
+
193
+ const cadastre = resultats["parcelles-cadastre"];
194
+ const parcelReference = cadastre?.refcadp || cadastre?.REFCADP;
195
+
196
+ if (parcelReference) {
197
+ const cadastreRow = document.createElement("div");
198
+ cadastreRow.className = "mapicgc-api-territorial-panel-row mapicgc-api-territorial-panel-row-parcela";
199
+
200
+ const parcelLabel = document.createElement("div");
201
+ parcelLabel.className = "mapicgc-api-territorial-panel-label";
202
+ parcelLabel.textContent = "Cadastre";
203
+
204
+ const parcelValue = document.createElement("div");
205
+ parcelValue.className = "mapicgc-api-territorial-panel-value";
206
+ parcelValue.textContent = parcelReference;
207
+
208
+ const parcelActions = document.createElement("div");
209
+ parcelActions.className = "mapicgc-api-territorial-panel-actions";
210
+
211
+ const copyParcelButton = document.createElement("button");
212
+ copyParcelButton.type = "button";
213
+ copyParcelButton.className = "mapicgc-api-territorial-panel-copy";
214
+ copyParcelButton.textContent = "Copiar";
215
+ copyParcelButton.addEventListener("click", async () => {
216
+ try {
217
+ await navigator.clipboard.writeText(parcelReference);
218
+ copyParcelButton.textContent = "Copiat";
219
+ setTimeout(() => {
220
+ copyParcelButton.textContent = "Copiar";
221
+ }, 1200);
222
+ } catch (error) {
223
+ copyParcelButton.textContent = "Error";
224
+ setTimeout(() => {
225
+ copyParcelButton.textContent = "Copiar";
226
+ }, 1200);
227
+ }
228
+ });
229
+
230
+ const cadastreLink = document.createElement("a");
231
+ cadastreLink.className = "mapicgc-api-territorial-panel-link";
232
+ cadastreLink.href = `${CADASTRE_URL}?RefC=${encodeURIComponent(parcelReference)}`;
233
+ cadastreLink.target = "_blank";
234
+ cadastreLink.rel = "noreferrer";
235
+ cadastreLink.textContent = "Obrir";
236
+ cadastreLink.title = "Obrir la Seu Electrònica del Cadastre";
237
+
238
+ parcelActions.appendChild(copyParcelButton);
239
+ parcelActions.appendChild(cadastreLink);
240
+
241
+ cadastreRow.appendChild(parcelLabel);
242
+ cadastreRow.appendChild(parcelValue);
243
+ cadastreRow.appendChild(parcelActions);
244
+ content.appendChild(cadastreRow);
245
+ }
246
+
247
+ panel.classList.remove("is-hidden");
248
+
249
+ return panel;
250
+ }
@@ -0,0 +1,250 @@
1
+ const TERRITORIAL_BASE_URL = "https://api.icgc.cat/territorial";
2
+
3
+ const DEFAULT_COLLECTIONS = [
4
+ "comarques",
5
+ "municipis",
6
+ "arees-basiques-salut",
7
+ "arees-basiques-policials",
8
+ "arees-basiques-serveis-socials",
9
+ "parcelles-cadastre",
10
+ ];
11
+
12
+ const COLLECTION_ALIASES = {
13
+ "arees-basqieus-policials": "arees-basiques-policials",
14
+ "arees-basiques-policial": "arees-basiques-policials",
15
+ };
16
+
17
+ function normalizeLookupKey(value) {
18
+ return String(value || "")
19
+ .normalize("NFD")
20
+ .replace(/[\u0300-\u036f]/g, "")
21
+ .toLowerCase()
22
+ .replace(/[^a-z0-9]/g, "");
23
+ }
24
+
25
+ function normalizeFieldList(fields) {
26
+ if (!fields) {
27
+ return null;
28
+ }
29
+
30
+ if (Array.isArray(fields)) {
31
+ return fields.map((field) => String(field).trim()).filter(Boolean);
32
+ }
33
+
34
+ if (typeof fields === "string") {
35
+ return fields
36
+ .split(",")
37
+ .map((field) => field.trim())
38
+ .filter(Boolean);
39
+ }
40
+
41
+ return null;
42
+ }
43
+
44
+ function normalizeTerritorialOptions(collectionsOrOptions) {
45
+ if (!collectionsOrOptions) {
46
+ return {
47
+ collections: DEFAULT_COLLECTIONS,
48
+ fields: null,
49
+ skipGeometry: false,
50
+ };
51
+ }
52
+
53
+ if (Array.isArray(collectionsOrOptions)) {
54
+ return {
55
+ collections: collectionsOrOptions,
56
+ fields: null,
57
+ skipGeometry: false,
58
+ };
59
+ }
60
+
61
+ if (typeof collectionsOrOptions === "object") {
62
+ const collections = collectionsOrOptions.collections || DEFAULT_COLLECTIONS;
63
+ const fields = collectionsOrOptions.fields || null;
64
+ const skipGeometry = collectionsOrOptions.skipGeometry === true;
65
+
66
+ return {
67
+ collections,
68
+ fields,
69
+ skipGeometry,
70
+ };
71
+ }
72
+
73
+ return {
74
+ collections: DEFAULT_COLLECTIONS,
75
+ fields: null,
76
+ skipGeometry: false,
77
+ };
78
+ }
79
+
80
+ function normalizeCollections(collections) {
81
+ if (!collections) {
82
+ return DEFAULT_COLLECTIONS;
83
+ }
84
+
85
+ if (typeof collections === "string") {
86
+ return [collections.trim()].filter(Boolean);
87
+ }
88
+
89
+ if (!Array.isArray(collections)) {
90
+ return DEFAULT_COLLECTIONS;
91
+ }
92
+
93
+ return collections
94
+ .map((collection) => {
95
+ if (typeof collection === "string") {
96
+ const normalized = collection.trim();
97
+ return COLLECTION_ALIASES[normalized] || normalized;
98
+ }
99
+
100
+ if (collection && typeof collection === "object") {
101
+ const normalized = String(collection.id || collection.name || "").trim();
102
+ return COLLECTION_ALIASES[normalized] || normalized;
103
+ }
104
+
105
+ return "";
106
+ })
107
+ .filter(Boolean);
108
+ }
109
+
110
+ async function searchTerritorialCollection(collectionId, bbox, options = {}) {
111
+ const params = new URLSearchParams({
112
+ bbox: bbox.join(","),
113
+ f: "geojson",
114
+ });
115
+
116
+ if (options.skipGeometry) {
117
+ params.set("skipgeometry", "true");
118
+ }
119
+
120
+ const url = `${TERRITORIAL_BASE_URL}/collections/${collectionId}/items?${params.toString()}`;
121
+
122
+ try {
123
+ const response = await fetch(url, {
124
+ headers: {
125
+ Accept: "application/geo+json",
126
+ },
127
+ });
128
+
129
+ if (!response.ok) {
130
+ return null;
131
+ }
132
+
133
+ const geojson = await response.json();
134
+ const feature = geojson?.features?.[0] || null;
135
+ const features = Array.isArray(geojson?.features) ? geojson.features : [];
136
+
137
+ return {
138
+ properties: feature?.properties || null,
139
+ firstFeature: feature,
140
+ features,
141
+ geojson,
142
+ };
143
+ } catch (error) {
144
+ return {
145
+ properties: null,
146
+ firstFeature: null,
147
+ features: [],
148
+ geojson: null,
149
+ };
150
+ }
151
+ }
152
+
153
+ function filterTerritorialProperties(properties, fields, collectionId) {
154
+ if (!properties || !fields) {
155
+ return properties || null;
156
+ }
157
+
158
+ const fieldsForCollection = Array.isArray(fields)
159
+ ? fields
160
+ : normalizeFieldList(fields?.[collectionId]) || normalizeFieldList(fields?.default);
161
+
162
+ if (!fieldsForCollection || fieldsForCollection.length === 0) {
163
+ return properties;
164
+ }
165
+
166
+ const filtered = {};
167
+ const normalizedPropertyKeys = new Map(
168
+ Object.keys(properties).map((key) => [normalizeLookupKey(key), key])
169
+ );
170
+
171
+ for (const fieldName of fieldsForCollection) {
172
+ const directMatch = Object.prototype.hasOwnProperty.call(properties, fieldName)
173
+ ? fieldName
174
+ : null;
175
+ const normalizedMatch = normalizedPropertyKeys.get(normalizeLookupKey(fieldName));
176
+ const propertyKey = directMatch || normalizedMatch;
177
+
178
+ if (propertyKey) {
179
+ const value = properties[propertyKey];
180
+ if (value !== undefined && value !== null && value !== "") {
181
+ filtered[propertyKey] = value;
182
+ }
183
+ }
184
+ }
185
+
186
+ if (Object.keys(filtered).length > 0) {
187
+ return filtered;
188
+ }
189
+
190
+ // If requested fields do not match this collection, keep full properties for export use cases.
191
+ return properties;
192
+ }
193
+
194
+ export async function searchApiTerritorialICGC(
195
+ lng,
196
+ lat,
197
+ collectionsOrOptions = DEFAULT_COLLECTIONS
198
+ ) {
199
+ const { collections, fields, skipGeometry } = normalizeTerritorialOptions(collectionsOrOptions);
200
+ const requestedCollections = normalizeCollections(collections);
201
+ const delta = 0.00005;
202
+ const bbox = [lng - delta, lat - delta, lng + delta, lat + delta];
203
+
204
+ const collectionResults = await Promise.all(
205
+ requestedCollections.map(async (collectionId) => [
206
+ collectionId,
207
+ await searchTerritorialCollection(collectionId, bbox, { skipGeometry }),
208
+ ])
209
+ );
210
+
211
+ const resultats = Object.fromEntries(
212
+ collectionResults.map(([collectionId, data]) => [
213
+ collectionId,
214
+ filterTerritorialProperties(data?.properties, fields, collectionId),
215
+ ])
216
+ );
217
+
218
+ const firstFeature = Object.fromEntries(
219
+ collectionResults.map(([collectionId, data]) => [
220
+ collectionId,
221
+ data?.firstFeature || null,
222
+ ])
223
+ );
224
+
225
+ const features = Object.fromEntries(
226
+ collectionResults.map(([collectionId, data]) => [
227
+ collectionId,
228
+ data?.features || [],
229
+ ])
230
+ );
231
+
232
+ const raw = Object.fromEntries(
233
+ collectionResults.map(([collectionId, data]) => [
234
+ collectionId,
235
+ data?.geojson || null,
236
+ ])
237
+ );
238
+
239
+ return {
240
+ lng,
241
+ lat,
242
+ bbox,
243
+ resultats,
244
+ firstFeature,
245
+ features,
246
+ raw,
247
+ };
248
+ }
249
+
250
+ export default searchApiTerritorialICGC;
@@ -0,0 +1,113 @@
1
+ <html>
2
+ <head>
3
+ <meta charset='utf-8' />
4
+ <title>addApiTerritorialICGC.html</title>
5
+ <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
6
+ <link href="../../dist/mapicgc-gl.css" rel="stylesheet" />
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ padding: 0;
11
+ }
12
+
13
+ #map {
14
+ position: absolute;
15
+ top: 0;
16
+ bottom: 0;
17
+ width: 100%;
18
+ height: 100%;
19
+ }
20
+ </style>
21
+ </head>
22
+ <body>
23
+ <div id="map" class="map"></div>
24
+
25
+ <script type="module">
26
+ import { Map, Config } from "../../dist/mapicgc-gl.mjs";
27
+
28
+ async function initMap() {
29
+ const data = await Config.getConfigICGC();
30
+ const map = new Map({
31
+ container: "map",
32
+ // Estil base del mapa.
33
+ style: data.Styles.TOPO,
34
+ // Centre inicial sobre Catalunya.
35
+ center: [1.808, 41.618],
36
+ // Zoom inicial recomanat per veure territori amb detall.
37
+ zoom: 10,
38
+ // Límits de zoom del visor.
39
+ maxZoom: 19,
40
+ // Activa la sincronització URL <-> mapa.
41
+ hash: true,
42
+ // Sense inclinació inicial.
43
+ pitch: 0,
44
+ });
45
+
46
+ map.on("load", () => {
47
+ const mapPinIconSvg = `
48
+ <svg viewBox="0 0 24 24" width="18" height="18" aria-hidden="true" focusable="false">
49
+ <circle cx="12" cy="12" r="11" fill="#cfd8e3" stroke="#304b63" stroke-width="1.2"></circle>
50
+ <path d="M4.8 16.6 4 7.4h5.1v4L6.5 13l4.2 3.1h4.7l-.1-2.6-2.2-2 2.7-1.4h3l-.7 6.5z" fill="#8ed27a" stroke="#2e4a63" stroke-linejoin="round" stroke-width="0.9"></path>
51
+ <path d="M12 5.7c-1.8 0-3.2 1.4-3.2 3.2 0 2.2 3.2 5.4 3.2 5.4s3.2-3.2 3.2-5.4c0-1.8-1.4-3.2-3.2-3.2z" fill="#ff7d62" stroke="#2e4a63" stroke-width="0.9"></path>
52
+ <circle cx="12" cy="8.9" r="1.1" fill="#e9f0f8" stroke="#2e4a63" stroke-width="0.7"></circle>
53
+ </svg>`;
54
+ const mapPinIconImage = "https://uxwing.com/wp-content/themes/uxwing/download/location-travel-map/unknown-map-location-icon.png"
55
+ map.addApiTerritorialICGC({
56
+ // Mostra o amaga el panell lateral automàtic.
57
+ infoPanel: true,
58
+
59
+ // true: botó visible. false: consulta activa sense botó.
60
+ IconButton: true,
61
+
62
+ // Icona del botó: text, SVG inline, URL d'imatge o objecte { src, alt }.
63
+ icon: mapPinIconSvg,
64
+ // icon: mapPinIconImage,
65
+
66
+ // Posició lliure dins del contenidor del mapa.
67
+ // (Si ho treus, usarà la posició MapLibre de l'argument "top-right").
68
+ customPosition: {
69
+ top: 88,
70
+ left: 14,
71
+ zIndex: 6,
72
+ },
73
+
74
+ // Col·leccions que es consulten al clic.
75
+ collections: [
76
+ "comarques",
77
+ "municipis",
78
+ "provincies",
79
+ "parcelles-cadastre",
80
+ "arees-basiques-policials"
81
+ ],
82
+
83
+ // Camps que volem conservar de cada col·lecció. Si no es defineix, es retorna tota la propietat trobada.
84
+ // Si el camp no existeix en la resposta, no es mostra.
85
+ fields: {
86
+ default: ["id", "nom"],
87
+ municipis: ["NOMMUNI"],
88
+ comarques: ["NOMCOMAR"],
89
+ provincies: ["NOMPROV"],
90
+ "arees-basiques-policials": [
91
+ "Àrea bàsica policial",
92
+ "Regió policial",
93
+ "Població"
94
+ ],
95
+ "parcelles-cadastre": ["refcadp"],
96
+ },
97
+
98
+ // Callback per rebre la informació retornada per l'API.
99
+ // Es pot fer servir per logs, destacar elements o disparar altres accions.
100
+ onResult(resultat, lngLat) {
101
+ console.log("Resultat territorial (complet):", resultat);
102
+
103
+ // Exemple: retornar la dada perquè la pugui usar qui crida el mètode.
104
+ return resultat;
105
+ },
106
+ }, "top-right");
107
+ });
108
+ }
109
+
110
+ initMap();
111
+ </script>
112
+ </body>
113
+ </html>
@@ -5,7 +5,6 @@
5
5
  <title>Exemple mapicgc-gl-js: Afegir mapa base ICGC</title>
6
6
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
7
7
 
8
- <script src="../../dist/mapicgc-gl.js"></script>
9
8
  <link href="../../dist/mapicgc-gl.css" rel="stylesheet" />
10
9
 
11
10
  <style>
@@ -36,11 +35,12 @@
36
35
  <body>
37
36
  <div id="map"></div>
38
37
  <!-- <div id="basemap-group" class="basemap-group"></div> -->
39
- <script>
38
+ <script type="module">
39
+ import { Map, Config } from "../../dist/mapicgc-gl.mjs";
40
40
 
41
41
  async function initMap() {
42
- const data = await mapicgcgl.Config.getConfigICGC();
43
- const map = new mapicgcgl.Map({
42
+ const data = await Config.getConfigICGC();
43
+ const map = new Map({
44
44
  container: "map",
45
45
  style: data.Styles.ORTO, // <-- add style basemap here
46
46
  center: [2.1464, 41.306],
@@ -4,7 +4,6 @@
4
4
  <meta charset="utf-8" />
5
5
  <title>Exemple mapicgc-gl-js: Afegir comparador</title>
6
6
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
7
- <script src="../../dist/mapicgc-gl.js"></script>
8
7
  <link href="../../dist/mapicgc-gl.css" rel="stylesheet" />
9
8
 
10
9
  <style>
@@ -37,10 +36,12 @@
37
36
  <div id="after" class="map"></div>
38
37
  </div>
39
38
 
40
- <script>
39
+ <script type="module">
40
+ import { Map, Config, CompareMaps } from "../../dist/mapicgc-gl.mjs";
41
+
41
42
  async function initMap() {
42
- const data = await mapicgcgl.Config.getConfigICGC();;
43
- const map1 = new mapicgcgl.Map({
43
+ const data = await Config.getConfigICGC();
44
+ const map1 = new Map({
44
45
  container: "before",
45
46
  style: data.Styles.ORTO,
46
47
  center: [1.1464, 41.706],
@@ -50,7 +51,7 @@
50
51
  pitch: 0,
51
52
  });
52
53
 
53
- const map2 = new mapicgcgl.Map({
54
+ const map2 = new Map({
54
55
  container: "after",
55
56
  style: data.Styles.TOPO,
56
57
  center: [1.1464, 41.706],
@@ -62,7 +63,7 @@
62
63
 
63
64
  const container = "#comparison-container";
64
65
 
65
- const map = new mapicgcgl.CompareMaps(map1, map2, container, {});
66
+ const map = new CompareMaps(map1, map2, container, {});
66
67
  }
67
68
 
68
69
  initMap();