班加罗尔geojson地图与d3 js [英] Bangalore geojson map with d3 js

查看:160
本文介绍了班加罗尔geojson地图与d3 js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过使用d3.js使用其中有8个区域(功能)的Bangalore geojson文件

Am trying to use a Bangalore geojson file with 8 zones (features) in it by using d3.js

地图未正确显示。这里有什么问题。 ??

The map is not showing up properly. What's wrong here. ??

<!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>

文件是: BangaloreGeojsonwithZones

Geojson文件或d3代码中的问题

Is the problem in geojson file or in the d3 code??

推荐答案

您的GeoJSON文件使用EPSG: :37001。尝试将其转换为EPSG:4326,看看这是否有帮助。您可以使用 QGIS 转换。

Your GeoJSON file uses EPSG::37001. Try converting it to EPSG:4326 and see if that helps. You can convert it with QGIS.

我有一个类似的问题,解决方案是这里: d3-javascript-and-geojson-lines-in-stockholm-map-very-strange

I've had a similar problem, the solution is here: d3-javascript-and-geojson-lines-in-stockholm-map-very-strange.

这篇关于班加罗尔geojson地图与d3 js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