@foodmarketmaker/mapag 0.0.10 → 0.0.11

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.
@@ -225,7 +225,10 @@ class Styles {
225
225
  return;
226
226
  }
227
227
  // Fetch and cache the style definition if not already cached
228
- await this.fetchAndCacheStyle(styleData);
228
+ const styleSpec = await this.fetchAndCacheStyle(styleData);
229
+ if (!styleSpec) {
230
+ return;
231
+ }
229
232
  this.saveCustomSourcesAndLayers();
230
233
  this.map.once("styledata", () => {
231
234
  setTimeout(() => {
@@ -235,13 +238,23 @@ class Styles {
235
238
  this.restoreCustomSourcesAndLayers();
236
239
  }, 100);
237
240
  });
238
- this.map.setStyle(styleData.url);
241
+ // this.map.setStyle(styleData.url);
242
+ this.map.setStyle(styleSpec);
239
243
  this.style.set(styleData);
240
244
  this.currentStyleCode = styleData.code;
241
245
  if (this.onStyleChange) {
242
246
  this.onStyleChange(styleData);
243
247
  }
244
248
  }
249
+ async FetchStyleDefinition(styleData) {
250
+ const response = await fetch(styleData.url);
251
+ if (!response.ok) {
252
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
253
+ }
254
+ const styleSpec = await response.json();
255
+ styleSpec.glyphs = 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf';
256
+ return styleSpec;
257
+ }
245
258
  async fetchAndCacheStyle(styleData) {
246
259
  // Skip if already cached
247
260
  if (this.styleCache[styleData.code]) {
@@ -258,6 +271,10 @@ class Styles {
258
271
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
259
272
  }
260
273
  const styleSpec = await response.json();
274
+ // Add Glyphs
275
+ if (!styleSpec.glyphs) {
276
+ styleSpec.glyphs = 'https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf';
277
+ }
261
278
  // Extract source and layer IDs
262
279
  const sourceIds = Object.keys(styleSpec.sources || {});
263
280
  const layerIds = (styleSpec.layers || []).map((layer) => layer.id);
@@ -268,6 +285,7 @@ class Styles {
268
285
  layers: layerIds
269
286
  };
270
287
  this.styleCache[styleData.code] = enhancedStyleData;
288
+ return styleSpec;
271
289
  }
272
290
  catch (error) {
273
291
  console.error('Failed to fetch style definition for:', styleData.code, ':', error);
@@ -14082,17 +14100,20 @@ class MapComponent {
14082
14100
  ngOnDestroy() {
14083
14101
  this.styles.destroy();
14084
14102
  }
14085
- initializeMap() {
14086
- this.zone.runOutsideAngular(() => {
14103
+ async initializeMap() {
14104
+ this.zone.runOutsideAngular(async () => {
14087
14105
  const container = this.mapContainer();
14088
- let style = 'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json';
14089
- // style = 'https://demotiles.maplibre.org/style.json'
14106
+ // let style =
14107
+ // 'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json';
14108
+ // // style = 'https://demotiles.maplibre.org/style.json'
14109
+ let style = await this.styles.FetchStyleDefinition(this.styles.style());
14090
14110
  if (container) {
14091
14111
  // @ts-ignore - Type conflict between different maplibre-gl versions
14092
14112
  const map = new maplibregl.Map({
14093
14113
  container: container.nativeElement,
14094
14114
  // style: this.basemap(),
14095
- style: this.styles.style().url, // Default style
14115
+ // style: this.styles.style().url, // Default style
14116
+ style: style, // Default style
14096
14117
  center: [-98, 38.88],
14097
14118
  minZoom: 1,
14098
14119
  zoom: 3,
@@ -14898,10 +14919,18 @@ class VectorTileServerMapper {
14898
14919
  // }
14899
14920
 
14900
14921
  class WatershedMapper {
14922
+ static WBDHU2 = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/WBDHU2.pmtiles';
14923
+ static WBDHU4 = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/WBDHU4.pmtiles';
14924
+ static WBDHU6 = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/watershedhu6.pmtiles';
14925
+ static WBDHU8 = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/WBDHU8.pmtiles';
14926
+ static WBDHU10 = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/WBDHU10.pmtiles';
14927
+ static WBDHU12 = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/WBDHU12.pmtiles';
14901
14928
  FILL_LAYER_ID = 'watershed-layer';
14902
14929
  LINE_LAYER_ID = 'watershed-layer-line';
14930
+ LABEL_LAYER_ID = 'watershed-layer-label';
14903
14931
  SOURCE_ID = 'watershedSource';
14904
14932
  SOURCE_LAYER = 'watershedhu6';
14933
+ currentHU = 'HUC6';
14905
14934
  settings = signal(new WatershedSettings(), ...(ngDevMode ? [{ debugName: "settings" }] : []));
14906
14935
  current = null;
14907
14936
  currentFeatureID = undefined;
@@ -14926,6 +14955,11 @@ class WatershedMapper {
14926
14955
  return;
14927
14956
  }
14928
14957
  const map = this.map;
14958
+ if (this.currentHU !== settings.hydrologicUnit) {
14959
+ this.clear();
14960
+ this.currentHU = settings.hydrologicUnit;
14961
+ this.create();
14962
+ }
14929
14963
  if (settings.visible) {
14930
14964
  map.setLayoutProperty(this.FILL_LAYER_ID, 'visibility', 'visible');
14931
14965
  map.setLayoutProperty(this.LINE_LAYER_ID, 'visibility', 'visible');
@@ -14939,13 +14973,47 @@ class WatershedMapper {
14939
14973
  map.setPaintProperty(this.LINE_LAYER_ID, 'line-color', settings.borderColor);
14940
14974
  map.setPaintProperty(this.LINE_LAYER_ID, 'line-width', settings.borderWidth);
14941
14975
  map.setPaintProperty(this.LINE_LAYER_ID, 'line-opacity', settings.borderOpacity);
14976
+ map.setLayoutProperty(this.LABEL_LAYER_ID, 'visibility', settings.labelsVisible ? 'visible' : 'none');
14977
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-size', settings.labelsSize);
14978
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-color', settings.labelsColor);
14979
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-halo-color', settings.labelsHaloColor);
14980
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-halo-width', settings.labelsHaloWidth);
14942
14981
  }
14943
14982
  create() {
14944
14983
  if (!this.map) {
14945
14984
  return;
14946
14985
  }
14947
14986
  const map = this.map;
14948
- const PMTILES_URL = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/watershedhu6.pmtiles';
14987
+ let PMTILES_URL = WatershedMapper.WBDHU6;
14988
+ switch (this.settings().hydrologicUnit) {
14989
+ case 'HUC2':
14990
+ PMTILES_URL = WatershedMapper.WBDHU2;
14991
+ this.SOURCE_LAYER = 'WBDHU2';
14992
+ break;
14993
+ case 'HUC4':
14994
+ PMTILES_URL = WatershedMapper.WBDHU4;
14995
+ this.SOURCE_LAYER = 'WBDHU4';
14996
+ break;
14997
+ case 'HUC6':
14998
+ PMTILES_URL = WatershedMapper.WBDHU6;
14999
+ this.SOURCE_LAYER = 'watershedhu6';
15000
+ break;
15001
+ case 'HUC8':
15002
+ PMTILES_URL = WatershedMapper.WBDHU8;
15003
+ this.SOURCE_LAYER = 'WBDHU8';
15004
+ break;
15005
+ case 'HUC10':
15006
+ PMTILES_URL = WatershedMapper.WBDHU10;
15007
+ this.SOURCE_LAYER = 'WBDHU10';
15008
+ break;
15009
+ case 'HUC12':
15010
+ PMTILES_URL = WatershedMapper.WBDHU12;
15011
+ this.SOURCE_LAYER = 'WBDHU12';
15012
+ break;
15013
+ default:
15014
+ PMTILES_URL = WatershedMapper.WBDHU6;
15015
+ this.SOURCE_LAYER = 'watershedhu6';
15016
+ }
14949
15017
  AddSource(map, this.SOURCE_ID, {
14950
15018
  type: 'vector',
14951
15019
  url: PMTILES_URL,
@@ -14963,6 +15031,15 @@ class WatershedMapper {
14963
15031
  "source-layer": this.SOURCE_LAYER,
14964
15032
  type: 'line',
14965
15033
  }, StandardLayersMapper.POLYGONS_BACKGROUND);
15034
+ AddLayer(map, {
15035
+ id: this.LABEL_LAYER_ID,
15036
+ source: this.SOURCE_ID,
15037
+ "source-layer": this.SOURCE_LAYER,
15038
+ type: 'symbol',
15039
+ layout: {
15040
+ 'text-field': ['get', 'name'],
15041
+ },
15042
+ }, StandardLayersMapper.POLYGONS_BACKGROUND);
14966
15043
  this._update(this.settings());
14967
15044
  if (!addedFill) {
14968
15045
  return;
@@ -15006,6 +15083,7 @@ class WatershedMapper {
15006
15083
  if (this.map) {
15007
15084
  this.map.removeLayer(this.FILL_LAYER_ID);
15008
15085
  this.map.removeLayer(this.LINE_LAYER_ID);
15086
+ this.map.removeLayer(this.LABEL_LAYER_ID);
15009
15087
  this.map.removeSource(this.SOURCE_ID);
15010
15088
  }
15011
15089
  }
@@ -15016,12 +15094,18 @@ class WatershedMapper {
15016
15094
  popup = null;
15017
15095
  }
15018
15096
  class WatershedSettings {
15097
+ hydrologicUnit = 'HUC6';
15019
15098
  visible = true;
15020
15099
  fillColor = '#0000ff';
15021
15100
  fillOpacity = 0.1;
15022
15101
  borderColor = '#01018bff';
15023
15102
  borderWidth = 1;
15024
15103
  borderOpacity = 1.0;
15104
+ labelsVisible = true;
15105
+ labelsSize = 12;
15106
+ labelsColor = '#000000';
15107
+ labelsHaloColor = '#ffffff';
15108
+ labelsHaloWidth = 1;
15025
15109
  }
15026
15110
 
15027
15111
  class HttpBoundaryLoader {