StartDrawingRequest RPC
Allows the user to draw on the map.
Use cases
- measure line
- measure area
- draw dot/line/area
Description
Activates draw control on map.
Parameters
(* means the parameter is required)
Name | Type | Description | Default value |
---|---|---|---|
\* id | String | Identifier for request | |
\* shape | String | Point|LineString|Polygon|Circle|Box|Square | |
options | Object | Parameters for options-object are listed in the next table | null |
Parameters for options-object:
Name | Type | Description | Default value |
---|---|---|---|
drawControl | Boolean | true - activates draw control. false - drawing will not activated. | true |
modifyControl | Boolean | true - activates modify control. false - modifying will not activated. | true |
allowMultipleDrawing | Boolean/String | true - multiple selection is allowed. false - after drawing is finished (by doubleclick), will stop drawing tool, but keeps selection on the map. 'single' - selection will be removed before drawing a new selection. 'multiGeom' - gathers drawn shapes into a single feature with multigeometry instead of sending multiple features in DrawingEvent. | true |
showMeasureOnMap | Boolean | Use this parameter for displaying measurement result on line or polygon. true - if measure result should be displayed on drawing feature. | false |
geojson | Object|String | FeatureCollection | Feature | Geometry in GeoJson format | null |
buffer | Number | Buffer for drawing buffered line and dot. | null |
limits | Object | Optional limits for validating drawn or modified geometry. | {selfIntersection: true} |
style | Object | Styles for draw, modify and intersect mode. If options don't include custom style, sets default styles. See styling example at the last example of this page. | { fill : { color : 'rgba(255,0,255,0.2)' }, stroke : { color : 'rgba(0,0,0,1)', width : 2 }, image : { radius: 4, fill : { color : 'rgba(0,0,0,1)' } }, text : { scale : 1.3, fill : { color : 'rgba(0,0,0,1)' }, stroke : { color : 'rgba(255,255,255,1)', width : 2 } } } |
Limits are used for validating finished geometry. If geometry is invalid, user will see warning text. Parameters for limits-object:
Name | Type | Description | Default value |
---|---|---|---|
selfIntersection | Boolean | Self-intersecting polygons are not allowed. | true |
area | Number | Maximum size for valid area in m2. | infinite |
length | Number | Maximum length for valid line in meters. | infinite |
Examples
Start to draw for 'measure' functionality and keep the drawing on the map:
Oskari.getSandbox().postRequestByName('DrawTools.StartDrawingRequest', ['measure', 'LineString', {
showMeasureOnMap: true
}]);
Start to draw for 'measure' functionality and remove previous drawing when new drawing is started:
Oskari.getSandbox().postRequestByName('DrawTools.StartDrawingRequest', ['select', 'Box', {
showMeasureOnMap: true,
allowMultipleDrawing: 'single'
}]);
Start to draw for 'bufferedselect' functionality without modify:
var sb = Oskari.getSandbox();
sb.postRequestByName('DrawTools.StartDrawingRequest', ['bufferedselect', 'LineString', {
buffer: 50,
modifyControl: false
}]);
DrawingEvent's bufferedGeoJson can be used for selection.
Start to draw a polygon for 'myplaces' functionality with specific style and area size limit:
const style = {
draw : {
fill : {
color: 'rgba(238,0,0,0.3)'
},
stroke : {
color: 'rgba(0,0,0,1)',
width: 2
},
image : {
radius: 4,
fill: {
color: 'rgba(0,0,0,1)'
}
}
},
modify : {
fill : {
color: 'rgba(153,102,255,0.3)'
},
stroke : {
color: 'rgba(0,0,0,1)',
width: 2
},
image : {
radius: 4,
fill: {
color: 'rgba(0,0,0,1)'
}
}
},
invalid : {
fill : {
color: 'rgba(255,255,255,0.3)'
},
stroke : {
color: 'rgba(0,0,0,1)',
width: 2,
lineDash: 5
},
image : {
radius: 4,
fill: {
color: 'rgba(0,0,0,1)'
}
}
}
};
Oskari.getSandbox().postRequestByName('DrawTools.StartDrawingRequest', ['myplaces', 'Polygon', {
showMeasureOnMap: true,
style: style,
limits: { area: 10000 }
}]);
Start to modify a polygon for 'myplaces' functionality:
const geometry = {
"type": "Polygon",
"coordinates": [
[
[420440.7092535111, 6814639.756003482],
[520280.7092535111, 6814639.756003482],
[520280.7092535111, 6870043.731054378],
[420440.7092535111, 6890043.731054378],
[420440.7092535111, 6814639.756003482]
]
]
};
Oskari.getSandbox().postRequestByName('DrawTools.StartDrawingRequest', ['myplaces', 'Polygon', {
showMeasureOnMap: true,
drawControl: false,
geojson: geometry
}]);
Implementing bundle
Related API
- StopDrawingRequest
- DrawingEvent