问题
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