我有一个名为lat_longs
的数组中的Lat Longs数组(看起来像这样 - [[39.749318, -104.9701129], [..], [..]]
),我试图使用Open Layers 3在OpenStreetMap中绘制它们。是我的代码 -
var icon_features = [];
$.each(lat_longs, function(index, item){
var point = new ol.geom.Point(item);
point.transform('EPSG:4326', 'EPSG:900913');
// I tried it the other way too, but doesn't seem to work
var iconFeature = new ol.Feature({
geometry: point,
name: item.name
});
icon_features.push(iconFeature);
});
var vectorSource = new ol.source.Vector({
features: icon_features
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
var view = new ol.View({
center: [0,0],
zoom: 2
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayer
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: ({
collapsible: false
})
}),
view: view
});
出于某种原因,它似乎要么在非洲附近绘制地点,要么根本没有绘制地点。
我该如何解决这个问题?
我发现代码可以在打开的图层2中进行投影和变换。无法在打开的图层3中找到如何做到这一点。
注意:我使用了 tsauerwein 的评论。但请注意,我必须将点从EPSG:4326
转换为EPSG:900913
答案 0 :(得分:1)
OpenLayers希望坐标为[lon, lat]
而不是[lat, lon]
。因此,在您的情况下,您将不得不更改订单。