Openlayers 3 readExtensions GPX

时间:2016-01-22 18:04:53

标签: openlayers-3

我是javascript的新手,但我正尝试使用openlayers 3从GPX轨道读取心率扩展。

Sample GPX track point

拖放交互接受GPX格式的构造函数。我可以通过传递ol.format.GPX构造函数来读取基本信息(lat,lon,ele,time),但我无法弄清楚如何使用' readExtensions'来传递构造函数。选项。

根据openlayers文档(http://openlayers.org/en/v3.1.1/apidoc/ol.format.GPX.html),它应该是一个回调函数,但是当我运行我的代码时,我收到一个错误:TypeError:d [g]不是构造函数。

    var dragAndDropInteraction = new ol.interaction.DragAndDrop({
  formatConstructors: [
    //ol.format.GPX(extFeature),
    new ol.format.GPX({
        readExtensions: function(x) {
          return x;
        }
        }),
    ol.format.GeoJSON,
    ol.format.IGC,
    ol.format.KML,
    ol.format.TopoJSON
  ]
});

如何格式化构造函数以便我获得扩展以及标准功能?

1 个答案:

答案 0 :(得分:2)

您可以创建一个继承自ol.format.GPX的自定义格式,并将您的构造函数传递给拖放式交互:

var CustomFormat = function() {
  ol.format.GPX.call(this, {
    // custom options
  });
};
ol.inherits(CustomFormat, ol.format.GPX);

var dragAndDropInteraction = new ol.interaction.DragAndDrop({
  formatConstructors: [
    CustomFormat,
    ...
  ]
});

http://jsfiddle.net/6zmprrj7/