简体   繁体   中英

How do I get my topojson file to work with datamaps?

I am trying to load my custom topojson file but I am getting this error:

Cannot read property 'type' of undefined

from this line 219 in topojson.min.js v1.6.9

return o.type === "GeometryCollection" ? {

I am using d3 v3.5.3 and topojs v1.6.9 because I haven't been able to get the newer versions working with my custom topojson file.

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

I'm guessing there might be something wrong with my topojson file, or maybe I need to figure out how to create this map with a newer version of topojson or something...

原来,这是CORS的Chrome扩展程序,由于某种原因导致其无法正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM