Skip to content

Instantly share code, notes, and snippets.

@franciscop
Last active September 17, 2021 22:46
Show Gist options
  • Save franciscop/63f47b1514a2c4d41f4560ebe3aa1394 to your computer and use it in GitHub Desktop.
Save franciscop/63f47b1514a2c4d41f4560ebe3aa1394 to your computer and use it in GitHub Desktop.
Japan train lines Mapbox+Leaflet
const map = ...;
const accessToken = "...";
// Add train lines (Shinkansen, metro, JR, etc) to Mapbox using LeafLet for a more
// accurate representation of Japan and Tokyo
// Using the layer mapbox.transit-v2 for trains and some custom styles
const trains =
"https://api.mapbox.com/v4/mapbox.transit-v2/{z}/{x}/{y}.vector.pbf?access_token={accessToken}";
const transit_line = (properties, zoom) => {
const isShinkansen = properties.mode === "high_speed_rail";
const isYamanote = properties.name === "山手線";
return {
color: (isYamanote ? "#00cc00" : properties.line_color) || "#666",
opacity: isShinkansen ? 0.75 : 0.5,
weight: isShinkansen || isYamanote ? 2 : 1.5
};
};
var mapillaryLayer = L.vectorGrid
.protobuf(trains, { accessToken, vectorTileLayerStyles: { transit_line } })
.addTo(map);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment