douro-hougaku-machi-no-dekikata-gl
Last active
September 16, 2021 07:00
-
-
Save frogcat/867f457dee02b073a7b9b6ecbed10ecb to your computer and use it in GitHub Desktop.
douro-hougaku-machi-no-dekikata-gl
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>douro-hougaku-machi-no-dekikata-gl</title> | |
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0" /> | |
<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@1.14.0/dist/maplibre-gl.css" /> | |
<script src="https://unpkg.com/maplibre-gl@1.14.0/dist/maplibre-gl.js"></script> | |
<script src="https://unpkg.com/@turf/turf/turf.min.js"></script> | |
</head> | |
<body> | |
<div id="map" style="position:absolute;top:0;left:0;bottom:0;right:0;"></div> | |
<script> | |
const style = { | |
"version": 8, | |
"glyphs": "https://maps.gsi.go.jp/xyz/noto-jp/{fontstack}/{range}.pbf", | |
"sources": { | |
"pale": { | |
"type": "raster", | |
"tiles": [ | |
"https://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png" | |
], | |
"tileSize": 256, | |
"minzoom": 5, | |
"maxzoom": 18, | |
"attribution": "<a href='https://maps.gsi.go.jp/development/ichiran.html'>地理院タイル(淡色地図)</a>" | |
}, | |
"experimental_bvmap": { | |
"type": "vector", | |
"tiles": [ | |
"https://cyberjapandata.gsi.go.jp/xyz/experimental_bvmap/{z}/{x}/{y}.pbf" | |
], | |
"minzoom": 5, | |
"maxzoom": 16, | |
"attribution": "<a href='https://github.com/gsi-cyberjapan/gsimaps-vector-experiment'>地理院地図Vector</a>" | |
}, | |
"overlay": { | |
"type": "geojson", | |
"data": { | |
"type": "FeatureCollection", | |
"features": [] | |
} | |
} | |
}, | |
"layers": [{ | |
"id": "pale", | |
"type": "raster", | |
"source": "pale", | |
"minzoom": 2, | |
"maxzoom": 18 | |
}, | |
{ | |
"id": "road", | |
"type": "line", | |
"source": "experimental_bvmap", | |
"source-layer": "road", | |
"filter": ["==", ["geometry-type"], "LineString"], | |
"minzoom": 5, | |
"maxzoom": 18, | |
"paint": { | |
"line-color": "#000000", | |
"line-width": 1 | |
}, | |
"layout": { | |
"line-cap": "round", | |
"line-join": "round" | |
} | |
}, | |
{ | |
"id": "overlay", | |
"type": "line", | |
"source": "overlay", | |
"paint": { | |
"line-color": ["get", "color"], | |
"line-width": ["get", "width"] | |
}, | |
"layout": { | |
"line-cap": "round", | |
"line-join": "round" | |
} | |
} | |
] | |
}; | |
const map = new maplibregl.Map({ | |
container: "map", | |
center: [139.8508, 35.416], | |
zoom: 9, | |
pitch: 60, | |
bearing: -30, | |
hash: true, | |
style: style | |
}); | |
map.on("idle", function() { | |
const features = []; | |
map.queryRenderedFeatures({ | |
layers: ["road"] | |
}).forEach(f => { | |
const g = f.geometry; | |
(g.type === "LineString" ? [g.coordinates] : g.coordinates).forEach(c => { | |
const head = c[0]; | |
const tail = c[c.length - 1]; | |
let bearing = turf.bearing(head, tail); | |
if (bearing < 0) bearing += 180; | |
if (bearing > 90) bearing -= 90; | |
features.push({ | |
"type": "Feature", | |
"properties": { | |
"color": `hsl(${45 - bearing*4},90%,45%)`, | |
"width": [4, 4, 6, 8, 10, 4, 4][f.properties.rnkWidth] | |
}, | |
"geometry": { | |
"type": "LineString", | |
"coordinates": c | |
} | |
}); | |
}); | |
}); | |
map.getSource("overlay").setData({ | |
"type": "FeatureCollection", | |
"features": features | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains 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
MIT License | |
Copyright (c) 2020 Yuzo Matsuzawa | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment