@foodmarketmaker/mapag 0.0.21 → 0.0.23

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.
@@ -228,6 +228,54 @@ async function pmtilesPixelInfo(url, map, e) {
228
228
  // const a = pixel[3];
229
229
  return pixel;
230
230
  }
231
+ function propertiesToTableHtml(properties) {
232
+ let html = '<table style="border-collapse: collapse; width: 100%; border: none; font-size: 9px;">';
233
+ for (const key in properties) {
234
+ if (properties.hasOwnProperty(key)) {
235
+ html += `<tr>
236
+ <td style="padding: 2px; font-weight: bold;">${key}</td>
237
+ <td style="padding: 2px;">${properties[key]}</td>
238
+ </tr>`;
239
+ }
240
+ }
241
+ html += '</table>';
242
+ return html;
243
+ }
244
+ class TableBuilder {
245
+ rows = [];
246
+ headerStyle = `style="padding: 2px; padding-top:6ps; font-size: 9px; font-weight: bold;"`;
247
+ rowStyle1 = `style="padding: 2px; font-size: 9px; font-weight: bold;"`;
248
+ rowStyle2 = `style="padding: 2px; font-size: 9px;`;
249
+ addHeader(...cells) {
250
+ this.rows.push(new TableRow(cells, true));
251
+ return this;
252
+ }
253
+ add(...cells) {
254
+ this.rows.push(new TableRow(cells));
255
+ return this;
256
+ }
257
+ toHtml() {
258
+ const rowHtml = this.rows.map(row => row.toHtml()).join('');
259
+ return `<table style="border-collapse: collapse; width: 100%; font-size: 9px;">${rowHtml}</table>`;
260
+ }
261
+ }
262
+ class TableRow {
263
+ isHeader;
264
+ cells;
265
+ headerStyle = `padding: 2px; padding-top:6px; font-size: 9px; font-weight: bold; text-align: left;`;
266
+ rowStyle1 = `padding: 2px; font-size: 9px; font-weight: bold;`;
267
+ rowStyle2 = `padding: 2px; font-size: 9px;`;
268
+ constructor(cells, isHeader = false) {
269
+ this.cells = cells;
270
+ this.isHeader = isHeader;
271
+ }
272
+ toHtml() {
273
+ if (this.isHeader) {
274
+ return `<tr>${this.cells.map(cell => `<th style="${this.headerStyle}">${cell}</th>`).join('\n')}</tr>`;
275
+ }
276
+ return `<tr>${this.cells.map((cell, index) => `<td style="${index == 0 ? this.rowStyle1 : this.rowStyle2}">${cell}</td>`).join('')}</tr>`;
277
+ }
278
+ }
231
279
 
232
280
  const DEFAULT_GLYPHS = "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer/resources/fonts/{fontstack}/{range}.pbf";
233
281
  // export const DEFAULT_GLYPHS = "'https://geoserveis.icgc.cat/contextmaps/glyphs/{fontstack}/{range}.pbf';"
@@ -15158,6 +15206,163 @@ Dbl Crop Barley/Soybeans 254 433 47.5% 52.5% 0.47
15158
15206
 
15159
15207
  */
15160
15208
 
