-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Grid has been added if a GPX url is supplied- Grid options (2x2, 3x3, etc) can be found in the background controls if and only if the bounding area is a rectangle.
- Loading branch information
Showing
10 changed files
with
284 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,89 @@ | ||
import { geoExtent } from '../geo'; | ||
|
||
import toGeoJSON from '@mapbox/togeojson'; | ||
import { dispatch as d3_dispatch } from 'd3-dispatch'; | ||
import { utilRebind } from '../util'; | ||
|
||
|
||
export function coreRapidContext(context) { | ||
export function coreRapidContext() { | ||
var rapidContext = {}; | ||
rapidContext.version = '1.0.1'; | ||
var _isTaskBoundsRect = undefined; | ||
var dispatch = d3_dispatch('task_extent_set'); | ||
|
||
function distinct (value, index, self) { | ||
return self.indexOf(value) === index; | ||
} | ||
|
||
var taskExtent; | ||
rapidContext.setTaskExtentByGpxData = function(gpxData) { | ||
var dom = (new DOMParser()).parseFromString(gpxData, 'text/xml'); | ||
var gj = toGeoJSON.gpx(dom); | ||
|
||
var lineStringCount = gj.features.reduce(function (accumulator, currentValue) { | ||
return accumulator + (currentValue.geometry.type === 'LineString' ? 1 : 0); | ||
}, 0); | ||
|
||
if (gj.type === 'FeatureCollection') { | ||
var minlat, minlon, maxlat, maxlon; | ||
// Calculate task extent. | ||
gj.features.forEach(function(f) { | ||
if (f.geometry.type === 'Point') { | ||
var lon = f.geometry.coordinates[0]; | ||
var lat = f.geometry.coordinates[1]; | ||
if (minlat === undefined || lat < minlat) minlat = lat; | ||
if (minlon === undefined || lon < minlon) minlon = lon; | ||
if (maxlat === undefined || lat > maxlat) maxlat = lat; | ||
if (maxlon === undefined || lon > maxlon) maxlon = lon; | ||
if (maxlon === undefined || lon > maxlon) maxlon = lon; | ||
} | ||
|
||
if (f.geometry.type === 'LineString' && lineStringCount === 1) { | ||
var lats = f.geometry.coordinates.map(function(f) {return f[0];}); | ||
var lngs = f.geometry.coordinates.map(function(f) {return f[1];}); | ||
var uniqueLats = lats.filter(distinct); | ||
var uniqueLngs = lngs.filter(distinct); | ||
|
||
var eachLatHas2Lngs = true; | ||
uniqueLats.forEach(function (lat) { | ||
var lngsForThisLat = f.geometry.coordinates | ||
// Filter the coords to the ones with this lat | ||
.filter(function(coord){ return coord[0] === lat; }) | ||
// Make an array of lngs that associate with that lat | ||
.map(function(coord){ return coord[1]; }) | ||
// Finally, filter for uniqueness | ||
.filter(distinct); | ||
|
||
if (lngsForThisLat.length !== 2) { | ||
eachLatHas2Lngs = false; | ||
} | ||
}); | ||
// Check for exactly two unique latitudes, two unique longitudes, | ||
//and that each latitude was associated with exactly 2 longitudes, | ||
// | ||
if (uniqueLats.length === 2 && uniqueLngs.length === 2 && eachLatHas2Lngs) { | ||
_isTaskBoundsRect = true; | ||
} else { | ||
_isTaskBoundsRect = false; | ||
} | ||
} | ||
}); | ||
taskExtent = new geoExtent([minlon, minlat], [maxlon, maxlat]); | ||
dispatch.call('task_extent_set'); | ||
} | ||
}; | ||
|
||
|
||
rapidContext.getTaskExtent = function() { | ||
return taskExtent; | ||
}; | ||
|
||
return rapidContext; | ||
|
||
rapidContext.isTaskRectangular = function() { | ||
if (!taskExtent) { | ||
return false; | ||
} | ||
|
||
return _isTaskBoundsRect; | ||
}; | ||
|
||
return utilRebind(rapidContext, dispatch, 'on'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.