Permalink
Browse files

is featureCoordTimes is a string: look for the specified property

  • Loading branch information...
1 parent 92bbc4e commit 0df8071fc6a6eedd3bfc61fbe15d43aad5160eea @tyrasd committed May 25, 2016
Showing with 36 additions and 0 deletions.
  1. +8 −0 index.js
  2. +28 −0 test/test.js
View
@@ -17,6 +17,14 @@ function togpx( geojson, options ) {
featureCoordTimes: get_feature_coord_times,
}, options || {});
+ // is featureCoordTimes is a string -> look for the specified property
+ if (typeof options.featureCoordTimes === 'string') {
+ var customTimesFieldKey = options.featureCoordTimes;
+ options.featureCoordTimes = function (feature) {
+ return feature.properties[customTimesFieldKey];
+ }
+ }
+
function get_feature_title(props) {
// a simple default heuristic to determine a title for a given feature
// uses a nested `tags` object or the feature's `properties` if present
View
@@ -521,6 +521,34 @@ describe("properties", function () {
expect(pts[1].getElementsByTagName("time")[0].textContent).to.equal("2014-06-23T20:29:11Z");
});
+ it('Time (string)', function() {
+ var geojson, result;
+ geojson = {
+ type: "FeatureCollection",
+ features: [{
+ type: "Feature",
+ properties: {
+ customTimesField: [
+ "2014-06-23T20:29:08Z",
+ "2014-06-23T20:29:11Z",
+ ]
+ },
+ geometry: {
+ type: "LineString",
+ coordinates: [[1.0,2.0],[3.0,4.0]]
+ }
+ }]
+ };
+ result = togpx(geojson, {
+ featureCoordTimes: "customTimesField"
+ });
+ result = (new DOMParser()).parseFromString(result, 'text/xml');
+ var pts = result.getElementsByTagName("trkpt");
+ expect(pts[0].getElementsByTagName("time")).to.have.length(1);
+ expect(pts[0].getElementsByTagName("time")[0].textContent).to.equal("2014-06-23T20:29:08Z");
+ expect(pts[1].getElementsByTagName("time")).to.have.length(1);
+ expect(pts[1].getElementsByTagName("time")[0].textContent).to.equal("2014-06-23T20:29:11Z");
+ });
});
describe("elevation", function () {

0 comments on commit 0df8071

Please sign in to comment.