-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1004 from plotly/geo-line-picking
Multiple scattergeo improvement
- Loading branch information
Showing
30 changed files
with
865 additions
and
388 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
/** | ||
* Convert calcTrace to GeoJSON 'MultiLineString' coordinate arrays | ||
* | ||
* @param {object} calcTrace | ||
* gd.calcdata item. | ||
* Note that calcTrace[i].lonlat is assumed to be defined | ||
* | ||
* @return {array} | ||
* return line coords array (or array of arrays) | ||
* | ||
*/ | ||
exports.calcTraceToLineCoords = function(calcTrace) { | ||
var trace = calcTrace[0].trace, | ||
connectgaps = trace.connectgaps; | ||
|
||
var coords = [], | ||
lineString = []; | ||
|
||
for(var i = 0; i < calcTrace.length; i++) { | ||
var calcPt = calcTrace[i]; | ||
|
||
lineString.push(calcPt.lonlat); | ||
|
||
if(!connectgaps && calcPt.gapAfter && lineString.length > 0) { | ||
coords.push(lineString); | ||
lineString = []; | ||
} | ||
} | ||
|
||
coords.push(lineString); | ||
|
||
return coords; | ||
}; | ||
|
||
|
||
/** | ||
* Make line ('LineString' or 'MultiLineString') GeoJSON | ||
* | ||
* @param {array} coords | ||
* results form calcTraceToLineCoords | ||
* @param {object} trace | ||
* (optional) full trace object to be added on to output | ||
* | ||
* @return {object} out | ||
* GeoJSON object | ||
* | ||
*/ | ||
exports.makeLine = function(coords, trace) { | ||
var out = {}; | ||
|
||
if(coords.length === 1) { | ||
out = { | ||
type: 'LineString', | ||
coordinates: coords[0] | ||
}; | ||
} | ||
else { | ||
out = { | ||
type: 'MultiLineString', | ||
coordinates: coords | ||
}; | ||
} | ||
|
||
if(trace) out.trace = trace; | ||
|
||
return out; | ||
}; | ||
|
||
/** | ||
* Make polygon ('Polygon' or 'MultiPolygon') GeoJSON | ||
* | ||
* @param {array} coords | ||
* results form calcTraceToLineCoords | ||
* @param {object} trace | ||
* (optional) full trace object to be added on to output | ||
* | ||
* @return {object} out | ||
* GeoJSON object | ||
*/ | ||
exports.makePolygon = function(coords, trace) { | ||
var out = {}; | ||
|
||
if(coords.length === 1) { | ||
out = { | ||
type: 'Polygon', | ||
coordinates: coords | ||
}; | ||
} | ||
else { | ||
var _coords = new Array(coords.length); | ||
|
||
for(var i = 0; i < coords.length; i++) { | ||
_coords[i] = [coords[i]]; | ||
} | ||
|
||
out = { | ||
type: 'MultiPolygon', | ||
coordinates: _coords | ||
}; | ||
} | ||
|
||
if(trace) out.trace = trace; | ||
|
||
return out; | ||
}; | ||
|
||
/** | ||
* Make blank GeoJSON | ||
* | ||
* @return {object} | ||
* Blank GeoJSON object | ||
* | ||
*/ | ||
exports.makeBlank = function() { | ||
return { | ||
type: 'Point', | ||
coordinates: [] | ||
}; | ||
}; |
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.