D3: map with topojson not showing properly

I am trying to draw a svg card with d3 from a topojson file, but all I have is corrupted lines.

I use most of the code that I found at http://www.tnoda.com/blog/2013-12-07 . When I use topojson files from this site, everything works fine. I may have a problem in my topojson file, but when I import it into mapshaper, I get a normal map.

plnkr: http://plnkr.co/edit/TYiT5AoI29nEHC3Fre6D?p=preview

Here is my code:

index.html

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css" type="text/css">    
    <script src="//code.jquery.com/jquery-2.0.0.js"></script>    
    <script src="//d3js.org/d3.v3.min.js"></script>
    <script src="//d3js.org/topojson.v1.min.js"></script>
  </head>
  <body>
    <div id="map"></div>
    <script src="script.js"></script>
  </body>
</html>

script.js

var m_width = $("#map").width(), 
    width = 800, 
    height = 500

var projection = d3.geo.mercator()
    .scale(105)
    .translate([width / 2, height / 1.5]);

var path = d3.geo.path()
    .projection(projection);

var svg = d3.select("#map").append("svg")
    .attr("width", m_width)
    .attr("height", m_width * height / width);

var g = svg.append("g");

d3.json("zupanije.max.topo.json", function(error, us) {
    g.append("g")
        .attr("id", "states")   
        .selectAll("path")
        .data(topojson.feature(us, us.objects.states).features) 
        .enter()
        .append("path")
        .attr("id", function(d) { return d.id; })       
        .attr("d", path)
});

styles.css

#map {
    background-color: #fff;
    border: 1px solid #ccc;
}
.background {
    fill: none;
    pointer-events: all;
}
#states{
    cursor: pointer;
    fill: #cde;
    stroke: #fff;
    stroke-linejoin: round;
    stroke-linecap: round;
}
#states .active {
    fill: #89a;
}
pre.prettyprint {
    border: 1px solid #ccc;
    margin-bottom: 0;
    padding: 9.5px;
}
+4
source share
1 answer

, SHP GeoJSON/Topojson . ! - QGIS : https://www.qgis.org/en/site/forusers/download.html - SHP GeoJSON - , . - "" > " " - : Geojson - CSR: WGS 84, EPSG: 4326 - .

!

+1

All Articles