如何在OpenLayers中将投影与IGC文件格式匹配?

时间:2018-09-19 20:27:38

标签: openlayers

我正在构建OpenLayers应用程序。地图上有圆圈,并且IGC文件应该显示轨迹接触了圆圈。但是,从下面的图像来看并非如此。 enter image description here

经过验证,该轨迹可以通过其他方法进入圆圈,因此问题似乎出在不同的坐标系或投影上。

在下面的代码中,我用

定义了圆
var MAGMA = new ol.geom.Circle(ol.proj.transform([-111.5032, 33.1356], 'EPSG:4326', 'EPSG:3857'), 5000);

代码的IGC部分是

var igcUrls = [
track1.igc',
];
function get(url, callback) {
var client = new XMLHttpRequest();
client.open('GET', url);
client.onload = function() {
callback(client.responseText);
};
client.send();
}
var igcFormat = new ol.format.IGC();
for (var i = 0; i < igcUrls.length; ++i) {
get(igcUrls[i], function(data) {
var features = igcFormat.readFeatures(data,
{featureProjection: 'EPSG:3857'});
vectorSource.addFeatures(features);
});

如果我将featueProjection: 'EPSG:3857'更改为'featueProjection: 'EPSG:4326',则IGC曲目将从页面上消失。我最确定的是,这个问题与预测不符,因为IGC文件使用的是WGS-1984,但我不知道如何纠正它。

ol.map在这里。将projection: 'EPSG:4326'添加到ol.view会导致地图无法正确呈现。

var map = new ol.Map({
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    }),
    new ol.layer.Vector({
      source: vectorSource,
      style: styleFunction
    }),

    vectorLineLayer,
    vectorLayer
  ],
  target: 'map',
  controls: ol.control.defaults({
    attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
      collapsible: false
    })
  }),
  view: new ol.View({
    center: whartonMercator,
    zoom: 9,
  })
});

原始代码在这里找到:https://openlayers.org/en/latest/examples/data/igc/Clement-Latour.igc

0 个答案:

没有答案