Openlayers 3 GeoJSON coordinates shows wrong resul

2019-08-15 16:32发布

I am using angular-openlayers-directive to build my project.

I try to rewrite the example of geojson part cause I will get point information dynamically. So I made the source part of geojson inside instead of loading from json file. However, the position of my code is totally different as I expect.

The result suppose to show a point at that coordinate I set. But the point is like at the [0, 0]. If I change the to use loading from the json file, that will work.

I have no idea why the coordinate change so much. If anyone know the reason why, please let me know! I will appreciate that.

The following is my code:

        source: {
            type: "GeoJSON",
            projection: 'EPSG:4326',
            geojson: {
                object: {
                    type: "FeatureCollection",

                    features: [{
                        type: "Feature",
                        id: "TWN",
                        properties: {
                            name: "Taiwan"
                        },
                        geometry: {
                            type: "Point",
                            coordinates: [25.038507, 121.525527]
                        }
                    }]
                }
            }
            //url: 'json/ESP.geo.json'
        }

2条回答
劫难
2楼-- · 2019-08-15 17:24

There is an error in the placement of the 'projection' attribute. The answer below shows the correct one.

source: {
        type: "GeoJSON",
        geojson: {
            object: {
                type: "FeatureCollection",

                features: [{
                    type: "Feature",
                    id: "TWN",
                    properties: {
                        name: "Taiwan"
                    },
                    geometry: {
                        type: "Point",
                        coordinates: [25.038507, 121.525527]
                    }
                }]
            },

            projection: 'EPSG:4326',
        }

}

查看更多
闹够了就滚
3楼-- · 2019-08-15 17:27

The GeoJSON you've supplied is invalid. GeoJSON coordinates pairs are in the form of longitude/latitude, not latitude/longitude as you've used for Taiwan. Switch them and you'll be fine.

查看更多
登录 后发表回答