【问题标题】:Open Layers 3 - Convert Lat Long to Point打开第 3 层 - 将经纬度转换为点
【发布时间】:2015-02-07 07:23:22
【问题描述】:

我在一个名为 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
});

由于某种原因,它似乎要么在非洲附近绘制位置,要么根本不绘制位置。

我该如何解决这个问题?

我找到了在 Open Layers 2 中进行投影和变换的代码。在 Open Layers 3 中找不到确切的方法。

注意:我得到了它与 tsauerwein 的评论一起使用。但请注意,我必须将点从 EPSG:4326 转换为 EPSG:900913

【问题讨论】:

  • 坐标是[lat, lon]还是[lon, lat]? ol3 期望 [lon, lat]
  • 啊.. 它们是 [lat, lon].. 让我尝试用不同的 EPSG 反转它们
  • 好吧,反转它们就像一个魅力!您可以将其发布为答案吗?我希望它会帮助别人。

标签: javascript ruby-on-rails gis openlayers-3


【解决方案1】:

OpenLayers 期望坐标为[lon, lat] 而不是[lat, lon]。因此,在您的情况下,您将不得不更改顺序。

【讨论】:

  • 我想知道有多少人犯了这个错误(包括我自己),我知道这是一个小的性能问题,但为什么不使用类似{"lon": lon, "lat": lat} 或带有.lat.lon 的对象?
猜你喜欢
  • 2013-09-09
  • 2021-09-24
  • 1970-01-01
  • 1970-01-01
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-14
相关资源
最近更新 更多