Created
October 18, 2025 11:37
-
-
Save codydotio/0b0bed65a3d61f2e33db9a45dfe1c9ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map.current!.addLayer({ | |
| id: "charlton-ct-label", | |
| type: "symbol", | |
| source: "charlton-ct", | |
| layout: { | |
| "symbol-placement": "line", | |
| "text-field": ["get", "name"], | |
| "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"], | |
| "text-size": 14, | |
| "text-offset": [1, -0.6], | |
| }, | |
| paint: { | |
| "text-color": "#FFFFFF", | |
| "text-halo-color": "#000000", | |
| "text-halo-width": 2, | |
| }, | |
| }); | |
| console.log("Charlton Ct layers added"); | |
| const style = map.current!.getStyle(); | |
| if (style && Array.isArray(style.layers)) { | |
| style.layers.forEach((layer) => { | |
| if ( | |
| layer.type === "symbol" && | |
| layer.layout && | |
| layer.layout["text-field"] | |
| ) { | |
| try { | |
| map.current!.setLayoutProperty(layer.id, "text-font", [ | |
| "Open Sans Bold", | |
| "Arial Unicode MS Bold", | |
| ]); | |
| map.current!.setLayoutProperty(layer.id, "text-size", 14); | |
| map.current!.setPaintProperty( | |
| layer.id, | |
| "text-color", | |
| "#FFFFFF" | |
| ); | |
| map.current!.setPaintProperty( | |
| layer.id, | |
| "text-halo-color", | |
| "#000000" | |
| ); | |
| map.current!.setPaintProperty( | |
| layer.id, | |
| "text-halo-width", | |
| 2 | |
| ); | |
| } catch (e) { | |
| console.error("Error styling layer:", layer.id, e); | |
| } | |
| } | |
| }); | |
| style.layers.forEach((layer) => { | |
| if ( | |
| layer.type === "symbol" && | |
| layer.layout && | |
| layer.layout["text-field"] | |
| ) { | |
| try { | |
| map.current!.setLayoutProperty( | |
| layer.id, | |
| "text-allow-overlap", | |
| true | |
| ); | |
| map.current!.setLayoutProperty( | |
| layer.id, | |
| "text-ignore-placement", | |
| true | |
| ); | |
| map.current!.setLayoutProperty( | |
| layer.id, | |
| "symbol-placement", | |
| "line" | |
| ); | |
| } catch (e) { | |
| console.error( | |
| "Error setting extended layout properties for layer:", | |
| layer.id, | |
| e | |
| ); | |
| } | |
| } | |
| }); | |
| style.layers.forEach((layer) => { | |
| if ( | |
| layer.type === "symbol" && | |
| layer.layout && | |
| layer.layout["text-field"] | |
| ) { | |
| try { | |
| map.current!.setLayerZoomRange(layer.id, 0, 24); | |
| } catch (e) { | |
| console.error( | |
| "Error setting zoom range for layer:", | |
| layer.id, | |
| e | |
| ); | |
| } | |
| } | |
| }); | |
| style.layers.forEach((layer) => { | |
| if ( | |
| layer.id.includes("poi-label") || | |
| layer.id.includes("transit-label") | |
| ) { | |
| try { | |
| map.current!.setPaintProperty( | |
| layer.id, | |
| "text-color", | |
| "#666666" | |
| ); | |
| map.current!.setPaintProperty( | |
| layer.id, | |
| "text-halo-color", | |
| "#000000" | |
| ); | |
| map.current!.setPaintProperty( | |
| layer.id, | |
| "text-halo-width", | |
| 1 | |
| ); | |
| } catch (e) { | |
| console.error("Error styling label layer:", layer.id, e); | |
| } | |
| } | |
| }); | |
| } | |
| } catch (e) { | |
| console.error("Error adding Charlton Ct layers:", e); | |
| } | |
| setTimeout(() => { | |
| if (map.current) { | |
| map.current.resize(); | |
| } | |
| }, 100); | |
| }); | |
| } catch (error) { | |
| console.error("Error initializing Mapbox:", error); | |
| } | |
| }, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment