@foodmarketmaker/mapag 0.0.24 → 0.0.25

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.
@@ -277,7 +277,8 @@ class TableRow {
277
277
  }
278
278
  }
279
279
 
280
- const DEFAULT_GLYPHS = "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer/resources/fonts/{fontstack}/{range}.pbf";
280
+ const DEFAULT_GLYPHS2 = "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer/resources/fonts/{fontstack}/{range}.pbf";
281
+ const DEFAULT_GLYPHS = "https://demotiles.maplibre.org/font/{fontstack}/{range}.pbf";
281
282
  // export const DEFAULT_GLYPHS = "'https://geoserveis.icgc.cat/contextmaps/glyphs/{fontstack}/{range}.pbf';"
282
283
  class Styles {
283
284
  style = signal(MapStyles["streetmap"], ...(ngDevMode ? [{ debugName: "style" }] : []));
@@ -350,6 +351,7 @@ class Styles {
350
351
  }
351
352
  const styleSpec = await response.json();
352
353
  console.debug("Glyphs property:", styleSpec.glyphs);
354
+ // Only set a default glyphs URL when the fetched style doesn't include one.
353
355
  if (!styleSpec.glyphs) {
354
356
  styleSpec.glyphs = DEFAULT_GLYPHS;
355
357
  }
@@ -14194,9 +14196,6 @@ class MapComponent {
14194
14196
  async initializeMap() {
14195
14197
  this.zone.runOutsideAngular(async () => {
14196
14198
  const container = this.mapContainer();
14197
- // let style =
14198
- // 'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json';
14199
- // // style = 'https://demotiles.maplibre.org/style.json'
14200
14199
  let style = await this.styles.FetchStyleDefinition(this.styles.style());
14201
14200
  if (container) {
14202
14201
  // @ts-ignore - Type conflict between different maplibre-gl versions
@@ -16205,6 +16204,369 @@ const Codes = [
16205
16204
  return (a.Category + ' - ' + a.Name).localeCompare(b.Category + ' - ' + b.Name);
16206
16205
  });
16207
16206
 
16207
+ class RailroadsMapper {
16208
+ static PMTILES = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/railroads.pmtiles';
16209
+ LINE_LAYER_ID = 'ust-railroads-layer-line';
16210
+ LABEL_LAYER_ID = 'ust-railroads-layer-label';
16211
+ SOURCE_ID = 'ust-railroads-source';
16212
+ SOURCE_LAYER = 'railroads';
16213
+ settings = signal(new RailroadSettings(), ...(ngDevMode ? [{ debugName: "settings" }] : []));
16214
+ current = null;
16215
+ currentFeatureID = undefined;
16216
+ over = signal(null, ...(ngDevMode ? [{ debugName: "over" }] : []));
16217
+ constructor(settings) {
16218
+ if (settings) {
16219
+ this.settings.set({
16220
+ ...this.settings(),
16221
+ ...settings
16222
+ });
16223
+ }
16224
+ const _ = effect(() => {
16225
+ const settings = this.settings();
16226
+ this._update(settings);
16227
+ }, ...(ngDevMode ? [{ debugName: "_" }] : []));
16228
+ }
16229
+ update(settings) {
16230
+ this.settings.set({ ...this.settings(), ...settings });
16231
+ }
16232
+ updateUsageSettings(key, usageSettings) {
16233
+ const s = this.settings();
16234
+ s[key] = { ...s[key], ...usageSettings };
16235
+ this.settings.set({ ...s });
16236
+ }
16237
+ _update(settings) {
16238
+ if (!this.map) {
16239
+ return;
16240
+ }
16241
+ const map = this.map;
16242
+ if (settings.visible) {
16243
+ map.setLayoutProperty(this.LINE_LAYER_ID, 'visibility', 'visible');
16244
+ }
16245
+ else {
16246
+ map.setLayoutProperty(this.LINE_LAYER_ID, 'visibility', 'none');
16247
+ }
16248
+ this.filterByUsage();
16249
+ map.setPaintProperty(this.LINE_LAYER_ID, 'line-color', this.lineColorSteps());
16250
+ map.setPaintProperty(this.LINE_LAYER_ID, 'line-width', this.lineWidthSteps());
16251
+ map.setPaintProperty(this.LINE_LAYER_ID, 'line-opacity', this.lineOpacitySteps());
16252
+ const labelsVisible = settings.visible && settings.labelsVisible;
16253
+ map.setLayoutProperty(this.LABEL_LAYER_ID, 'visibility', labelsVisible ? 'visible' : 'none');
16254
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-color', settings.labelsColor);
16255
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-halo-color', settings.labelsHaloColor);
16256
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-halo-width', settings.labelsHaloWidth);
16257
+ map.setPaintProperty(this.LABEL_LAYER_ID, 'text-opacity', settings.labelsOpacity);
16258
+ map.setLayoutProperty(this.LABEL_LAYER_ID, 'text-size', settings.labelsSize);
16259
+ map.setLayoutProperty(this.LABEL_LAYER_ID, 'text-allow-overlap', settings.labelOverlap);
16260
+ this.legends = this.getLegends();
16261
+ }
16262
+ create() {
16263
+ if (!this.map) {
16264
+ return;
16265
+ }
16266
+ const map = this.map;
16267
+ let PMTILES_URL = RailroadsMapper.PMTILES;
16268
+ AddSource(map, this.SOURCE_ID, {
16269
+ type: 'vector',
16270
+ url: PMTILES_URL,
16271
+ });
16272
+ const added = AddLayer(map, {
16273
+ id: this.LINE_LAYER_ID,
16274
+ source: this.SOURCE_ID,
16275
+ "source-layer": this.SOURCE_LAYER,
16276
+ type: 'line',
16277
+ }, StandardLayersMapper.POLYGONS_BACKGROUND);
16278
+ // Add labels (symbol) layer only if the style exposes a glyphs endpoint.
16279
+ // Some raster-only styles (or styles lacking a `glyphs` URL) will cause
16280
+ // MapLibre to attempt to fetch glyph PBFs from an undefined/invalid URL
16281
+ // which can produce PBF parsing errors (eg. "Unimplemented type: 3").
16282
+ const style = map.getStyle && map.getStyle();
16283
+ const hasGlyphs = !!(style && style.glyphs);
16284
+ if (hasGlyphs) {
16285
+ AddLayer(map, {
16286
+ id: this.LABEL_LAYER_ID,
16287
+ source: this.SOURCE_ID,
16288
+ "source-layer": this.SOURCE_LAYER,
16289
+ type: 'symbol',
16290
+ layout: {
16291
+ 'text-field': ['get', 'name'],
16292
+ 'text-font': ['Open Sans Semibold'], //,'Open Sans Regular'
16293
+ 'text-size': this.settings().labelsSize,
16294
+ 'text-allow-overlap': this.settings().labelOverlap,
16295
+ },
16296
+ paint: {
16297
+ 'text-color': this.settings().labelsColor,
16298
+ 'text-halo-color': this.settings().labelsHaloColor,
16299
+ 'text-halo-width': this.settings().labelsHaloWidth,
16300
+ },
16301
+ }, StandardLayersMapper.POLYGONS_BACKGROUND);
16302
+ }
16303
+ else {
16304
+ console.warn('RailroadsMapper: style has no `glyphs` URL — skipping labels layer to avoid PBF/glyph parse errors. Switch to a style with glyphs to enable labels.');
16305
+ }
16306
+ this._update(this.settings());
16307
+ if (!added) {
16308
+ return;
16309
+ }
16310
+ map.on('click', this.LINE_LAYER_ID, (e) => {
16311
+ // Publish
16312
+ this.over.set(e.features && e.features.length > 0 ? e.features[0] : null);
16313
+ if (e.features && e.features.length > 0) {
16314
+ const feature = e.features[0];
16315
+ const coordinates = e.lngLat;
16316
+ if (this.popup) {
16317
+ this.popup.remove();
16318
+ }
16319
+ const name = feature.properties['name'];
16320
+ const tb = new TableBuilder();
16321
+ tb.add('Length', this.fmtDistance(feature.properties['lengthkm']));
16322
+ tb.add('Owner', feature.properties['railowner'] ?? '');
16323
+ tb.add('Owner Code', feature.properties['railownercode'] ?? '');
16324
+ tb.add('Usage', this.usageLabel(feature.properties['railusage'] ?? 0));
16325
+ tb.add('Source', feature.properties['source_datadesc'] ?? '');
16326
+ tb.add('Originator', feature.properties['source_originator'] ?? '');
16327
+ tb.add('Load Date', feature.properties['loaddate'] ?? '');
16328
+ const fieldsHtml = tb.toHtml();
16329
+ let html = "";
16330
+ if (name) {
16331
+ html += `<strong>${name}</strong><br/>`;
16332
+ }
16333
+ html += fieldsHtml;
16334
+ this.currentFeatureID = feature?.properties?.['globalid'];
16335
+ this.popup = new Popup({ maxWidth: '400px' })
16336
+ .setLngLat(coordinates)
16337
+ .setHTML(html)
16338
+ .addTo(map);
16339
+ }
16340
+ });
16341
+ }
16342
+ fmtDistance(km) {
16343
+ if (!km) {
16344
+ return "";
16345
+ }
16346
+ return km.toFixed(1) + ' km / ' + (km * 0.621371).toFixed(1) + ' mi';
16347
+ }
16348
+ async onReady(map, svc) {
16349
+ this.map = map;
16350
+ this.create();
16351
+ }
16352
+ reset() { }
16353
+ clear() {
16354
+ if (this.map) {
16355
+ this.map.removeLayer(this.LINE_LAYER_ID);
16356
+ this.map.removeLayer(this.LABEL_LAYER_ID);
16357
+ this.map.removeSource(this.SOURCE_ID);
16358
+ }
16359
+ }
16360
+ filterByUsage() {
16361
+ if (!this.map) {
16362
+ return;
16363
+ }
16364
+ const map = this.map;
16365
+ if (!map.getLayer(this.LINE_LAYER_ID)) {
16366
+ return;
16367
+ }
16368
+ const settings = this.settings();
16369
+ if (!settings.perUsageDisplay) {
16370
+ this.map.setFilter(this.LINE_LAYER_ID, null);
16371
+ return;
16372
+ }
16373
+ map.setFilter(this.LINE_LAYER_ID, [
16374
+ "match",
16375
+ ["get", "railusage"],
16376
+ "F", settings.freight.visible,
16377
+ "P", settings.passenger.visible,
16378
+ "M", settings.mixed.visible,
16379
+ "I", settings.inactive.visible,
16380
+ "O", settings.other.visible,
16381
+ "Y", settings.yard.visible,
16382
+ "U", settings.unknown.visible,
16383
+ false
16384
+ ]);
16385
+ }
16386
+ lineColorSteps() {
16387
+ const settings = this.settings();
16388
+ if (!settings.perUsageDisplay) {
16389
+ return settings.lineColor;
16390
+ }
16391
+ return [
16392
+ "match",
16393
+ ["get", "railusage"],
16394
+ "F", settings.freight.lineColor, // Freight = blue
16395
+ "P", settings.passenger.lineColor, // Passenger = orange
16396
+ "M", settings.mixed.lineColor, // Both = green
16397
+ "I", settings.inactive.lineColor, // Inactive = gray
16398
+ "O", settings.other.lineColor, // Other = red
16399
+ "Y", settings.yard.lineColor, // Yard = purple
16400
+ "U", settings.unknown.lineColor, // Unknown = brown
16401
+ "#000000" // Default = black
16402
+ ];
16403
+ }
16404
+ lineOpacitySteps() {
16405
+ const settings = this.settings();
16406
+ if (!settings.perUsageDisplay) {
16407
+ return settings.lineOpacity;
16408
+ }
16409
+ return [
16410
+ "match",
16411
+ ["get", "railusage"],
16412
+ "F", settings.freight.lineOpacity, // Freight = blue
16413
+ "P", settings.passenger.lineOpacity, // Passenger = orange
16414
+ "M", settings.mixed.lineOpacity, // Both = green
16415
+ "I", settings.inactive.lineOpacity, // Inactive = gray
16416
+ "O", settings.other.lineOpacity, // Other = red
16417
+ "Y", settings.yard.lineOpacity, // Yard = purple
16418
+ "U", settings.unknown.lineOpacity, // Unknown = brown
16419
+ settings.lineOpacity // Default = black
16420
+ ];
16421
+ }
16422
+ lineWidthSteps() {
16423
+ const settings = this.settings();
16424
+ if (!settings.perUsageDisplay) {
16425
+ return settings.lineWidth;
16426
+ }
16427
+ return [
16428
+ "match",
16429
+ ["get", "railusage"],
16430
+ "F", settings.freight.lineWidth, // Freight = blue
16431
+ "P", settings.passenger.lineWidth, // Passenger = orange
16432
+ "M", settings.mixed.lineWidth, // Both = green
16433
+ "I", settings.inactive.lineWidth, // Inactive = gray
16434
+ "O", settings.other.lineWidth, // Other = red
16435
+ "Y", settings.yard.lineWidth, // Yard = purple
16436
+ "U", settings.unknown.lineWidth, // Unknown = brown
16437
+ settings.lineWidth // Default = black
16438
+ ];
16439
+ }
16440
+ usageLabel(usage) {
16441
+ switch (usage) {
16442
+ case "F":
16443
+ return "Freight rail line";
16444
+ case "P":
16445
+ return "Passenger rail line";
16446
+ case "M":
16447
+ return "Mixed use (freight and passenger)";
16448
+ case "O":
16449
+ return "Other (yard, spur, industrial, or special use)";
16450
+ case "I":
16451
+ return "Inactive or abandoned";
16452
+ case "Y":
16453
+ return "Yard tracks";
16454
+ case "U":
16455
+ return "Unknown or unspecified";
16456
+ default:
16457
+ return `Unrecognized code (${usage})`;
16458
+ }
16459
+ }
16460
+ getLegends() {
16461
+ const settings = this.settings();
16462
+ const items = [];
16463
+ if (!settings.perUsageDisplay) {
16464
+ items.push({
16465
+ value: settings.lineColor,
16466
+ label: 'Railroads',
16467
+ });
16468
+ }
16469
+ else {
16470
+ items.push({ value: settings.freight.lineColor, label: settings.freight.description });
16471
+ items.push({ value: settings.passenger.lineColor, label: settings.passenger.description });
16472
+ items.push({ value: settings.mixed.lineColor, label: settings.mixed.description });
16473
+ items.push({ value: settings.inactive.lineColor, label: settings.inactive.description });
16474
+ items.push({ value: settings.other.lineColor, label: settings.other.description });
16475
+ items.push({ value: settings.yard.lineColor, label: settings.yard.description });
16476
+ items.push({ value: settings.unknown.lineColor, label: settings.unknown.description });
16477
+ }
16478
+ const l = {
16479
+ title: 'Railroads',
16480
+ items: items
16481
+ };
16482
+ // Implementation for generating legends based on settings
16483
+ return [l];
16484
+ }
16485
+ legends;
16486
+ count = 0;
16487
+ total = 0;
16488
+ map;
16489
+ popup = null;
16490
+ }
16491
+ class RailroadSettings {
16492
+ perUsageDisplay = false;
16493
+ visible = true;
16494
+ lineColor = '#000000';
16495
+ lineWidth = 1;
16496
+ lineOpacity = 0.5;
16497
+ labelsVisible = false;
16498
+ labelsSize = 10;
16499
+ labelsColor = '#000000';
16500
+ labelsHaloColor = '#ffffff';
16501
+ labelsHaloWidth = 1;
16502
+ labelsOpacity = 1.0;
16503
+ labelOverlap = false;
16504
+ freight = {
16505
+ code: "F",
16506
+ description: "Freight rail line",
16507
+ visible: true,
16508
+ lineColor: "#1f77b4",
16509
+ lineWidth: 2,
16510
+ lineOpacity: 0.8
16511
+ };
16512
+ passenger = {
16513
+ code: "P",
16514
+ description: "Passenger rail line",
16515
+ visible: true,
16516
+ lineColor: "#ff7f0e",
16517
+ lineWidth: 2,
16518
+ lineOpacity: 0.8
16519
+ };
16520
+ mixed = {
16521
+ code: "M",
16522
+ description: "Mixed use (freight and passenger)",
16523
+ visible: true,
16524
+ lineColor: "#2ca02c",
16525
+ lineWidth: 2,
16526
+ lineOpacity: 0.8
16527
+ };
16528
+ inactive = {
16529
+ code: "I",
16530
+ description: "Inactive or abandoned",
16531
+ visible: false,
16532
+ lineColor: "#7f7f7f",
16533
+ lineWidth: 2,
16534
+ lineOpacity: 0.5
16535
+ };
16536
+ other = {
16537
+ code: "O",
16538
+ description: "Other (yard, spur, industrial, or special use)",
16539
+ visible: true,
16540
+ lineColor: "#d62728",
16541
+ lineWidth: 2,
16542
+ lineOpacity: 0.5
16543
+ };
16544
+ yard = {
16545
+ code: "Y",
16546
+ description: "Yard tracks",
16547
+ visible: true,
16548
+ lineColor: "#9467bd",
16549
+ lineWidth: 2,
16550
+ lineOpacity: 0.5
16551
+ };
16552
+ unknown = {
16553
+ code: "U",
16554
+ description: "Unknown or unspecified",
16555
+ visible: false,
16556
+ lineColor: "#8c564b",
16557
+ lineWidth: 2,
16558
+ lineOpacity: 0.5
16559
+ };
16560
+ }
16561
+ class RailroadUsageSettings {
16562
+ code = "";
16563
+ description = "";
16564
+ visible = true;
16565
+ lineColor = '#000000';
16566
+ lineWidth = 1;
16567
+ lineOpacity = 0.5;
16568
+ }
16569
+
16208
16570
  class SimpleMapper {
16209
16571
  reset() {
16210
16572
  if (this.map) {
@@ -16478,7 +16840,8 @@ class WatershedMapper {
16478
16840
  type: 'symbol',
16479
16841
  layout: {
16480
16842
  'text-field': ['get', 'name'],
16481
- 'text-font': ['Open Sans Regular'],
16843
+ // 'text-font': ['Open Sans Regular'],
16844
+ 'text-font': ['Open Sans Semibold'], //,'Open Sans Regular'
16482
16845
  'text-size': this.settings().labelsSize,
16483
16846
  'text-allow-overlap': this.settings().labelOverlap,
16484
16847
  },
@@ -16742,5 +17105,5 @@ class HttpBoundaryLoader {
16742
17105
  * Generated bundle index. Do not edit.
16743
17106
  */
16744
17107
 
16745
- export { AddLayer, AddSource, AreaMapperMapper, BackgroundMaskMapper, BackgroundMaskSettings, BaseMapLight, BasemapSelect, BasemapSelectMenu, CensusTractMapper, Codes, CropSequenceMapper, CropSequenceSettings, CroplandDataLayerMapper, CroplandDataLayerSettings, CroplandLegend, DEFAULT_GLYPHS, DrawingMapper, EsriMapper, EsriSettings, HardinessMapper, HardinessSettings, HttpBoundaryLoader, MapAreaSelectComponent, MapComponent, MapSelectionService, MapService, MapStyles, MapboxMapperGroup, NAASMapper, NAASSettings, NaicsMapper, NaicsMapperSettings, NoOpMapper, RemoveLayer, RemoveSource, SaveMap, SelectMode, SimpleMapper, StandardLayersMapper, Styles, TableBuilder, TableRow, VectorTileServerMapper, WatershedMapper, WatershedSettings, discoverLayers, isGeoloader, isMultiPolygon, isNumber2DArray, isNumber3DArray, isPolygon, mapboxLoadImages, mapboxloadImage, pmtilesPixelInfo, propertiesToTableHtml, sampleTilesForLayers, simpleClone, toMultiPolygon, trySync };
17108
+ export { AddLayer, AddSource, AreaMapperMapper, BackgroundMaskMapper, BackgroundMaskSettings, BaseMapLight, BasemapSelect, BasemapSelectMenu, CensusTractMapper, Codes, CropSequenceMapper, CropSequenceSettings, CroplandDataLayerMapper, CroplandDataLayerSettings, CroplandLegend, DEFAULT_GLYPHS, DEFAULT_GLYPHS2, DrawingMapper, EsriMapper, EsriSettings, HardinessMapper, HardinessSettings, HttpBoundaryLoader, MapAreaSelectComponent, MapComponent, MapSelectionService, MapService, MapStyles, MapboxMapperGroup, NAASMapper, NAASSettings, NaicsMapper, NaicsMapperSettings, NoOpMapper, RailroadSettings, RailroadUsageSettings, RailroadsMapper, RemoveLayer, RemoveSource, SaveMap, SelectMode, SimpleMapper, StandardLayersMapper, Styles, TableBuilder, TableRow, VectorTileServerMapper, WatershedMapper, WatershedSettings, discoverLayers, isGeoloader, isMultiPolygon, isNumber2DArray, isNumber3DArray, isPolygon, mapboxLoadImages, mapboxloadImage, pmtilesPixelInfo, propertiesToTableHtml, sampleTilesForLayers, simpleClone, toMultiPolygon, trySync };
16746
17109
  //# sourceMappingURL=foodmarketmaker-mapag.mjs.map