如何使我的topojson文件与数据映射一起使用?

时间:2018-12-21 20:09:37

标签: d3.js data-visualization topojson datamaps d3.geo

我正在尝试加载自定义的topojson文件,但出现此错误:

  

无法读取未定义的属性“类型”

从topojson.min.js v1.6.9的第219行起

  

返回o.type ===“ GeometryCollection”吗? {

我使用的是d3 v3.5.3和topojs v1.6.9,因为我无法使用自定义的topojson文件来获得较新的版本。

<script src="d3.min.3.5.3.js"></script>
<script src="d3-geo-projection.min.js"></script>
<script src="topojson.min.1.6.9.js"></script>
<script src="datamaps.usa.min.js"></script>
<script>
    var map = new Datamap({
        element: document.getElementById('container'),
        geographyConfig: {
            dataUrl: 'Utah_Municipalities_custom.topojson'
        },
        scope: 'custom',
        setProjection: function(element, options) {
            var projection, path;

            // Utah Central
            projection = d3.geo.conicConformal()
                .parallels([39 + 1 / 60, 40 + 39 / 60])
                .rotate([111 + 30 / 60, 0]);

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

            return {path: path, projection: projection};
        }
    });
</script>
</body>
</html>

Utah_Municipalities_custom.topojson

{"type":"Topology","objects":{"Municipalities.gdb":{"type":"GeometryCollection","geometries":[{"type":"MultiPolygon","arcs":[[[0,1,2,3,4,5,6,7,8]]],"properties":{"COUNTYNBR":"06","NAME":"Farmington","COUNTYSEAT":1,"SHORTDESC":"FARMINGTON","UPDATED":"2018/10/05 00:00:00","FIPS":"24740","ENTITYNBR":3050,"SALESTAXID":"017","IMSCOLOR":3,"MINNAME":"Farmington","POPLASTCENSUS":18752,"POPLASTESTIMATE":22566,"GNIS":"1441004","Shape_Length":31551.51123429135,"Shape_Area":25990884.690499976}},
{"type":"MultiPolygon","arcs":[[[9]]],"properties":{"COUNTYNBR":"01","NAME":"Minersville","COUNTYSEAT":0,"SHORTDESC":"MINERSVILLE","UPDATED":"2012/04/02 00:00:00","FIPS":"50590","ENTITYNBR":3030,"SALESTAXID":"009","IMSCOLOR":3,"MINNAME":"Minersville","POPLASTCENSUS":921,"POPLASTESTIMATE":869,"GNIS":"1430376","Shape_Length":23283.92651941338,"Shape_Area":5645426.963867947}},
{"type":"MultiPolygon","arcs":[[[10]]],"properties":{"COUNTYNBR":"22","NAME":"Francis","COUNTYSEAT":0,"SHORTDESC":"FRANCIS","UPDATED":"2016/04/29 00:00:00","FIPS":"26940","ENTITYNBR":3020,"SALESTAXID":"013","IMSCOLOR":2,"MINNAME":" ","POPLASTCENSUS":1094,"POPLASTESTIMATE":1258,"GNIS":"1428080","Shape_Length":27357.49743179958,"Shape_Area":6733236.332748903}},
etc...

我猜我的topojson文件可能有问题,或者我可能需要弄清楚如何使用新版本的topojson或其他内容来创建此地图...

1 个答案:

答案 0 :(得分:0)

事实证明,它是CORS的Chrome扩展程序,由于某种原因导致它无法正常工作。