Built with blockbuilder.org
Created
March 17, 2017 07:22
-
-
Save sugasaki/0bbe51103ac94e6008f667562f815a1b to your computer and use it in GitHub Desktop.
geojson test
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
license: mit |
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 lang="ja"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="content-language" content="ja"> | |
<title>geojson test</title> | |
<!--d3--> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3-legend.min.js"></script> | |
<!--leaflet--> | |
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css" /> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js"></script> | |
<style> | |
html,body{ | |
margin: 0px; | |
padding: 0px; | |
} | |
#map { | |
width: 690px; | |
height:460px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="view.js"></script> | |
<script> | |
var jsonUrl = "./floore7.js"; | |
d3.json(jsonUrl, function (json) { | |
mapInit(json); | |
}); | |
</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
function mapInit(json){ | |
geojson = json.features; | |
//Leaflet初期設定 | |
map = L.map('map', { | |
maxZoom: 15, | |
minZoom: 1, | |
crs: L.CRS.Simple //(L.CRS.Simpleは緯度経度の代わりにシンプルなXY座標でマップを表示します) | |
}); | |
var southWest = new L.LatLng(54.88, 138.48); | |
var northEast = new L.LatLng(54.88, 138.48); | |
//var southWest = new L.LatLng(64641, -167786); | |
//var northEast = new L.LatLng(126779, -147119); | |
var bounds = new L.LatLngBounds(southWest, northEast); | |
map.fitBounds(bounds); | |
//デフォルトズーム | |
map.setZoom(10); | |
//Leafletに用意されたsvgを使う | |
map._initPathRoot(); | |
// svg要素を選択 | |
var svg = d3.select("#map").select("svg"); | |
g = svg.append("g"); | |
//緯度経度->パスジェネレーター関数作成 | |
var transform = d3.geo.transform({point: projectPoint}); | |
var path = d3.geo.path().projection(transform); | |
var baseMaps = g.selectAll("path.baseMaps") | |
.data(geojson) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.attr({ | |
"stroke":"gray", | |
"fill":"none", | |
}) | |
; | |
map.on("viewreset", update); | |
update(); | |
//pathのd属性を更新 | |
function update() { | |
baseMaps.attr("d", path); | |
} | |
//位置→座標変換 | |
function projectPoint(x, y) { | |
var point = map.latLngToLayerPoint(new L.LatLng(y, x)); | |
this.stream.point(point.x, point.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment