-
Notifications
You must be signed in to change notification settings - Fork 166
overview
ModeHandler
s provide a way of handling user interactions in order to manipulate GeoJSON features and geometries.
The following are the built-in, and default ModeHandler
s provided by nebula.gl:
- Mode name:
view
No edits are possible, but selection is still possible.
- Mode name:
modify
User can move existing points, add intermediate points along lines, and remove points.
editContext
argument to the onEdit
callback contains the following properties:
-
positionIndexes
(Array): An array of numbers representing the indexes of the edited position within the feature'scoordinates
array -
position
(Array): An array containing the ground coordinates (i.e. [lng, lat]) of the edited position
- Mode name:
extrude
User can move edge. Click and drag from anywhere between 2 points in edge.
- Mode name:
scale
User can scale a feature about its centroid by clicking and dragging (inward or outward) the selected geometry. This mode supports multiple selections.
- Mode name:
rotate
User can rotate a feature about its centroid by clicking and dragging the selected geometry. This mode supports multiple selections.
- Mode name:
translate
User can translate a feature by clicking selected feature and dragging anywhere on the screen. This mode supports multiple selections.
- Mode name:
duplicate
User can duplicate and translate a feature by clicking selected feature and dragging anywhere on the screen. This mode is extends TranslateHandler. This mode supports multiple selections.
- Mode name:
drawPoint
User can draw a new Point
feature by clicking where the point is to be.
- Mode name:
drawLineString
User can draw a new LineString
feature by clicking positions to add.
-
If a
LineString
feature is selected, clicking will add a position to it. -
If no feature is selected, a new
LineString
feature will be added. Note: you must select the new feature (via theonEdit
callback) in order to start extending it. -
If multiple features are selected, or a non-
LineString
is selected, the user will be prevented from drawing.
The following options can be provided in the modeConfig
object:
-
drawAtFront
(optional):<boolean>
- If
true
, will render the tentative feature at the "beginning" of the line, i.e. relative to the start of the coordinates array.
- If
editContext
argument to the onEdit
callback contains the following properties:
-
positionIndexes
(Array): An array of numbers representing the indexes of the added position within the feature'scoordinates
array -
position
(Array): An array containing the ground coordinates (i.e. [lng, lat]) of the added position
- Mode name:
drawPolygon
User can draw a new Polygon
feature by clicking positions to add then closing the polygon (or double-clicking).
editContext
argument to the onEdit
callback contains the following properties:
-
positionIndexes
(Array): An array of numbers representing the indexes of the added position within the feature'scoordinates
array -
position
(Array): An array containing the ground coordinates (i.e. [lng, lat]) of the added position
- Mode name:
draw90DegreePolygon
User can draw a new Polygon
feature with 90 degree corners (right angle) by clicking positions to add then closing the polygon (or double-clicking). After clicking the 2 points, the draw mode guides/allows to have right angle polygon.
- Mode name:
drawRectangle
User can draw a new rectanglular Polygon
feature by clicking two opposing corners of the rectangle.
- Mode name:
drawRectangleUsing3Points
User can draw a new rectanglular Polygon
feature by clicking three corners of the rectangle.
- Mode name:
drawCircleFromCenter
User can draw a new circular Polygon
feature by clicking the center then along the ring.
The following options can be provided in the modeConfig
object:
-
steps
(optional):x <number>
- If steps:
x
means the circle will be drawn usingx
number of points.
- If steps:
- Mode name:
drawCircleByBoundingBox
User can draw a new circular Polygon
feature by clicking the two corners of bounding box.
The following options can be provided in the modeConfig
object:
-
steps
(optional):x <number>
- If steps:
x
means the circle will be drawn usingx
number of points.
- If steps:
- Mode name:
drawEllipseByBoundingBox
User can draw a new ellipse shape Polygon
feature by clicking two corners of bounding box.
- Mode name:
drawEllipseUsing3Points
User can draw a new ellipse shape Polygon
feature by clicking center and two corners of the ellipse.
- Mode name:
split
User can split a polygon by drawing a new LineString
feature on top of the polygon.
-
If the first and the last click is outside the polygon, it will split the polygon
-
If the clicked position is inside the polygon, it will not split the polygon
- Mode name:
elevation
User can move a point up and down. min
and max
can be configured in modeConfig
.
The following options can be provided in the modeConfig
object:
-
gap
(optional):x <number>
- If gap:
x
means the spacing between the polygon would bex
. - Gap value should be greater than 0.
- Default gap is
0.1
- If gap:
-
unit
(optional):centimeters|feet|inches|meters|kilometers|miles|yards
- If unit:
x
means the unit used for the spacing would be ofx
unit. - Default unit is
centimeters
- If unit:
-
lock90Degree
(Boolean, optional)- Default:
false
- If true, all angles will be guaranteed to be 90 degrees.
- Default:
For all polygon drawing modes, the following options can be provided in the modeConfig
object:
-
booleanOperation
(optional):null|'union'|'difference'|'intersection'
- If non-null, requires a single
Polygon
orMultiPolygon
selection - If
null
, the drawnPolygon
is added as a new feature regardless of selection - If
union
, the drawnPolygon
is unioned with the selected geometry - If
difference
, the drawnPolygon
is subtracted from the selected geometry - If
intersection
, the drawnPolygon
is intersected with the selected geometry
- If non-null, requires a single
Use CompositeModeHandler
to combine multiple handlers.
Not all combinations are guaranteed to work.
new CompositeModeHandler(handlers, options = {})
-
handlers
:Array<ModeHandler>
Handlers you want to combine. Order is very important. -
options
(optional): Options to be added later.
const modeHandlers = Object.assign(
{
'drawLineString+modify': new CompositeModeHandler([
new DrawLineStringHandler(),
new ModifyHandler()
])
},
EditableGeoJsonLayer.defaultProps.modeHandlers
);
Footer
Sidebar