Asw*_*nan 6 javascript gis ruby-on-rails openlayers-3
我在一个名为的数组中有一个经纬度数组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
});
Run Code Online (Sandbox Code Playgroud)
由于某种原因,它似乎要么绘制了非洲附近的位置,要么根本没有绘制该位置。
我该如何解决?
我找到了在 Open Layers 2 中进行投影和变换的代码。无法准确找到如何在 Open Layers 3 中执行此操作。
注意:我让它与tsauerwein的评论一起工作。但请注意,我必须将要点EPSG:4326从EPSG:900913
OpenLayers 期望坐标为[lon, lat]而非[lat, lon]。因此,在您的情况下,您必须更改顺序。
| 归档时间: |
|
| 查看次数: |
6423 次 |
| 最近记录: |