@geogdev/styles 0.1.0

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.
@@ -0,0 +1,232 @@
1
+ import type { LayerSpecification } from "@maplibre/maplibre-gl-style-spec";
2
+ import { ZOOM } from "../constants";
3
+ import type { Style } from "../styles";
4
+
5
+ /**
6
+ * Creates transit infrastructure layers (rail, bus, ferry)
7
+ * Progressive disclosure: main rail z10, freight z11, heritage/bus z13
8
+ */
9
+ export function createTransitLayers(
10
+ source: string,
11
+ style: Style,
12
+ ): LayerSpecification[] {
13
+ return [
14
+ // 1. Freight rail - darker, wider, dashed (z11+)
15
+ {
16
+ id: "transit_freight_rail",
17
+ type: "line",
18
+ source,
19
+ "source-layer": "transportation",
20
+ minzoom: ZOOM.TRANSIT_FREIGHT_RAIL_MIN,
21
+ filter: [
22
+ "all",
23
+ ["==", ["get", "class"], "rail"],
24
+ ["==", ["get", "usage"], "freight"],
25
+ ["!", ["has", "service"]], // Exclude service tracks
26
+ ],
27
+ paint: {
28
+ "line-color":
29
+ style.transit_freight || style.transit_rail || style.railway,
30
+ "line-width": [
31
+ "interpolate",
32
+ ["exponential", 1.4],
33
+ ["zoom"],
34
+ 11,
35
+ 1.5,
36
+ 13,
37
+ 2.5,
38
+ 16,
39
+ 4.5,
40
+ ],
41
+ "line-dasharray": [0.5, 1.5],
42
+ "line-opacity": 0.6,
43
+ },
44
+ },
45
+
46
+ // 2. Bus infrastructure - orange, dashed, subtle (z13+)
47
+ {
48
+ id: "transit_bus_infrastructure",
49
+ type: "line",
50
+ source,
51
+ "source-layer": "transportation",
52
+ minzoom: ZOOM.TRANSIT_BUS_MIN,
53
+ filter: ["==", ["get", "class"], "bus"],
54
+ paint: {
55
+ "line-color": style.transit_bus || style.transit_rail || style.railway,
56
+ "line-width": [
57
+ "interpolate",
58
+ ["exponential", 1.4],
59
+ ["zoom"],
60
+ 13,
61
+ 1.2,
62
+ 15,
63
+ 2.0,
64
+ 18,
65
+ 4.0,
66
+ ],
67
+ "line-dasharray": [2, 1],
68
+ "line-opacity": 0.6,
69
+ },
70
+ },
71
+
72
+ // 3. Heritage/tourist rail - decorative dotted pattern (z13+)
73
+ {
74
+ id: "transit_heritage_rail",
75
+ type: "line",
76
+ source,
77
+ "source-layer": "transportation",
78
+ minzoom: ZOOM.TRANSIT_HERITAGE_MIN,
79
+ filter: [
80
+ "all",
81
+ ["==", ["get", "class"], "rail"],
82
+ ["==", ["get", "usage"], "heritage"],
83
+ ],
84
+ paint: {
85
+ "line-color":
86
+ style.transit_heritage || style.transit_rail || style.railway,
87
+ "line-width": 1.8,
88
+ "line-dasharray": [0.5, 0.5],
89
+ "line-opacity": 0.5,
90
+ },
91
+ },
92
+
93
+ // 4. Mixed-use rail corridors - intermediate styling (z11+)
94
+ {
95
+ id: "transit_mixed_rail",
96
+ type: "line",
97
+ source,
98
+ "source-layer": "transportation",
99
+ minzoom: ZOOM.TRANSIT_MIXED_RAIL_MIN,
100
+ filter: [
101
+ "all",
102
+ ["==", ["get", "class"], "rail"],
103
+ ["==", ["get", "usage"], "mixed"],
104
+ ],
105
+ paint: {
106
+ "line-color": style.transit_rail || style.railway,
107
+ "line-width": [
108
+ "interpolate",
109
+ ["exponential", 1.4],
110
+ ["zoom"],
111
+ 11,
112
+ 1.5,
113
+ 13,
114
+ 2.2,
115
+ 16,
116
+ 4.0,
117
+ ],
118
+ "line-dasharray": [0.4, 0.4],
119
+ "line-opacity": 0.6,
120
+ },
121
+ },
122
+
123
+ // 5. Urban transit (subway, light_rail, tram, monorail) - z11+
124
+ {
125
+ id: "transit_urban_rail",
126
+ type: "line",
127
+ source,
128
+ "source-layer": "transportation",
129
+ minzoom: ZOOM.TRANSIT_URBAN_RAIL_MIN,
130
+ filter: [
131
+ "all",
132
+ ["==", ["get", "class"], "rail"],
133
+ [
134
+ "in",
135
+ ["get", "subclass"],
136
+ ["literal", ["subway", "light_rail", "tram", "monorail"]],
137
+ ],
138
+ ],
139
+ paint: {
140
+ "line-color": style.transit_rail || style.railway,
141
+ "line-width": [
142
+ "interpolate",
143
+ ["exponential", 1.4],
144
+ ["zoom"],
145
+ 11,
146
+ 1.5,
147
+ 14,
148
+ 2.5,
149
+ 18,
150
+ 4.0,
151
+ ],
152
+ "line-dasharray": [0.4, 1.2],
153
+ "line-opacity": 0.6,
154
+ },
155
+ },
156
+
157
+ // 6. Passenger rail (default) - standard styling (z10+)
158
+ {
159
+ id: "transit_passenger_rail",
160
+ type: "line",
161
+ source,
162
+ "source-layer": "transportation",
163
+ minzoom: ZOOM.TRANSIT_PASSENGER_RAIL_MIN,
164
+ filter: [
165
+ "all",
166
+ ["==", ["get", "class"], "rail"],
167
+ ["!", ["has", "usage"]], // No usage attribute = passenger default
168
+ // Exclude urban transit types (handled above)
169
+ [
170
+ "!",
171
+ [
172
+ "in",
173
+ ["get", "subclass"],
174
+ ["literal", ["subway", "light_rail", "tram", "monorail"]],
175
+ ],
176
+ ],
177
+ ],
178
+ paint: {
179
+ "line-color": style.transit_rail || style.railway,
180
+ "line-width": [
181
+ "interpolate",
182
+ ["exponential", 1.4],
183
+ ["zoom"],
184
+ 10,
185
+ 1.5,
186
+ 13,
187
+ 2.2,
188
+ 16,
189
+ 3.5,
190
+ ],
191
+ "line-dasharray": [0.4, 1.2],
192
+ "line-opacity": 0.5,
193
+ },
194
+ },
195
+
196
+ // 7. Service tracks (yards, sidings) - very subtle, z14+ only
197
+ {
198
+ id: "transit_service_tracks",
199
+ type: "line",
200
+ source,
201
+ "source-layer": "transportation",
202
+ minzoom: ZOOM.TRANSIT_SERVICE_TRACKS_MIN,
203
+ filter: [
204
+ "all",
205
+ ["==", ["get", "class"], "rail"],
206
+ ["has", "service"], // Only service tracks
207
+ ],
208
+ paint: {
209
+ "line-color": style.transit_rail || style.railway,
210
+ "line-width": 1.0,
211
+ "line-dasharray": [0.3, 2.0],
212
+ "line-opacity": 0.3,
213
+ },
214
+ },
215
+
216
+ // 8. Ferry routes
217
+ {
218
+ id: "transit_ferry",
219
+ type: "line",
220
+ source,
221
+ "source-layer": "transportation",
222
+ minzoom: ZOOM.TRANSIT_FERRY_MIN,
223
+ filter: ["==", ["get", "class"], "ferry"],
224
+ paint: {
225
+ "line-color": style.railway,
226
+ "line-width": 1.5,
227
+ "line-dasharray": [4, 2],
228
+ "line-opacity": 0.6,
229
+ },
230
+ },
231
+ ];
232
+ }
package/src/styles.ts ADDED
@@ -0,0 +1,182 @@
1
+ // ============================================
2
+ // JSON CONFIG IMPORTS
3
+ // ============================================
4
+
5
+ import darkConfig from "./config/styles/dark.json";
6
+ import grayConfig from "./config/styles/gray.json";
7
+ import lightConfig from "./config/styles/light.json";
8
+ import warmConfig from "./config/styles/warm.json";
9
+
10
+ // ============================================
11
+ // STYLE NAME TYPE
12
+ // ============================================
13
+
14
+ /**
15
+ * Valid style name strings
16
+ */
17
+ export const STYLE_NAMES = ["light", "dark", "gray", "warm"] as const;
18
+
19
+ /**
20
+ * Type for valid style names
21
+ */
22
+ export type StyleName = (typeof STYLE_NAMES)[number];
23
+
24
+ /**
25
+ * Type guard to check if a string is a valid style name
26
+ */
27
+ export function isValidStyleName(name: string): name is StyleName {
28
+ return STYLE_NAMES.includes(name as StyleName);
29
+ }
30
+
31
+ // ============================================
32
+ // STYLE INTERFACES
33
+ // ============================================
34
+
35
+ export interface Style {
36
+ background: string;
37
+ earth: string;
38
+ park_a: string;
39
+ park_b: string;
40
+ hospital: string;
41
+ industrial: string;
42
+ school: string;
43
+ wood_a: string;
44
+ wood_b: string;
45
+ pedestrian: string;
46
+ scrub_a: string;
47
+ scrub_b: string;
48
+ glacier: string;
49
+ sand: string;
50
+ beach: string;
51
+ aerodrome: string;
52
+ runway: string;
53
+ water: string;
54
+ zoo: string;
55
+ military: string;
56
+
57
+ tunnel_other_casing: string;
58
+ tunnel_minor_casing: string;
59
+ tunnel_link_casing: string;
60
+ tunnel_major_casing: string;
61
+ tunnel_highway_casing: string;
62
+ tunnel_other: string;
63
+ tunnel_minor: string;
64
+ tunnel_link: string;
65
+ tunnel_major: string;
66
+ tunnel_highway: string;
67
+
68
+ pier: string;
69
+ buildings: string;
70
+
71
+ minor_service_casing: string;
72
+ minor_casing: string;
73
+ link_casing: string;
74
+ major_casing_late: string;
75
+ highway_casing_late: string;
76
+ other: string;
77
+ minor_service: string;
78
+ minor_a: string;
79
+ minor_b: string;
80
+ link: string;
81
+ major_casing_early: string;
82
+ major: string;
83
+ highway_casing_early: string;
84
+ highway: string;
85
+
86
+ railway: string;
87
+ boundaries: string;
88
+
89
+ bridges_other_casing: string;
90
+ bridges_minor_casing: string;
91
+ bridges_link_casing: string;
92
+ bridges_major_casing: string;
93
+ bridges_highway_casing: string;
94
+ bridges_other: string;
95
+ bridges_minor: string;
96
+ bridges_link: string;
97
+ bridges_major: string;
98
+ bridges_highway: string;
99
+
100
+ roads_label_minor: string;
101
+ roads_label_minor_halo: string;
102
+ roads_label_major: string;
103
+ roads_label_major_halo: string;
104
+ ocean_label: string;
105
+ subplace_label: string;
106
+ subplace_label_halo: string;
107
+ city_label: string;
108
+ city_label_halo: string;
109
+ state_label: string;
110
+ state_label_halo: string;
111
+ country_label: string;
112
+
113
+ address_label: string;
114
+ address_label_halo: string;
115
+
116
+ regular?: string;
117
+ bold?: string;
118
+ italic?: string;
119
+ medium?: string;
120
+
121
+ pois?: Pois;
122
+ landcover?: Landcover;
123
+ shields?: Shields;
124
+
125
+ // Transit (optional for backward compatibility)
126
+ transit_rail?: string;
127
+ transit_freight?: string; // Darker gray for freight rail
128
+ transit_bus?: string; // Orange/warm for bus infrastructure
129
+ transit_heritage?: string; // Lighter/decorative for heritage
130
+ }
131
+
132
+ export interface Pois {
133
+ blue: string;
134
+ green: string;
135
+ lapis: string;
136
+ pink: string;
137
+ red: string;
138
+ slategray: string;
139
+ tangerine: string;
140
+ turquoise: string;
141
+ }
142
+
143
+ export interface Landcover {
144
+ barren: string;
145
+ farmland: string;
146
+ forest: string;
147
+ glacier: string;
148
+ grassland: string;
149
+ scrub: string;
150
+ urban_area: string;
151
+ rock: string;
152
+ wetland: string;
153
+ }
154
+
155
+ export interface Shields {
156
+ interstate_fill: string;
157
+ interstate_stroke: string;
158
+ interstate_text: string;
159
+ us_highway_fill: string;
160
+ us_highway_stroke: string;
161
+ us_highway_text: string;
162
+ state_fill: string;
163
+ state_stroke: string;
164
+ state_text: string;
165
+ county_fill: string;
166
+ county_stroke: string;
167
+ county_text: string;
168
+ default_fill: string;
169
+ default_stroke: string;
170
+ default_text: string;
171
+ banner_text: string;
172
+ banner_text_halo: string;
173
+ }
174
+
175
+ // ============================================
176
+ // STYLE INSTANCES (from JSON configs)
177
+ // ============================================
178
+
179
+ export const LIGHT: Style = lightConfig as Style;
180
+ export const DARK: Style = darkConfig as Style;
181
+ export const GRAY: Style = grayConfig as Style;
182
+ export const WARM: Style = warmConfig as Style;