mapicgc-gl-js 0.0.39 → 0.0.41

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/src/map/Map.js CHANGED
@@ -266,7 +266,7 @@ inputsearch[0].addEventListener('input', function(event) {
266
266
  */
267
267
  getStyle() {
268
268
  try {
269
- this.map.getStyle();
269
+ return this.map.getStyle();
270
270
  } catch (error) {
271
271
  console.error(`Error getting style: ${error.message}`);
272
272
  }
@@ -628,7 +628,7 @@ if ( featureTree === 'all'){
628
628
  // map.addLayerTree(geojson);
629
629
 
630
630
  map.addMenuItem(name);
631
- map.addFeatureQuery(name)
631
+ // map.addFeatureQuery(name)
632
632
  }else{
633
633
 
634
634
  let field= featureTree
@@ -750,6 +750,7 @@ geojson.features.forEach(feature => {
750
750
  }
751
751
  }
752
752
 
753
+ // Agregar la nueva capa al objeto de capas
753
754
  layers[fieldMarker] = true;
754
755
  map.addMenuItem(fieldMarker);
755
756
  }
@@ -758,6 +759,16 @@ geojson.features.forEach(feature => {
758
759
 
759
760
  }
760
761
 
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+ //add feature queries
771
+ // map.addFeatureQuery(name);
761
772
  } catch (error) {
762
773
  console.error(`Error fetching data: ${error.message}`);
763
774
  }
@@ -842,7 +853,7 @@ geojson.features.forEach(feature => {
842
853
  */
843
854
  getSource(source) {
844
855
  try {
845
- this.map.getSource(source);
856
+ return this.map.getSource(source);
846
857
  } catch (error) {
847
858
  console.error(`Error getting source: ${error.message}`);
848
859
  }
@@ -860,6 +871,9 @@ geojson.features.forEach(feature => {
860
871
  console.error(`Error adding source: ${error.message}`);
861
872
  }
862
873
  }
874
+
875
+
876
+
863
877
  /**
864
878
  * Sets the style of the map.
865
879
  * @function setStyle
@@ -915,11 +929,28 @@ geojson.features.forEach(feature => {
915
929
 
916
930
  getLayer(layerId) {
917
931
  try {
918
- this.map.getLayer(layerId);
932
+ return this.map.getLayer(layerId);
919
933
  } catch (error) {
920
934
  console.error(`Error getting layer: ${error.message}`);
921
935
  }
922
936
  }
937
+
938
+
939
+ /**
940
+ * Set filter for specified style layer.
941
+ * @function setFilter
942
+ * @param {string} layerId - The ID of the layer to retrieve.
943
+ * @param {array} filter - The filter.
944
+ * @param {string} options - Options object.
945
+ */
946
+
947
+ setFilter(layerId ,filter, options) {
948
+ try {
949
+ return this.map.setFilter(layerId, filter, options);
950
+ } catch (error) {
951
+ console.error(`Error setting filter: ${error.message}`);
952
+ }
953
+ }
923
954
  /**
924
955
  * Jumps to the specified coordinates and zoom on the map.
925
956
  * @function jumpTo
@@ -1149,7 +1180,7 @@ geojson.features.forEach(feature => {
1149
1180
  */
1150
1181
  addLayerGeoJSON(layer) {
1151
1182
  try {
1152
- this.map.on("load", () => {
1183
+ // this.map.on("load", () => {
1153
1184
  this.map.addSource(`${layer.id}-sourceIcgcMap`, {
1154
1185
  type: "geojson",
1155
1186
  data: layer.data,
@@ -1162,7 +1193,7 @@ geojson.features.forEach(feature => {
1162
1193
  layout: layer.layout,
1163
1194
  paint: layer.paint,
1164
1195
  });
1165
- });
1196
+ // });
1166
1197
  } catch (error) {
1167
1198
  console.error(`Error adding GeoJSON layer: ${error.message}`);
1168
1199
  }
@@ -1178,7 +1209,7 @@ geojson.features.forEach(feature => {
1178
1209
  */
1179
1210
  addLayerWMS(layer) {
1180
1211
  try {
1181
- this.map.on("load", () => {
1212
+ // this.map.on("load", () => {
1182
1213
  console.log("holaaddlayerwms", layer);
1183
1214
  this.map.addSource(`${layer.id}-sourceIcgcMap`, {
1184
1215
  type: "raster",
@@ -1191,7 +1222,7 @@ geojson.features.forEach(feature => {
1191
1222
  source: `${layer.id}-sourceIcgcMap`,
1192
1223
  paint: {},
1193
1224
  });
1194
- });
1225
+ // });
1195
1226
  } catch (error) {
1196
1227
  console.error(`Error adding WMS layer: ${error.message}`);
1197
1228
  }
@@ -1275,7 +1306,7 @@ geojson.features.forEach(feature => {
1275
1306
  };
1276
1307
 
1277
1308
  const basemapGroup = document.getElementById("basemap-group");
1278
- this.map.on("load", () => {
1309
+ // this.map.on("load", () => {
1279
1310
  for (const url of basesArray) {
1280
1311
  for (const key of Object.keys(defaultOptions.baseStyles)) {
1281
1312
  const item = defaultOptions.baseStyles[key];
@@ -1289,7 +1320,7 @@ geojson.features.forEach(feature => {
1289
1320
  }
1290
1321
  }
1291
1322
  }
1292
- });
1323
+ // });
1293
1324
  } catch (error) {
1294
1325
  console.error(`Error adding basemaps: ${error.message}`);
1295
1326
  }
@@ -1310,7 +1341,7 @@ geojson.features.forEach(feature => {
1310
1341
  };
1311
1342
 
1312
1343
  const basemapGroup = document.getElementById("basemap-group");
1313
- this.map.on("load", () => {
1344
+ // this.map.on("load", () => {
1314
1345
  baseLayers.forEach((base) => {
1315
1346
  const div = document.createElement("div");
1316
1347
  div.className = "basemap-item";
@@ -1319,7 +1350,7 @@ geojson.features.forEach(feature => {
1319
1350
  basemapGroup.appendChild(div);
1320
1351
  div.addEventListener("click", () => handleClick(base));
1321
1352
  });
1322
- });
1353
+ // });
1323
1354
  } catch (error) {
1324
1355
  console.error(`Error adding basemaps: ${error.message}`);
1325
1356
  }
@@ -1335,7 +1366,7 @@ geojson.features.forEach(feature => {
1335
1366
  try {
1336
1367
  let description;
1337
1368
 
1338
- this.map.on("load", () => {
1369
+ // this.map.on("load", () => {
1339
1370
  // console.log('layer', layerName, options)
1340
1371
  this.map.on("mouseenter", layerName, () => {
1341
1372
  this.map.getCanvas().style.cursor = "pointer";
@@ -1380,7 +1411,7 @@ geojson.features.forEach(feature => {
1380
1411
  }
1381
1412
  }
1382
1413
  });
1383
- });
1414
+ // });
1384
1415
  } catch (error) {
1385
1416
  console.error(`Error adding feature query: ${error.message}`);
1386
1417
  }
@@ -1470,7 +1501,7 @@ geojson.features.forEach(feature => {
1470
1501
  },
1471
1502
  };
1472
1503
 
1473
- this.map.on("load", () => {
1504
+ // this.map.on("load", () => {
1474
1505
  this.map.addSource("geojson", {
1475
1506
  type: "geojson",
1476
1507
  data: geojson,
@@ -1501,7 +1532,7 @@ geojson.features.forEach(feature => {
1501
1532
  },
1502
1533
  filter: ["in", "$type", "LineString"],
1503
1534
  });
1504
- });
1535
+ // });
1505
1536
 
1506
1537
  this.map.on("click", (e) => {
1507
1538
  clearTimeout(clickTimer);
@@ -1651,12 +1682,12 @@ geojson.features.forEach(feature => {
1651
1682
  */
1652
1683
  addPopup(coordinates, text) {
1653
1684
  try {
1654
- this.map.on("load", () => {
1685
+ // this.map.on("load", () => {
1655
1686
  new maplibregl.Popup()
1656
1687
  .setLngLat(coordinates)
1657
1688
  .setHTML(text)
1658
1689
  .addTo(this.map);
1659
- });
1690
+ // });
1660
1691
  } catch (error) {}
1661
1692
  }
1662
1693
 
@@ -1739,6 +1770,7 @@ geojson.features.forEach(feature => {
1739
1770
  */
1740
1771
  addMenuItem(name) {
1741
1772
  try {
1773
+ if (name.length > 0){
1742
1774
  const menuGroup = document.getElementById("menu-group");
1743
1775
 
1744
1776
  const input = document.createElement("input");
@@ -1761,6 +1793,7 @@ geojson.features.forEach(feature => {
1761
1793
  e.target.checked ? "visible" : "none"
1762
1794
  );
1763
1795
  });
1796
+ }
1764
1797
  } catch (error) {
1765
1798
  console.error(`Error adding menu item: ${error.message}`);
1766
1799
  }
@@ -1779,7 +1812,7 @@ geojson.features.forEach(feature => {
1779
1812
  let places = options.features;
1780
1813
 
1781
1814
  const filterGroup = document.getElementById("filter-group");
1782
- this.map.on("load", () => {
1815
+ // this.map.on("load", () => {
1783
1816
  const layers = this.map.getStyle().layers;
1784
1817
  let firstSymbolId;
1785
1818
  for (let i = 0; i < layers.length; i++) {
@@ -1831,7 +1864,7 @@ geojson.features.forEach(feature => {
1831
1864
  });
1832
1865
  }
1833
1866
  });
1834
- });
1867
+ // });
1835
1868
  } catch (error) {
1836
1869
  console.error(`Error adding layer tree: ${error.message}`);
1837
1870
  }
@@ -2047,18 +2080,47 @@ geojson.features.forEach(feature => {
2047
2080
  // layerUrl = op.url;
2048
2081
 
2049
2082
  const response = await fetch(layerUrl);
2050
- this.map.on("load", async () => {
2083
+
2084
+
2085
+ // this.map.on("load", async () => {
2051
2086
  const fc = { type: "FeatureCollection", features: [] };
2052
2087
  for await (const f of flatgeobuf.deserialize(response.body))
2088
+
2053
2089
  fc.features.push(f);
2054
- let src = op.name + "-source";
2090
+
2091
+ // console.log('ffff', fc, response)
2092
+
2093
+ let src = name + "-source";
2055
2094
 
2056
2095
  this.map.addSource(src, {
2057
2096
  type: "geojson",
2058
2097
  data: fc,
2059
2098
  });
2099
+
2100
+ if (layerUrl.includes('text')){
2101
+ // console.log('entro', name)
2102
+ this.map.addLayer({
2103
+ id: name + "-text",
2104
+ type: "symbol",
2105
+ source: src,
2106
+ layout:{
2107
+ "text-letter-spacing":0.1,
2108
+ "text-size":{"base":1.2,"stops":[[8,0],[12,14],[15,15]]},
2109
+ "text-font":["FiraSans-Regular"],
2110
+ "text-field":["get","NOM_AC"],
2111
+ "text-transform":"none",
2112
+ "text-max-width":25,
2113
+ "visibility":"visible",
2114
+ "text-justify":"right",
2115
+ "text-anchor":"top",
2116
+ "text-allow-overlap":false,
2117
+ "symbol-spacing":2,
2118
+ "text-line-height":1},
2119
+ paint:{"text-halo-blur":0.5,"text-color":"rgba(90, 7, 7, 1)","text-halo-width":2,"text-halo-color":"rgba(255, 255, 255,0.8)"}
2120
+ });
2121
+ }else{
2060
2122
  this.map.addLayer({
2061
- id: op.name + "-fill",
2123
+ id: name + "-fill",
2062
2124
  type: "fill",
2063
2125
  source: src,
2064
2126
  paint: {
@@ -2067,16 +2129,28 @@ geojson.features.forEach(feature => {
2067
2129
  },
2068
2130
  });
2069
2131
  this.map.addLayer({
2070
- id: op.name + "-line",
2132
+ id: name + "-underline",
2071
2133
  type: "line",
2072
2134
  source: src,
2073
2135
  paint: {
2074
- "line-color": "#FFFFFF",
2075
- "line-opacity": 0.49,
2136
+ "line-color": "#ffffff",
2137
+ "line-opacity": 1,
2138
+ "line-width": 3,
2139
+ },
2140
+ });
2141
+ this.map.addLayer({
2142
+ id: name + "-line",
2143
+ type: "line",
2144
+ source: src,
2145
+ paint: {
2146
+ "line-color": "#4832a8",
2147
+ "line-opacity": 1,
2076
2148
  "line-width": 1,
2077
2149
  },
2078
2150
  });
2079
- });
2151
+ }
2152
+
2153
+ // });
2080
2154
  }
2081
2155
  } catch (error) {
2082
2156
  console.error(`Error adding ICGC vector layer: ${error.message}`);
@@ -2090,7 +2164,7 @@ geojson.features.forEach(feature => {
2090
2164
  * @param {string} [positionButton='top-right'] - Position to add the button on the map.
2091
2165
  */
2092
2166
  addTerrainICGC(resolution, positionButton) {
2093
- this.map.on("load", () => {
2167
+ // this.map.on("load", () => {
2094
2168
  try {
2095
2169
  // let op = Terrains.find(
2096
2170
  // (objeto) => objeto.name === resolution
@@ -2155,6 +2229,6 @@ if (resolution.includes('terrarium') ){
2155
2229
  } catch (error) {
2156
2230
  console.error(`Error adding 3D terrain: ${error.message}`);
2157
2231
  }
2158
- }); //'load end
2232
+ // }); //'load end
2159
2233
  }
2160
2234
  }