15209
+ class CropSequenceMapper {
15210
+ static PMTILES = 'pmtiles://https://foodmarketmaker-upload-data.s3.us-west-2.amazonaws.com/tiles/NationalCSB_2017_2024_rev23.pmtiles';
15211
+ FILL_LAYER_ID = 'cropsequence-layer';
15212
+ LINE_LAYER_ID = 'cropsequence-layer-line';
15213
+ SOURCE_ID = 'cropsequence-source';
15214
+ SOURCE_LAYER = 'NationalCSB_2017_2024_rev23';
15215
+ settings = signal(new CropSequenceSettings(), ...(ngDevMode ? [{ debugName: "settings" }] : []));
15216
+ current = null;
15217
+ currentFeatureID = undefined;
15218
+ over = signal(null, ...(ngDevMode ? [{ debugName: "over" }] : []));
15219
+ constructor(settings) {
15220
+ if (settings) {
15221
+ this.settings.set({
15222
+ ...this.settings(),
15223
+ ...settings
15224
+ });
15225
+ }
15226
+ const _ = effect(() => {
15227
+ const settings = this.settings();
15228
+ this._update(settings);
15229
+ }, ...(ngDevMode ? [{ debugName: "_" }] : []));
15230
+ }
15231
+ update(settings) {
15232
+ this.settings.set({ ...this.settings(), ...settings });
15233
+ }
15234
+ _update(settings) {
15235
+ if (!this.map) {
15236
+ return;
15237
+ }
15238
+ const map = this.map;
15239
+ if (settings.visible) {
15240
+ map.setLayoutProperty(this.FILL_LAYER_ID, 'visibility', 'visible');
15241
+ map.setLayoutProperty(this.LINE_LAYER_ID, 'visibility', 'visible');
15242
+ }
15243
+ else {
15244
+ map.setLayoutProperty(this.FILL_LAYER_ID, 'visibility', 'none');
15245
+ map.setLayoutProperty(this.LINE_LAYER_ID, 'visibility', 'none');
15246
+ }
15247
+ map.setPaintProperty(this.FILL_LAYER_ID, 'fill-color', settings.fillColor);
15248
+ map.setPaintProperty(this.FILL_LAYER_ID, 'fill-opacity', settings.fillOpacity);
15249
+ map.setPaintProperty(this.LINE_LAYER_ID, 'line-color', settings.borderColor);
15250
+ map.setPaintProperty(this.LINE_LAYER_ID, 'line-width', settings.borderWidth);
15251
+ map.setPaintProperty(this.LINE_LAYER_ID, 'line-opacity', settings.borderOpacity);
15252
+ }
15253
+ create() {
15254
+ if (!this.map) {
15255
+ return;
15256
+ }
15257
+ const map = this.map;
15258
+ let PMTILES_URL = CropSequenceMapper.PMTILES;
15259
+ AddSource(map, this.SOURCE_ID, {
15260
+ type: 'vector',
15261
+ url: PMTILES_URL,
15262
+ });
15263
+ const addedFill = AddLayer(map, {
15264
+ id: this.FILL_LAYER_ID,
15265
+ source: this.SOURCE_ID,
15266
+ "source-layer": this.SOURCE_LAYER,
15267
+ type: 'fill',
15268
+ }, StandardLayersMapper.POLYGONS_BACKGROUND);
15269
+ AddLayer(map, {
15270
+ id: this.LINE_LAYER_ID,
15271
+ source: this.SOURCE_ID,
15272
+ "source-layer": this.SOURCE_LAYER,
15273
+ type: 'line',
15274
+ }, StandardLayersMapper.POLYGONS_BACKGROUND);
15275
+ this._update(this.settings());
15276
+ if (!addedFill) {
15277
+ return;
15278
+ }
15279
+ map.on('mousemove', this.FILL_LAYER_ID, (e) => {
15280
+ this.over.set(e.features && e.features.length > 0 ? e.features[0] : null);
15281
+ });
15282
+ map.on('click', this.FILL_LAYER_ID, (e) => {
15283
+ // Publish
15284
+ this.over.set(e.features && e.features.length > 0 ? e.features[0] : null);
15285
+ if (e.features && e.features.length > 0) {
15286
+ const feature = e.features[0];
15287
+ const coordinates = e.lngLat;
15288
+ if (this.popup) {
15289
+ this.popup.remove();
15290
+ }
15291
+ const tb = new TableBuilder();
15292
+ const crop2017 = this.lookupClass(feature.properties ? feature.properties['CDL2017'] : null);
15293
+ const crop2018 = this.lookupClass(feature.properties ? feature.properties['CDL2018'] : null);
15294
+ const crop2019 = this.lookupClass(feature.properties ? feature.properties['CDL2019'] : null);
15295
+ const crop2020 = this.lookupClass(feature.properties ? feature.properties['CDL2020'] : null);
15296
+ const crop2021 = this.lookupClass(feature.properties ? feature.properties['CDL2021'] : null);
15297
+ const crop2022 = this.lookupClass(feature.properties ? feature.properties['CDL2022'] : null);
15298
+ const crop2023 = this.lookupClass(feature.properties ? feature.properties['CDL2023'] : null);
15299
+ const crop2024 = this.lookupClass(feature.properties ? feature.properties['CDL2024'] : null);
15300
+ tb.addHeader('Year', 'Crop Type');
15301
+ tb.add('2024', crop2024 ?? 'Unknown');
15302
+ tb.add('2023', crop2023 ?? 'Unknown');
15303
+ tb.add('2022', crop2022 ?? 'Unknown');
15304
+ tb.add('2021', crop2021 ?? 'Unknown');
15305
+ tb.add('2020', crop2020 ?? 'Unknown');
15306
+ tb.add('2019', crop2019 ?? 'Unknown');
15307
+ tb.add('2018', crop2018 ?? 'Unknown');
15308
+ tb.add('2017', crop2017 ?? 'Unknown');
15309
+ tb.addHeader('Location', "");
15310
+ tb.add('State FIPS', feature.properties ? feature.properties['STATEFIPS'] : 'Unknown');
15311
+ tb.add('County', feature.properties ? feature.properties['CNTY'] : 'Unknown');
15312
+ tb.add('County FIPS', feature.properties ? feature.properties['CNTYFIPS'] : 'Unknown');
15313
+ tb.add('ASD', feature.properties ? feature.properties['ASD'] : 'Unknown');
15314
+ tb.add('Area (M²)', feature.properties ? feature.properties['Shape_Area'] : 'Unknown');
15315
+ const fieldsHtml = tb.toHtml();
15316
+ this.currentFeatureID = feature?.properties?.['globalid'];
15317
+ this.popup = new Popup({ maxWidth: '400px' })
15318
+ .setLngLat(coordinates)
15319
+ .setHTML(`<strong>Crop Sequence</strong><br/>${fieldsHtml}`)
15320
+ .addTo(map);
15321
+ }
15322
+ });
15323
+ }
15324
+ lookupClass(code) {
15325
+ const found = CroplandLegend.find((item) => {
15326
+ return item.code == code;
15327
+ });
15328
+ if (found) {
15329
+ return found.class;
15330
+ }
15331
+ return undefined;
15332
+ }
15333
+ lookup(code) {
15334
+ const found = CroplandLegend.find((item) => {
15335
+ return item.code == code;
15336
+ });
15337
+ return found;
15338
+ }
15339
+ async onReady(map, svc) {
15340
+ this.map = map;
15341
+ this.create();
15342
+ }
15343
+ reset() { }
15344
+ clear() {
15345
+ if (this.map) {
15346
+ this.map.removeLayer(this.FILL_LAYER_ID);
15347
+ this.map.removeLayer(this.LINE_LAYER_ID);
15348
+ this.map.removeSource(this.SOURCE_ID);
15349
+ }
15350
+ }
15351
+ legends;
15352
+ count = 0;
15353
+ total = 0;
15354
+ map;
15355
+ popup = null;
15356
+ }
15357
+ class CropSequenceSettings {
15358
+ visible = true;
15359
+ fillColor = '#1aac39';
15360
+ fillOpacity = 0.2;
15361
+ borderColor = '#006e16';
15362
+ borderWidth = 1;
15363
+ borderOpacity = 0.5;
15364
+ }
15365
+
15161
15366
  class EsriMapper {
15162
15367
  jsonUrl = 'https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer/resources/styles/root.json';
15163
15368
  SOURCE_ID = 'esri';
@@ -16573,5 +16778,5 @@ class HttpBoundaryLoader {
16573
16778
  * Generated bundle index. Do not edit.
16574
16779
  */
16575
16780
 
16576
- export { AddLayer, AddSource, AreaMapperMapper, BackgroundMaskMapper, BackgroundMaskSettings, BaseMapLight, BasemapSelect, BasemapSelectMenu, CensusTractMapper, Codes, 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, VectorTileServerMapper, WatershedMapper, WatershedSettings, discoverLayers, isGeoloader, isMultiPolygon, isNumber2DArray, isNumber3DArray, isPolygon, mapboxLoadImages, mapboxloadImage, pmtilesPixelInfo, sampleTilesForLayers, simpleClone, toMultiPolygon, trySync };
16781
+ 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 };
16577
16782
  //# sourceMappingURL=foodmarketmaker-mapag.mjs.map