Skip to content

Instantly share code, notes, and snippets.

@mapconcierge
Forked from frogcat/20200813.md
Created August 14, 2020 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapconcierge/0b854694dcaaf6e6e320d442e6cb53e2 to your computer and use it in GitHub Desktop.
Save mapconcierge/0b854694dcaaf6e6e320d442e6cb53e2 to your computer and use it in GitHub Desktop.
douro-hougaku-machi-no-dekikata

douro-hougaku-machi-no-dekikata

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>douro-hougaku-machi-no-dekikata</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" />
<script src='https://unpkg.com/@turf/turf/turf.min.js'></script>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"></script>
<script src="https://unpkg.com/leaflet.vectorgrid@1.3.0/dist/Leaflet.VectorGrid.bundled.min.js"></script>
<script src="https://unpkg.com/leaflet-hash@0.2.1/leaflet-hash.js"></script>
</head>
<body>
<div id="map" style="position:absolute;top:0;left:0;bottom:0;right:0;"></div>
<script>
const map = L.map("map", {
maxZoom: 19,
zoom: 15,
center: [35.6941, 139.792615],
preferCanvas: true
});
map.attributionControl.addAttribution("<a href='https://dailyportalz.jp/kiji/douro-hougaku-machi-no-dekikata'>道路を方角ごとに塗り分けると、その街のでき方がわかる :: デイリーポータルZ</a>");
L.tileLayer('https://maps.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png', {
attribution: "<a href='https://maps.gsi.go.jp/development/ichiran.html' target='_blank'>地理院タイル</a>"
}).addTo(map);
L.hash(map);
Object.assign(new L.GridLayer({
attribution: "<a href='https://github.com/gsi-cyberjapan/gsimaps-vector-experiment' target='_blank'>国土地理院ベクトルタイル提供実験</a>",
minZoom: 4,
maxZoom: 16
}), {
createTile: function(coords) {
const template = "https://cyberjapandata.gsi.go.jp/xyz/experimental_bvmap/{z}/{x}/{y}.pbf";
const div = document.createElement('div');
div.group = L.layerGroup();
fetch(L.Util.template(template, coords)).then(a => a.arrayBuffer()).then(buffer => {
const road = new VectorTile(new Pbf(buffer)).layers.road;
if (!road) return;
if (!div.group) return;
if (!this._map) return;
for (let i = 0; i < road.length; i++) {
const geojson = road.feature(i).toGeoJSON(coords.x, coords.y, coords.z);
const lines = geojson.geometry.type === "LineString" ? [geojson.geometry.coordinates] : geojson.geometry.coordinates;
lines.forEach(line => {
const head = line[0];
const tail = line[line.length - 1];
let bearing = turf.bearing(head, tail);
if (bearing < 0) bearing += 180;
if (bearing > 90) bearing -= 90;
div.group.addLayer(L.polyline(line.map(a => [a[1], a[0]]), {
color: `hsl(${45 - bearing*4},90%,45%)`
}));
});
}
div.group.addTo(this._map);
});
return div;
}
}).on("tileunload", function(e) {
if (e.tile.group) {
if (this._map) this._map.removeLayer(e.tile.group);
delete e.tile.group;
}
}).addTo(map);
</script>
</body>
</html>
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