2016-01-22 90 views
2

我是新来的JavaScript,但想读从GPX轨道心脏率与延长3的OpenLayers的OpenLayers 3 readExtensions 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 
    ] 
}); 

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

回答

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/