@aguacerowx/mapsgl 0.0.58 → 0.0.59

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.
@@ -1,113 +1,113 @@
1
- // aguacero-api/src/style-applicator.js
2
- import { STYLE_LAYER_MAP } from './style-layer-map.js';
3
-
4
- function sanitizeColor(color) {
5
- if (typeof color === 'string' && color.startsWith('#') && color.length === 9) {
6
- // It's an 8-digit hex (#rrggbbaa), convert to 6-digit hex (#rrggbb)
7
- return color.substring(0, 7);
8
- }
9
- // Otherwise, the color is already in a valid format (e.g., #ffffff, rgba(...))
10
- return color;
11
- }
12
-
13
- const applyLineStyles = (map, layerId, styles) => {
14
- if (!map.getLayer(layerId)) return;
15
- map.setLayoutProperty(layerId, 'visibility', styles.visible ? 'visible' : 'none');
16
- // --- MODIFICATION: Sanitize the color ---
17
- map.setPaintProperty(layerId, 'line-color', sanitizeColor(styles.color));
18
- map.setPaintProperty(layerId, 'line-width', styles.width);
19
- if (styles.lineType) {
20
- const dashArray = { 'dashed': [2, 2], 'dotted': [0, 2], 'solid': [] };
21
- map.setPaintProperty(layerId, 'line-dasharray', dashArray[styles.lineType] || []);
22
- }
23
- };
24
-
25
- // Helper to apply styles to a symbol (label) layer, now with color sanitization
26
- const applySymbolStyles = (map, layerId, styles) => {
27
- if (!map.getLayer(layerId)) return;
28
- map.setLayoutProperty(layerId, 'visibility', styles.visible ? 'visible' : 'none');
29
- // --- MODIFICATION: Sanitize both text and halo colors ---
30
- map.setPaintProperty(layerId, 'text-color', sanitizeColor(styles.color));
31
- map.setPaintProperty(layerId, 'text-halo-color', sanitizeColor(styles.outlineColor));
32
- map.setPaintProperty(layerId, 'text-halo-width', styles.outlineWidth);
33
- map.setLayoutProperty(layerId, 'text-size', styles.fontSize);
34
- map.setLayoutProperty(layerId, 'text-font', [styles.fontFamily]);
35
- };
36
-
37
- function applyPaintAndVisibility(map, layerId, property, styles) {
38
- if (!styles) return;
39
- if (!map.getLayer(layerId)) return;
40
- // --- MODIFICATION: Sanitize the color ---
41
- if (styles.color) map.setPaintProperty(layerId, property, sanitizeColor(styles.color));
42
- if (styles.visible !== undefined) map.setLayoutProperty(layerId, 'visibility', styles.visible ? 'visible' : 'none');
43
- }
44
-
45
- /**
46
- * Applies a comprehensive set of style customizations to the Mapbox map.
47
- * @param {mapboxgl.Map} map - The Mapbox map instance.
48
- * @param {object} customStyles - A style configuration object (e.g., defaultDarkMapStyles).
49
- */
50
- export function applyStyleCustomizations(map, customStyles) {
51
- if (!map || !map.isStyleLoaded()) return;
52
-
53
- // --- Land & Water ---
54
- if (customStyles.landOcean) {
55
- const { landColor, oceanColor, waterDepth, nationalPark } = customStyles.landOcean;
56
- // --- MODIFICATION: Sanitize the colors here too ---
57
- if (map.getLayer(STYLE_LAYER_MAP.landColor.layerId)) {
58
- map.setPaintProperty(STYLE_LAYER_MAP.landColor.layerId, 'background-color', sanitizeColor(landColor));
59
- }
60
- if (map.getLayer(STYLE_LAYER_MAP.oceanColor.layerId)) {
61
- map.setPaintProperty(STYLE_LAYER_MAP.oceanColor.layerId, 'fill-color', sanitizeColor(oceanColor));
62
- }
63
- applyPaintAndVisibility(map, STYLE_LAYER_MAP.waterDepth.layerId, 'fill-color', waterDepth);
64
- applyPaintAndVisibility(map, STYLE_LAYER_MAP.nationalPark.layerId, 'fill-color', nationalPark);
65
- }
66
-
67
- // --- Transportation ---
68
- if (customStyles.transportation) {
69
- applyLineStyles(map, STYLE_LAYER_MAP.roads.layerId, customStyles.transportation.roads);
70
- applyLineStyles(map, STYLE_LAYER_MAP.airports.layerId, customStyles.transportation.airports);
71
- }
72
-
73
- // --- Boundaries ---
74
- if (customStyles.boundaries) {
75
- applyLineStyles(map, STYLE_LAYER_MAP.countries.layerId, customStyles.boundaries.countries);
76
- applyLineStyles(map, STYLE_LAYER_MAP.states.layerId, customStyles.boundaries.states);
77
- applyLineStyles(map, STYLE_LAYER_MAP.counties.layerId, customStyles.boundaries.counties);
78
- }
79
-
80
- // --- Water Features ---
81
- if (customStyles.waterFeatures) {
82
- applyLineStyles(map, STYLE_LAYER_MAP.waterways.layerId, customStyles.waterFeatures.waterways);
83
- }
84
-
85
- // --- Labels ---
86
- if (customStyles.labels) {
87
- applySymbolStyles(map, STYLE_LAYER_MAP.continents.layerId, customStyles.labels.continents);
88
- applySymbolStyles(map, STYLE_LAYER_MAP.countriesLabels.layerId, customStyles.labels.countries);
89
- applySymbolStyles(map, STYLE_LAYER_MAP.statesLabels.layerId, customStyles.labels.states);
90
- applySymbolStyles(map, STYLE_LAYER_MAP.citiesMajor.layerId, customStyles.labels.cities.major);
91
- applySymbolStyles(map, STYLE_LAYER_MAP.citiesMinor.layerId, customStyles.labels.cities.minor);
92
- applySymbolStyles(map, STYLE_LAYER_MAP.airportsLabels.layerId, customStyles.labels.airports);
93
- applySymbolStyles(map, STYLE_LAYER_MAP.poi.layerId, customStyles.labels.poi);
94
- applySymbolStyles(map, STYLE_LAYER_MAP.waterLabels.layerId, customStyles.labels.waterLabels);
95
- applySymbolStyles(map, STYLE_LAYER_MAP.naturalLabels.layerId, customStyles.labels.naturalLabels);
96
- applySymbolStyles(map, STYLE_LAYER_MAP.subdivisionLabels.layerId, customStyles.labels.subdivisionLabels);
97
- }
98
-
99
- if (customStyles.terrain && map.getSource('mapbox-dem')) {
100
- if (customStyles.terrain.visible) {
101
- map.setTerrain({ source: 'mapbox-dem', exaggeration: 1 });
102
- if (map.getLayer('hillshade')) {
103
- map.setPaintProperty('hillshade', 'hillshade-exaggeration', customStyles.terrain.intensity);
104
- // --- MODIFICATION: Sanitize terrain colors ---
105
- map.setPaintProperty('hillshade', 'hillshade-shadow-color', sanitizeColor(customStyles.terrain.shadowColor));
106
- map.setPaintProperty('hillshade', 'hillshade-highlight-color', sanitizeColor(customStyles.terrain.highlightColor));
107
- map.setPaintProperty('hillshade', 'hillshade-accent-color', sanitizeColor(customStyles.terrain.accentColor));
108
- }
109
- } else {
110
- map.setTerrain(null);
111
- }
112
- }
1
+ // aguacero-api/src/style-applicator.js
2
+ import { STYLE_LAYER_MAP } from './style-layer-map.js';
3
+
4
+ function sanitizeColor(color) {
5
+ if (typeof color === 'string' && color.startsWith('#') && color.length === 9) {
6
+ // It's an 8-digit hex (#rrggbbaa), convert to 6-digit hex (#rrggbb)
7
+ return color.substring(0, 7);
8
+ }
9
+ // Otherwise, the color is already in a valid format (e.g., #ffffff, rgba(...))
10
+ return color;
11
+ }
12
+
13
+ const applyLineStyles = (map, layerId, styles) => {
14
+ if (!map.getLayer(layerId)) return;
15
+ map.setLayoutProperty(layerId, 'visibility', styles.visible ? 'visible' : 'none');
16
+ // --- MODIFICATION: Sanitize the color ---
17
+ map.setPaintProperty(layerId, 'line-color', sanitizeColor(styles.color));
18
+ map.setPaintProperty(layerId, 'line-width', styles.width);
19
+ if (styles.lineType) {
20
+ const dashArray = { 'dashed': [2, 2], 'dotted': [0, 2], 'solid': [] };
21
+ map.setPaintProperty(layerId, 'line-dasharray', dashArray[styles.lineType] || []);
22
+ }
23
+ };
24
+
25
+ // Helper to apply styles to a symbol (label) layer, now with color sanitization
26
+ const applySymbolStyles = (map, layerId, styles) => {
27
+ if (!map.getLayer(layerId)) return;
28
+ map.setLayoutProperty(layerId, 'visibility', styles.visible ? 'visible' : 'none');
29
+ // --- MODIFICATION: Sanitize both text and halo colors ---
30
+ map.setPaintProperty(layerId, 'text-color', sanitizeColor(styles.color));
31
+ map.setPaintProperty(layerId, 'text-halo-color', sanitizeColor(styles.outlineColor));
32
+ map.setPaintProperty(layerId, 'text-halo-width', styles.outlineWidth);
33
+ map.setLayoutProperty(layerId, 'text-size', styles.fontSize);
34
+ map.setLayoutProperty(layerId, 'text-font', [styles.fontFamily]);
35
+ };
36
+
37
+ function applyPaintAndVisibility(map, layerId, property, styles) {
38
+ if (!styles) return;
39
+ if (!map.getLayer(layerId)) return;
40
+ // --- MODIFICATION: Sanitize the color ---
41
+ if (styles.color) map.setPaintProperty(layerId, property, sanitizeColor(styles.color));
42
+ if (styles.visible !== undefined) map.setLayoutProperty(layerId, 'visibility', styles.visible ? 'visible' : 'none');
43
+ }
44
+
45
+ /**
46
+ * Applies a comprehensive set of style customizations to the Mapbox map.
47
+ * @param {mapboxgl.Map} map - The Mapbox map instance.
48
+ * @param {object} customStyles - A style configuration object (e.g., defaultDarkMapStyles).
49
+ */
50
+ export function applyStyleCustomizations(map, customStyles) {
51
+ if (!map || !map.isStyleLoaded()) return;
52
+
53
+ // --- Land & Water ---
54
+ if (customStyles.landOcean) {
55
+ const { landColor, oceanColor, waterDepth, nationalPark } = customStyles.landOcean;
56
+ // --- MODIFICATION: Sanitize the colors here too ---
57
+ if (map.getLayer(STYLE_LAYER_MAP.landColor.layerId)) {
58
+ map.setPaintProperty(STYLE_LAYER_MAP.landColor.layerId, 'background-color', sanitizeColor(landColor));
59
+ }
60
+ if (map.getLayer(STYLE_LAYER_MAP.oceanColor.layerId)) {
61
+ map.setPaintProperty(STYLE_LAYER_MAP.oceanColor.layerId, 'fill-color', sanitizeColor(oceanColor));
62
+ }
63
+ applyPaintAndVisibility(map, STYLE_LAYER_MAP.waterDepth.layerId, 'fill-color', waterDepth);
64
+ applyPaintAndVisibility(map, STYLE_LAYER_MAP.nationalPark.layerId, 'fill-color', nationalPark);
65
+ }
66
+
67
+ // --- Transportation ---
68
+ if (customStyles.transportation) {
69
+ applyLineStyles(map, STYLE_LAYER_MAP.roads.layerId, customStyles.transportation.roads);
70
+ applyLineStyles(map, STYLE_LAYER_MAP.airports.layerId, customStyles.transportation.airports);
71
+ }
72
+
73
+ // --- Boundaries ---
74
+ if (customStyles.boundaries) {
75
+ applyLineStyles(map, STYLE_LAYER_MAP.countries.layerId, customStyles.boundaries.countries);
76
+ applyLineStyles(map, STYLE_LAYER_MAP.states.layerId, customStyles.boundaries.states);
77
+ applyLineStyles(map, STYLE_LAYER_MAP.counties.layerId, customStyles.boundaries.counties);
78
+ }
79
+
80
+ // --- Water Features ---
81
+ if (customStyles.waterFeatures) {
82
+ applyLineStyles(map, STYLE_LAYER_MAP.waterways.layerId, customStyles.waterFeatures.waterways);
83
+ }
84
+
85
+ // --- Labels ---
86
+ if (customStyles.labels) {
87
+ applySymbolStyles(map, STYLE_LAYER_MAP.continents.layerId, customStyles.labels.continents);
88
+ applySymbolStyles(map, STYLE_LAYER_MAP.countriesLabels.layerId, customStyles.labels.countries);
89
+ applySymbolStyles(map, STYLE_LAYER_MAP.statesLabels.layerId, customStyles.labels.states);
90
+ applySymbolStyles(map, STYLE_LAYER_MAP.citiesMajor.layerId, customStyles.labels.cities.major);
91
+ applySymbolStyles(map, STYLE_LAYER_MAP.citiesMinor.layerId, customStyles.labels.cities.minor);
92
+ applySymbolStyles(map, STYLE_LAYER_MAP.airportsLabels.layerId, customStyles.labels.airports);
93
+ applySymbolStyles(map, STYLE_LAYER_MAP.poi.layerId, customStyles.labels.poi);
94
+ applySymbolStyles(map, STYLE_LAYER_MAP.waterLabels.layerId, customStyles.labels.waterLabels);
95
+ applySymbolStyles(map, STYLE_LAYER_MAP.naturalLabels.layerId, customStyles.labels.naturalLabels);
96
+ applySymbolStyles(map, STYLE_LAYER_MAP.subdivisionLabels.layerId, customStyles.labels.subdivisionLabels);
97
+ }
98
+
99
+ if (customStyles.terrain && map.getSource('mapbox-dem')) {
100
+ if (customStyles.terrain.visible) {
101
+ map.setTerrain({ source: 'mapbox-dem', exaggeration: 1 });
102
+ if (map.getLayer('hillshade')) {
103
+ map.setPaintProperty('hillshade', 'hillshade-exaggeration', customStyles.terrain.intensity);
104
+ // --- MODIFICATION: Sanitize terrain colors ---
105
+ map.setPaintProperty('hillshade', 'hillshade-shadow-color', sanitizeColor(customStyles.terrain.shadowColor));
106
+ map.setPaintProperty('hillshade', 'hillshade-highlight-color', sanitizeColor(customStyles.terrain.highlightColor));
107
+ map.setPaintProperty('hillshade', 'hillshade-accent-color', sanitizeColor(customStyles.terrain.accentColor));
108
+ }
109
+ } else {
110
+ map.setTerrain(null);
111
+ }
112
+ }
113
113
  }
@@ -1,27 +1,27 @@
1
- export const STYLE_LAYER_MAP = {
2
- // Background and water layers
3
- landColor: { layerId: 'AML_-_land' },
4
- oceanColor: { layerId: 'AML_-_water' },
5
- waterDepth: { layerId: 'AML_-_water-depth' },
6
- nationalPark: { layerId: 'AML_-_national-park' },
7
-
8
- // Line layers
9
- roads: { layerId: 'AML_-_roads' },
10
- airports: { layerId: 'AML_-_airports' },
11
- countries: { layerId: 'AML_-_countries' },
12
- states: { layerId: 'AML_-_states' },
13
- counties: { layerId: 'AML_-_counties' },
14
- waterways: { layerId: 'AML_-_waterway' },
15
-
16
- // Symbol (label) layers
17
- continents: { layerId: 'AML_-_continent-label' },
18
- countriesLabels: { layerId: 'AML_-_country-label' },
19
- statesLabels: { layerId: 'AML_-_state-label' },
20
- citiesMajor: { layerId: 'AML_-_major-city-label' },
21
- citiesMinor: { layerId: 'AML_-_minor-city-label' },
22
- airportsLabels: { layerId: 'AML_-_airport-label' },
23
- poi: { layerId: 'AML_-_poi-label' },
24
- waterLabels: { layerId: 'AML_-_water-point-label' }, // Assuming point label for general water
25
- naturalLabels: { layerId: 'AML_-_natural-point-label' }, // Assuming point label for natural features
26
- subdivisionLabels: { layerId: 'AML_-_subdivision-label' },
1
+ export const STYLE_LAYER_MAP = {
2
+ // Background and water layers
3
+ landColor: { layerId: 'AML_-_land' },
4
+ oceanColor: { layerId: 'AML_-_water' },
5
+ waterDepth: { layerId: 'AML_-_water-depth' },
6
+ nationalPark: { layerId: 'AML_-_national-park' },
7
+
8
+ // Line layers
9
+ roads: { layerId: 'AML_-_roads' },
10
+ airports: { layerId: 'AML_-_airports' },
11
+ countries: { layerId: 'AML_-_countries' },
12
+ states: { layerId: 'AML_-_states' },
13
+ counties: { layerId: 'AML_-_counties' },
14
+ waterways: { layerId: 'AML_-_waterway' },
15
+
16
+ // Symbol (label) layers
17
+ continents: { layerId: 'AML_-_continent-label' },
18
+ countriesLabels: { layerId: 'AML_-_country-label' },
19
+ statesLabels: { layerId: 'AML_-_state-label' },
20
+ citiesMajor: { layerId: 'AML_-_major-city-label' },
21
+ citiesMinor: { layerId: 'AML_-_minor-city-label' },
22
+ airportsLabels: { layerId: 'AML_-_airport-label' },
23
+ poi: { layerId: 'AML_-_poi-label' },
24
+ waterLabels: { layerId: 'AML_-_water-point-label' }, // Assuming point label for general water
25
+ naturalLabels: { layerId: 'AML_-_natural-point-label' }, // Assuming point label for natural features
26
+ subdivisionLabels: { layerId: 'AML_-_subdivision-label' },
27
27
  };