Javascript 开放层3-将横向长度转换为点
我在一个名为Javascript 开放层3-将横向长度转换为点,javascript,ruby-on-rails,gis,openlayers-3,Javascript,Ruby On Rails,Gis,Openlayers 3,我在一个名为Lat_Longs的数组中有一个Lat Longs数组(看起来像这样-[[39.749318,-104.9701129],,,,,,,]),我正试图使用OpenLayer3在OpenStreetMap中绘制它们。这是我的密码- var icon_features = []; $.each(lat_longs, function(index, item){ var point = new ol.geom.Point(item); point.transform('EPSG
Lat_Longs
的数组中有一个Lat Longs数组(看起来像这样-[[39.749318,-104.9701129],,,,,,,]
),我正试图使用OpenLayer3在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
OpenLayers希望坐标是[lon,lat]
,而不是[lat,lon]
。因此,在您的情况下,您必须更改顺序。是坐标[lat,lon]
还是[lon,lat]
?ol3期望[lon,lat]
.Ah。。他们是[拉丁,拉丁]。。让我试着用不同的方法反转它们好吧,反转它们就像一个符咒!你能把它作为答案贴出来吗?我希望它能帮助一些人。我想知道有多少次人们(包括我自己)弄错了这一点,我知道这是一个小的性能问题,但为什么不使用像{“lon”:lon,“lat”:lat}
或带有.lat
和.lon
的对象呢?