簡體   English   中英

帶有 d3 js 的班加羅爾 geojson 地圖

[英]Bangalore geojson map with d3 js

我正在嘗試使用 d3.js 使用帶有 8 個區域(功能)的班加羅爾 geojson 文件

地圖未正確顯示。 這里有什么問題。 ??

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>D3: expr maps</title> <script type="text/javascript" src="d3/d3.min.js"></script> <style type="text/css"> /* No style rules here yet */ </style> </head> <body> <script type="text/javascript"> //Width and height var width = 500; var height = 300; var vis = d3.select("body").append("svg") .attr("width", width).attr("height", height); d3.json("BangZone.json", function(json) { // Create a unit projection. var projection = d3.geo.mercator() .scale(1) .translate([0, 0]); // Create a path generator. var path = d3.geo.path() .projection(projection); // Compute the bounds of a feature of interest, then derive scale & translate. var b = path.bounds(json), s = .95 / Math.max((b[1][0] - b[0][0]) / width, (b[1][1] - b[0][1]) / height), t = [(width - s * (b[1][0] + b[0][0])) / 2, (height - s * (b[1][1] + b[0][1])) / 2]; // Update the projection to use computed scale & translate. projection .scale(s) .translate(t); path = path.projection(projection); // add a rectangle to see the bound of the svg vis.append("rect").attr('width', width).attr('height', height) .style('stroke', 'black').style('fill', 'none'); vis.selectAll("path").data(json.features).enter().append("path") .attr("d", path) .style("fill", "red") .style("stroke-width", "1") .style("stroke", "black") }); </script> </body> </html>

geojson 文件是: BangaloreGeojsonwithZones

問題是在 geojson 文件中還是在 d3 代碼中??

您的 GeoJSON 文件使用 EPSG::37001。 嘗試將其轉換為 EPSG:4326,看看是否有幫助。 您可以使用QGIS轉換它。

我遇到了類似的問題,解決方案在這里: d3-javascript-and-geojson-lines-in-stockholm-map-very-strange

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM