Openlayers 3 GeoJSON coordinates shows wrong result

让人想犯罪 __ 提交于 2020-01-05 09:49:00

问题


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'
        }

回答1:


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',
        }

}




回答2:


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.



来源:https://stackoverflow.com/questions/36079288/openlayers-3-geojson-coordinates-shows-wrong-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!