forked from mapbox/mapbox-gl-draw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass all properties when creating midpoints and vertices, close mapbo…
- Loading branch information
1 parent
c7ff98d
commit d06a7a0
Showing
7 changed files
with
188 additions
and
48 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,28 +1,33 @@ | ||
import * as Constants from '../constants'; | ||
import * as Constants from "../constants"; | ||
|
||
/** | ||
* Returns GeoJSON for a Point representing the | ||
* vertex of another feature. | ||
* | ||
* @param {string} parentId | ||
* @param {GeoJSON} parent | ||
* @param {Array<number>} coordinates | ||
* @param {string} path - Dot-separated numbers indicating exactly | ||
* where the point exists within its parent feature's coordinates. | ||
* @param {boolean} selected | ||
* @return {GeoJSON} Point | ||
*/ | ||
export default function(parentId, coordinates, path, selected) { | ||
return { | ||
export default function(parent, coordinates, path, selected) { | ||
const vertex = { | ||
type: Constants.geojsonTypes.FEATURE, | ||
properties: { | ||
...parent.properties, | ||
meta: Constants.meta.VERTEX, | ||
parent: parentId, | ||
parent: parent.properties && parent.properties.id, | ||
coord_path: path, | ||
active: (selected) ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE | ||
active: selected | ||
? Constants.activeStates.ACTIVE | ||
: Constants.activeStates.INACTIVE | ||
}, | ||
geometry: { | ||
type: Constants.geojsonTypes.POINT, | ||
coordinates | ||
} | ||
}; | ||
delete vertex.properties.id; | ||
return vertex; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,63 @@ | ||
import test from 'tape'; | ||
import createVertex from '../src/lib/create_vertex'; | ||
import test from "tape"; | ||
import createVertex from "../src/lib/create_vertex"; | ||
|
||
test('createVertex', (t) => { | ||
t.deepEqual(createVertex('foo', [1, 2], '3.4.5', true), { | ||
type: 'Feature', | ||
properties: { | ||
meta: 'vertex', | ||
parent: 'foo', | ||
coord_path: '3.4.5', | ||
active: 'true' | ||
}, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [1, 2] | ||
test("createVertex", t => { | ||
t.deepEqual( | ||
createVertex({ properties: { id: "foo" } }, [1, 2], "3.4.5", true), | ||
{ | ||
type: "Feature", | ||
properties: { | ||
meta: "vertex", | ||
parent: "foo", | ||
coord_path: "3.4.5", | ||
active: "true" | ||
}, | ||
geometry: { | ||
type: "Point", | ||
coordinates: [1, 2] | ||
} | ||
} | ||
); | ||
t.deepEqual( | ||
createVertex({ properties: { id: "bar" } }, [99, 199], "1", false), | ||
{ | ||
type: "Feature", | ||
properties: { | ||
meta: "vertex", | ||
parent: "bar", | ||
coord_path: "1", | ||
active: "false" | ||
}, | ||
geometry: { | ||
type: "Point", | ||
coordinates: [99, 199] | ||
} | ||
} | ||
}); | ||
); | ||
|
||
t.deepEqual(createVertex('bar', [99, 199], '1', false), { | ||
type: 'Feature', | ||
properties: { | ||
meta: 'vertex', | ||
parent: 'bar', | ||
coord_path: '1', | ||
active: 'false' | ||
t.deepEqual( | ||
createVertex( | ||
{ properties: { id: "bar", baz: "qux" } }, | ||
[99, 199], | ||
"1", | ||
false | ||
), | ||
{ | ||
type: "Feature", | ||
properties: { | ||
meta: "vertex", | ||
parent: "bar", | ||
coord_path: "1", | ||
active: "false", | ||
baz: "qux" | ||
}, | ||
geometry: { | ||
type: "Point", | ||
coordinates: [99, 199] | ||
} | ||
}, | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [99, 199] | ||
} | ||
}); | ||
"userProperties are copied to vertices" | ||
); | ||
|
||
t.end(); | ||
}); |