HTML5加载geojson,d3加载geojson实现地图显示

D3.js是最流行的可视化库之一,下面是一个d3加载geojson地图数据实现一个简单的地图显示demo。

官方地址:var json={"type":"FeatureCollection","features":[...]}

var width = 1600,height = 700;

var svg = d3.select("#main").append("svg").attr("width", width).attr("height", height);

var projection = d3.geoMercator().fitSize([width, height], json);

var path = d3.geoPath(projection);

svg.selectAll("path")

.data( json.features )

.enter()

.append("path")

.attr("stroke","#000")

.attr("stroke-width",1)

.attr("d", path)

.attr("fill", function(d,i){

if(d.geometry.type == 'Polygon') {

return d.properties.fill || "#555555";

} else {

return 'none';

}<

你可能感兴趣的:(HTML5加载geojson)