Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,671 additions
and
32 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
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,49 @@ | ||
{ | ||
"name": "@nebula.gl/edit-modes", | ||
"description": "GeoJSON editing modes for nebula.gl", | ||
"license": "MIT", | ||
"version": "0.12.1", | ||
"author": "Georgios Karnas <georgios@uber.com>", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/uber/nebula.gl" | ||
}, | ||
"keywords": [ | ||
"webgl", | ||
"visualization", | ||
"overlay", | ||
"layer" | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist-es6/index.js", | ||
"files": [ | ||
"dist", | ||
"dist-es6", | ||
"src" | ||
], | ||
"scripts": { | ||
"build-clean": "rm -fr dist dist-es6 && mkdir -p dist dist-es6", | ||
"build-es6": "rm -fr dist-es6 && BABEL_ENV=es6 babel src --config-file ../../babel.config.js --out-dir dist-es6 --source-maps inline", | ||
"build-es5": "rm -fr dist && BABEL_ENV=es5 babel src --config-file ../../babel.config.js --out-dir dist --source-maps inline", | ||
"build": "yarn build-clean && yarn build-es6 && yarn build-es5 && cp ../../README.md .", | ||
"flow": "(cd ../.. && yarn flow)", | ||
"lint": "(cd ../.. && yarn lint)", | ||
"prepublish": "yarn build", | ||
"publish-prod": "yarn build && yarn test && yarn test-dist && npm publish", | ||
"publish-beta": "yarn build && yarn test && yarn test-dist && npm publish --tag beta", | ||
"test": "yarn lint && yarn build && yarn flow && yarn jest", | ||
"test-r": "yarn lint && yarn build && yarn test-node && (cd test/rendering-test && node node-rendering.js)", | ||
"test-fast": "yarn test-node", | ||
"test-ci": "yarn lint && node test/node-ci.js", | ||
"test-cover": "NODE_ENV=test tape -r babel-register test/node.js && nyc report", | ||
"test-node": "(cd ../.. && node test/node.js)", | ||
"test-dist": "(cd ../.. && node test/node-dist.js)", | ||
"test-browser": "webpack-dev-server --env.test --progress --hot --open", | ||
"jest": "(cd ../.. && jest src)", | ||
"bench": "node test/bench/node.js", | ||
"bench-browser": "webpack-dev-server --env.bench --progress --hot --open", | ||
"test-rendering": "(cd test/rendering-test && webpack-dev-server --config webpack.config.test-rendering.js --progress --hot --open)" | ||
}, | ||
"dependencies": { | ||
} | ||
} |
File renamed without changes.
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,40 @@ | ||
// @flow | ||
|
||
export { EditMode, BaseEditMode } from './lib/edit-mode.js'; | ||
export { ImmutableFeatureCollection } from './lib/immutable-feature-collection.js'; | ||
|
||
export type { ModeState } from './lib/edit-mode.js'; | ||
|
||
export type { | ||
ScreenCoordinates, | ||
EditAction, | ||
Pick, | ||
ClickEvent, | ||
PointerMoveEvent, | ||
StartDraggingEvent, | ||
StopDraggingEvent | ||
} from './types.js'; | ||
|
||
export type { | ||
Position, | ||
PointCoordinates, | ||
LineStringCoordinates, | ||
PolygonCoordinates, | ||
MultiPointCoordinates, | ||
MultiLineStringCoordinates, | ||
MultiPolygonCoordinates, | ||
AnyCoordinates, | ||
Point, | ||
LineString, | ||
Polygon, | ||
MultiPoint, | ||
MultiLineString, | ||
MultiPolygon, | ||
Geometry, | ||
Polygonal, | ||
BoundingBoxArray, | ||
FeatureOf, | ||
Feature, | ||
FeatureCollection, | ||
AnyGeoJson | ||
} from './geojson-types.js'; |
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,121 @@ | ||
// @flow | ||
|
||
import type { ClickEvent, PointerMoveEvent } from '../types.js'; | ||
import type { Polygon, Position } from '../geojson-types.js'; | ||
import type { GeoJsonEditAction, EditHandle } from './geojson-edit-mode.js'; | ||
import { | ||
BaseGeoJsonEditMode, | ||
getPickedEditHandle, | ||
getEditHandlesForGeometry | ||
} from './geojson-edit-mode.js'; | ||
|
||
export class DrawPolygonMode extends BaseGeoJsonEditMode { | ||
getEditHandlesAdapter(picks?: Array<Object>, mapCoords?: Position): EditHandle[] { | ||
let handles = super.getEditHandlesAdapter(picks, mapCoords); | ||
|
||
const tentativeFeature = this.getTentativeFeature(); | ||
if (tentativeFeature) { | ||
handles = handles.concat(getEditHandlesForGeometry(tentativeFeature.geometry, -1)); | ||
// Slice off the handles that are are next to the pointer | ||
if (tentativeFeature && tentativeFeature.geometry.type === 'LineString') { | ||
// Remove the last existing handle | ||
handles = handles.slice(0, -1); | ||
} else if (tentativeFeature && tentativeFeature.geometry.type === 'Polygon') { | ||
// Remove the last existing handle | ||
handles = handles.slice(0, -1); | ||
} | ||
} | ||
|
||
return handles; | ||
} | ||
|
||
handleClickAdapter(event: ClickEvent): ?GeoJsonEditAction { | ||
super.handleClickAdapter(event); | ||
|
||
const { picks } = event; | ||
const tentativeFeature = this.getTentativeFeature(); | ||
|
||
let editAction: ?GeoJsonEditAction = null; | ||
const clickedEditHandle = getPickedEditHandle(picks); | ||
|
||
if (clickedEditHandle) { | ||
// User clicked an edit handle. | ||
// Remove it from the click sequence, so it isn't added as a new point. | ||
const clickSequence = this.getClickSequence(); | ||
clickSequence.splice(clickSequence.length - 1, 1); | ||
} | ||
|
||
if (tentativeFeature && tentativeFeature.geometry.type === 'Polygon') { | ||
const polygon: Polygon = tentativeFeature.geometry; | ||
|
||
if ( | ||
clickedEditHandle && | ||
clickedEditHandle.featureIndex === -1 && | ||
(clickedEditHandle.positionIndexes[1] === 0 || | ||
clickedEditHandle.positionIndexes[1] === polygon.coordinates[0].length - 3) | ||
) { | ||
// They clicked the first or last point (or double-clicked), so complete the polygon | ||
|
||
// Remove the hovered position | ||
const polygonToAdd: Polygon = { | ||
type: 'Polygon', | ||
coordinates: [[...polygon.coordinates[0].slice(0, -2), polygon.coordinates[0][0]]] | ||
}; | ||
|
||
this.resetClickSequence(); | ||
this._setTentativeFeature(null); | ||
editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd); | ||
} | ||
} | ||
|
||
// Trigger pointer move right away in order for it to update edit handles (to support double-click) | ||
const fakePointerMoveEvent = { | ||
screenCoords: [-1, -1], | ||
mapCoords: event.mapCoords, | ||
picks: [], | ||
isDragging: false, | ||
pointerDownPicks: null, | ||
pointerDownScreenCoords: null, | ||
pointerDownMapCoords: null, | ||
sourceEvent: null | ||
}; | ||
|
||
this.handlePointerMoveAdapter(fakePointerMoveEvent); | ||
|
||
return editAction; | ||
} | ||
|
||
handlePointerMoveAdapter({ | ||
mapCoords | ||
}: PointerMoveEvent): { editAction: ?GeoJsonEditAction, cancelMapPan: boolean } { | ||
const clickSequence = this.getClickSequence(); | ||
const result = { editAction: null, cancelMapPan: false }; | ||
|
||
if (clickSequence.length === 0) { | ||
// nothing to do yet | ||
return result; | ||
} | ||
|
||
if (clickSequence.length < 3) { | ||
// Draw a LineString connecting all the clicked points with the hovered point | ||
this._setTentativeFeature({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'LineString', | ||
coordinates: [...clickSequence, mapCoords] | ||
} | ||
}); | ||
} else { | ||
// Draw a Polygon connecting all the clicked points with the hovered point | ||
this._setTentativeFeature({ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Polygon', | ||
coordinates: [[...clickSequence, mapCoords, clickSequence[0]]] | ||
} | ||
}); | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.