简体   繁体   English

解析geojson文件后,为什么在浏览器中看不到地图?

[英]Why can't I see the map in my browser after parsing the geojson file?

I have the huge geojson showing all the districts of Dubai. 我有一个巨大的geojson,显示了迪拜的所有地区。 Here is a sample: 这是一个示例:

{
    "type":"FeatureCollection",
    "totalFeatures":224,
    "features":[
        {
            "type":"Feature",
            "id":"Community.1",
            "geometry":{
                "type":"MultiPolygon",
                "coordinates":[
                    [
                        [

                            [
                                55.16945847438926,
                                25.03005371689898
                            ],
                            [
                                55.168575711653915,
                                25.03074785219016
                            ],
                            [
                                55.169258376227525,
                                25.03150691074316
                            ],
                            [
                                55.169931129543535,
                                25.032274981961805
                            ],

                        ]
                    ]
                ]
            },
            "geometry_name":"the_geom",
            "properties":{
                "COMM_CODE":684,
                "NAME_AR":"البرشاء الجنوب الخامسة",
                "NAME_EN":"AL BARSHA SOUTH FIFTH",
                "AREA_ID":442,
                "SHAPE_AREA":2951425.95614,
                "SHAPE_LEN":10871.405155
            }
        },
        {
            "type":"Feature",
            "id":"Community.2",
            "geometry":{
                "type":"MultiPolygon",
                "coordinates":[
                    [
                        [
                            [
                                55.34592943407097,
                                25.16925511754935
                            ],

                            [
                                55.34604885385063,
                                25.17297434345408
                            ],
                            [
                                55.34600905862783,
                                25.171854965446766
                            ],
                            [
                                55.345979182892805,
                                25.170726559094064
                            ],
                            [
                                55.34592943407097,
                                25.16925511754935
                            ]
                        ]
                    ]
                ]
            }

I have a very simple code in d3, that parses the geojson and displays it in the browser. 我在d3中有一个非常简单的代码,可以解析geojson并将其显​​示在浏览器中。 However I cannot see the results. 但是我看不到结果。

Here is my code: 这是我的代码:

 d3.json("dld.json", createMap);

    function createMap(countries) {
        var aProjection = d3.geo.mercator();
        var geoPath = d3.geo.path().projection(aProjection);
        d3.select("svg").selectAll("path").data(countries.features)
            .enter()
            .append("path")
            .attr("d", geoPath)
            .attr("class", "countries")
    }

There is no error displayed in the console. 控制台中没有显示错误。 If someone could please point to me where I've mistaken, I would be the most thankful :) 如果有人可以指出我在哪里,我会最感激的:)

The issue is, that you haven't yet set your bounding box you want to view in the map. 问题是,您尚未设置要在地图中查看的边界框。 For this you can extend your projection like this: 为此,您可以像这样扩展投影:

var aProjection = d3.geo.mercator().scale(1000).translate([-1000, 1000]);

The entered values are just an example. 输入的值仅是示例。 Unfortunately setting this up can be quite tedious. 不幸的是,进行此设置可能非常繁琐。 For more information about how to find the correct values you can look here: 有关如何查找正确值的更多信息,请参见此处:

d3js scale, transform and translate d3js缩放,转换和翻译

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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