如何让我的topojson文件与数据图一起使用?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何让我的topojson文件与数据图一起使用?相关的知识,希望对你有一定的参考价值。

我试图加载我的自定义topojson文件,但我收到此错误:

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

来自topojson.min.js v1.6.9中的第219行

return 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或其他东西来创建这个地图......

答案

事实证明,它是CORS的Chrome扩展程序,导致它因某些原因无法运行。

以上是关于如何让我的topojson文件与数据图一起使用?的主要内容,如果未能解决你的问题,请参考以下文章

无法在 Ionic V5 App 上禁用 d3 topojson 底图缩放

如何按坐标过滤 GeoJSON/TopoJSON 数据?

如何将多对象 TopoJSON 文件中的一个对象提取到另一个单独的 TopoJSON 文件

PHP:如何让我的 IF 语句与 PDO 选择一起使用?

如何让我的 iOS4.2 SDK 开发代码与 iOS3.1.3 一起工作?

如何让我的 Google-service.json 与 Google Cloud Platform 中的 Firestore 一起使用?