Draw tool allows us to draw on a map.
Draw Tool Add-on
Draw
new Draw(options: Object)
Parameters
options
(Object)
Name | Type | Description |
---|---|---|
options.keybindings |
boolean
(default: true )
|
Whether or not to enable keyboard interactions for drawing. |
options.touchEnabled |
boolean
(default: true )
|
Whether or not to enable touch interactions for drawing. |
options.boxSelect |
boolean
(default: true )
|
Whether or not to enable box selection of features with
shift
+
click
+ drag. If
false
,
shift
+
click
+ drag zooms into an area.
|
options.clickBuffer |
number
(default: 2 )
|
Number of pixels around any feature or vertex (in every direction) that will respond to a click. |
options.touchBuffer |
number
(default: 25 )
|
Number of pixels around any feature of vertex (in every direction) that will respond to a touch. |
options.controls |
Object
|
Hide or show individual controls. Each property's name is a control, and value is a boolean
indicating whether the control is on or off. Available control names are
point
,
line_string
,
polygon
,
trash
,
combine_features
and
uncombine_features
. By default, all controls are on. To change that default, use
displayControlsDefault
.
|
options.displayControlsDefault |
boolean
(default: true )
|
The default value for
controls
. For example, if you would like all controls to be off by default, and specify an allowed
list with
controls
, use
displayControlsDefault
:
false
.
|
options.styles |
Array<Object>
|
An array of map style objects. By default, the addon provides a map style for you. |
options.modes |
Object
|
Override the default modes with your own.
Draw.modes
can be used to see the default values.
|
options.defaultMode |
modes
(default: Draw.modes.SIMPLE_SELECT )
|
The initial/starting mode of the addon. |
options.userProperties |
boolean
(default: false )
|
Whether or not the properties of a feature will also be available for styling and prefixed
with
user_
, e.g.,
['==', 'user_custom_label', 'Example']
|
Example
const drawControl = new TrimbleMapsControl.Draw({
defaultMode: TrimbleMapsControl.Draw.modes.DRAW_POLYGON,
userProperties: true
});
map.addControl(drawControl);
Static Members
Available modes for the Draw addon.
modes
Properties
Instance Members
Returns an array of feature ids for features currently rendered at the specified point.
The point argument requires x, y coordinates from pixel space, rather than longitude, latitude coordinates. With this function, you can use the coordinates provided by mouse events to get information.
getFeatureIdsAt(point: Point): Array<string>
Parameters
point
(Point)
Returns
Array<string>
:
Returns a GeoJSON FeatureCollection of all the features currently selected.
getSelected(): FeatureCollection
Returns
FeatureCollection
:
Returns a GeoJSON FeatureCollection of Points representing all the vertices currently selected.
getSelectedPoints(): FeatureCollection
Returns
FeatureCollection
:
Sets the addon's features to those in the specified FeatureCollection.
Performs whatever delete, create, and update actions are necessary to make the addon's features
match the specified FeatureCollection. Effectively, this is the same as deleteAll()
followed by add(featureCollection)
except that it does not affect performance as
much.
set(featureCollection: FeatureCollection): Array<string>
Parameters
featureCollection
(FeatureCollection)
Returns
Array<string>
:
This method takes either a GeoJSON Feature, FeatureCollection, or Geometry and adds it to the addon. It returns an array of ids for interacting with the added features. If a feature does not have its own id, one is automatically generated.
The supported GeoJSON feature types are supported: Point
, LineString
,
Polygon
, MultiPoint
, MultiLineString
, and
MultiPolygon
.
If you add()
a feature with an id that is already in use, the existing feature
will be updated and no new feature will be added.
add(geojson: Object): Array<string>
Parameters
geojson
(Object)
Returns
Array<string>
:
Returns a FeatureCollection of all features.
getAll(): FeatureCollection
Returns
FeatureCollection
:
Changes the addon to another mode. Returns the addon instance for chaining.
The mode argument must be one of the mode names enumerated in modes
.
simple_select
, direct_select
, and draw_line_string
modes
accept an options
object.
changeMode(mode: any, modeOptions: Object): Draw
Parameters
mode
(any)
modeOptions
(Object
= {}
)
Returns
Draw
:
Example
// `simple_select` options
{
// Array of ids of features that will be initially selected
featureIds: Array<string>
}
// `direct_select` options
{
// The id of the feature that will be directly selected (required)
featureId: string
}
// `draw_line_string` options
{
// The id of the LineString to continue drawing
featureId: string,
// The point to continue drawing from
from: Feature<Point>|Point|Array<number>
}
Invokes the current mode's trash action. Returns the addon instance for chaining.
In simple_select
mode, this deletes all selected features.
In direct_select
mode, this deletes the selected vertices.
In drawing modes, this cancels drawing and reverts the addon to simple_select
mode.
If you want to delete features regardless of the current mode, use the delete
or
deleteAll
function.
trash(): Draw
Returns
Draw
:
Invokes the current mode's combineFeatures action. Returns the addon instance for chaining.
In simple_select
mode, this combines all selected features into a single Multi*
feature, as long as they are all of the same geometry type.
For example two LineStrings will become a MultiLineString.
Calling this function when features of different geometry types are selected will not cause any changes.
In direct_select
mode and drawing modes, no action is taken.
combineFeatures(): Draw
Returns
Draw
:
Invokes the current mode's uncombineFeatures action. Returns the addon instance for chaining.
In simple_select
mode, this splits each selected Multi* feature into its component
feature parts, and leaves non-multifeatures untouched.
For example a MultiLineString of three parts will become LineString, LineString, LineString.
In the direct_select
and drawing modes, no action is taken.
uncombineFeatures(): Draw
Returns
Draw
:
Sets the value of a property on the feature with the specified id. Returns the addon instance for chaining.
This can be helpful if you are using addon features as your primary data store in your application.
setFeatureProperty(featureId: string, property: string, value: any): Draw
Parameters
Returns
Draw
:
Events
Fired just after the addon calls setData() on the map. This does not imply that the set data call has finished updating the map, just that the map is being updated.
draw.render