我对javascript还不熟悉,但我正在尝试从GPX的openlayers 3曲目中读取心率扩展。
示例GPX跟踪点
拖放交互接受GPX格式的构造函数。我可以通过传递ol.format.GPX构造函数来读取基本信息(lat、lon、ele、time),但我不知道如何传递带有'readExtensions‘选项的构造函数。
根据开放层文档(http://openlayers.org/en/v3.1.1/apidoc/ol.format.GPX.html),它应该是一个回调函数,但是当我运行我的代码时,我会得到一个错误: TypeError: dg不是一个构造函数。
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
]
});如何设置构造函数的格式,以便使扩展和标准特性相同?
发布于 2016-01-22 19:08:31
您可以创建从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/
https://stackoverflow.com/questions/34953202
复制相似问题