Posted at

Retroscope をつくろう

More than 1 year has passed since last update.


はじめに

これは State of the Map Japan 2018 の講演で使用したサンプルコード置き場です。


1. OpenStreetMap を表示しよう

このコードが


a.html

<!DOCTYPE html>

<html>

<head>
<meta charset="UTF-8">
<title>hello leaflet</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.3/dist/leaflet.js"></script>
</head>

<body>
<div id="map" style="position:absolute;top:0;left:0;bottom:0;right:0;"></div>
<script>
var map = L.map("map").setView([35.671872, 139.754969], 18);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "&copy; <a href='http://osm.org/copyright'>OpenStreetMap</a>contributors"
}).addTo(map);
</script>
</body>

</html>


こうなります

image.png


2. Retroscope を表示しよう

このコードが


b.html

<!DOCTYPE html>

<html>

<head>
<meta charset="UTF-8">
<title>retroscope</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.3.3/dist/leaflet.js"></script>
<script src="https://frogcat.github.io/leaflet-tilelayer-mask/leaflet-tilelayer-mask.js"></script>
</head>

<body>
<div id="map" style="position:absolute;top:0;left:0;bottom:0;right:0;"></div>
<script>
var map = L.map("map").setView([35.671872, 139.754969], 18);
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: "&copy; <a href='http://osm.org/copyright'>OpenStreetMap</a> contributors"
}).addTo(map);

var layer = L.tileLayer.mask("https://cyberjapandata.gsi.go.jp/xyz/seamlessphoto/{z}/{x}/{y}.jpg", {
attribution: "<a href='http://maps.gsi.go.jp/development/ichiran.html'>地理院タイル</a>"
}).addTo(map);

map.on("mousemove", function(event) {
layer.setCenter(event.containerPoint);
});
</script>
</body>

</html>


こうなります

retroscope.gif