【问题标题】:Openlayers 3 readExtensions GPXOpenlayers 3 读取扩展 GPX
【发布时间】:2016-01-23 03:08:31
【问题描述】:

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

Sample GPX track point

拖放交互接受 GPX 格式的构造函数。我可以通过传递 ol.format.GPX 构造函数来读取基本信息(纬度、经度、ele、时间),但我不知道如何使用“readExtensions”选项传递构造函数。

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

    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
  ]
});

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

【问题讨论】:

    标签: openlayers-3


    【解决方案1】:

    您可以创建一个继承自 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/

    【讨论】:

      猜你喜欢
      • 2014-07-03
      • 1970-01-01
      • 2017-04-10
      • 2019-05-09
      • 2012-07-23
      • 1970-01-01
      • 2013-03-19
      • 2013-08-06
      • 1970-01-01
      相关资源
      最近更新 更多