geometryEditor.Polygon
Extends IGeometryEditor.
The "Polygon" geometry editor.
Constructor | Fields | Events | Methods
Constructor
geometryEditor.Polygon(geometry[, options])
Parameters:
Parameter |
Default value |
Description |
— |
Type: IPolygonGeometry The "Polygon" geometry. |
|
— |
Type: Object Options for the geometry editor. |
|
— |
Type: Function Handler for double-clicking a vertex. Accepts a reference to a model of the vertex being edited. By default, the handler is defined by the function that removes the corresponding vertex. |
|
"arrow" |
Type: Boolean The mouse cursor in the mode for adding new vertexes. |
|
true |
Type: Boolean Allows to put points on top of map objects in the mode for adding new vertexes. |
|
true |
Type: Boolean Allows the intermediate vertices placemarks to use options with postfixes linked to the current state of the placemark. The following postfixes are available:
|
|
— |
Type: Function Class of the layout for interim placemarks. |
|
Infinity |
Type: Number The maximum allowable number of vertexes on a polygon. |
|
— |
Type: Function Context menu dispatcher for the menu that opens when clicking on a vertex. Accepts two arguments:
|
|
0 |
Type: Number The minimum allowable number of vertexes on a polygon. |
|
true |
Type: Boolean Enables autopan of the map when dragging a vertex on the boundary. |
|
true |
Type: Boolean Whether to use map margins in drawing mode. |
|
true |
Type: Boolean Allows the vertices placemarks to use options with postfixes linked to the current state of the vertex. The following postfixes are available:
|
|
— |
Type: Function Class of the layout for placemarks on polygon vertexes. |
* Mandatory parameter/option.
Fields
Name |
Type |
Description |
Event manager. Inherited from IEventEmitter. |
||
The geometry being edited. Inherited from IGeometryEditor. |
||
Options manager. Inherited from ICustomizable. |
||
Manager for the state of the geometry editor. Data fields that are available via the "get" and "set" methods:
|
Events
Name |
Description |
Event preceding the "edgedrag" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Event preceding the "edgedragstart" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Event preceding the "vertexadd" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Event preceding the "vertexdrag" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Event preceding the "vertexdragstart" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Event preceding the "vertexdraw" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Enabling the mode for adding new vertexes. Instance of the Event class. |
|
Disabling the mode for adding new vertexes. Instance of the Event class. |
|
Dragging an interim placemark. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
End of dragging an interim placemark. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Start of dragging an interim placemark. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Enabling the mode for editing vertexes. Instance of the Event class. |
|
Disabling the mode for editing vertexes. Instance of the Event class. |
|
Enabling the zoom mode. Instance of the Event class. |
|
Disabling the zoom mode. Instance of the Event class. |
|
Change to the object options. Inherited from ICustomizable. |
|
Change to the geometry editor state. Instance of the Event class. Inherited from IGeometryEditor. |
|
Adding a new vertex. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Dragging a vertex. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
End of vertex dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Start of vertex dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Drawing a new vertex. This event usually precedes the add vertex event, and occurs when the mouse moves and the mode for adding new vertexes is enabled. Based on data passed in this event, guide lines are displayed in vertex drawing mode. Instance of the Event class. Names of fields that are available via the Event.get method:
|
Methods
Name |
Returns |
Description |
getModel() |
Returns the promise object, which is confirmed by the model object at the time it is actually created, or is rejected with one of the following error messages:
|
|
Returns the editor's model, or null if it is missing at the time of the call. |
||
getView() |
Returns the promise object, which is confirmed by the representation object at the time it is actually created, or is rejected with one of the following error messages:
|
|
Returns the editor's representation, or null if it is missing at the time of the call. |
||
Enables drawing mode (for adding new vertexes to a polygon). Enabling occurs asynchronously. |
||
Enables edit mode (for adding new vertexes to a polygon). Enabling occurs asynchronously. |
||
Enables the zoom mode for a polygon. Enabling occurs asynchronously. |
||
Disables drawing mode (for adding new vertexes to a polygon). |
||
Disables edit mode. |
||
Disables the zoom mode. |
Fields details
state
{IDataManager} state
Manager for the state of the geometry editor.
Data fields that are available via the "get" and "set" methods:
- editing - Checks whether editing mode is enabled. Type - Boolean. Default value - false.
- drawing - Checks whether vertex drawing mode is enabled. Type - Boolean. Default value - false.
- drawingFrom - Checks how new points are added in drawing mode. Accepts one of two string values: "begin" - points are added at the beginning of the polygon; "end" - points are added at the end.
- drawingFromIndex - The index of the polygon vertex after which new points will be added in drawing mode. This field is available only during editing, because saving changes rearranges the order of vertexes in the polygon so that the point with the specified index becomes the last one. Type - integer.
- drawingPath - The index of the polygon contour where new points are added in drawing mode. Type - integer. Default value - 0.
Events details
beforeedgedrag
Event preceding the "edgedrag" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- pixelOffset - Array of two numbers that describe the pixel offset at this step.
- edgeModel - Reference to the model of the draggable placemark.
- globalPixels - Coordinates of the draggable placemark, in global pixel coordinates.
Names of methods that are accessible via Event.callMethod: - setPixelOffset - This method is for correcting the value of the pixel offset that will actually be applied. It takes an argument with the new pixel offset in the form of an array of two numbers.
If the Event.preventDefault method is called for this event, a subsequent "edgedrag" event will be canceled.
beforeedgedragstart
Event preceding the "edgedragstart" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- domEvent - Source DOM event (as a DomEvent object), if there is one.
- edgeModel - Reference to the model of the draggable placemark.
- globalPixels - Coordinates of the draggable placemark, in global pixel coordinates.
If the Event.preventDefault method is called for this event, any subsequent dragging, as well as the "edgedragstart" event, will be canceled.
beforevertexadd
Event preceding the "vertexadd" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- parentModel - Reference to the parent data model for the vertex being added.
- vertexIndex - Index of the vertex being added.
- globalPixels - Coordinates of the vertex being added, in global pixel coordinates.
Names of methods that are accessible via Event.callMethod: - setGlobalPixels - Use this method to correct the coordinate values of the added vertex. It takes an argument with the new global pixel coordinates of the vertex as an array of two numbers.
If the Event.preventDefault method is called for this event, a subsequent "vertexadd" event will be canceled.
Examples:
1.
// Prohibiting adding new vertexes further than 100 pixels from the map center.
polygon.editor.events.add("beforevertexadd", function (event) {
var mapGlobalPixelCenter = geoMap.getGlobalPixelCenter();
var globalPixels = event.get("globalPixels");
var vector = [mapGlobalPixelCenter[0] - globalPixels[0], mapGlobalPixelCenter[1] - globalPixels[1]];
var vectorLength = Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1]);
if (dist > 100) {
event.preventDefault();
}
});
2.
// Adjusting coordinates of the add vertex events so they fall inside a square
// with 100-pixel sides that is centered at the map center.
polygon.editor.events.add(["beforevertexdraw", "beforevertexadd"], function (event) {
var mapGlobalPixelCenter = geoMap.getGlobalPixelCenter();
var globalPixels = event.get("globalPixels");
var pixelBounds = [
[mapGlobalPixelCenter[0] - 100, mapGlobalPixelCenter[1] - 100],
[mapGlobalPixelCenter[0] + 100, mapGlobalPixelCenter[1] + 100]
];
event.callMethod("setGlobalPixels", [
Math.max(Math.min(globalPixels[0], pixelBounds[1][0]), pixelBounds[0][0]),
Math.max(Math.min(globalPixels[1], pixelBounds[1][1]), pixelBounds[0][1])
]);
});
beforevertexdrag
Event preceding the "vertexdrag" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- pixelOffset - Array of two numbers that describe the pixel offset at this step.
- vertexModel - Reference to the model of the draggable vertex.
- globalPixels - Coordinates of the draggable vertex, in global pixel coordinates.
Names of methods that are accessible via Event.callMethod: - setPixelOffset - This method is for correcting the value of the pixel offset that will actually be applied. It takes an argument with the new pixel offset in the form of an array of two numbers.
If the Event.preventDefault method is called for this event, a subsequent "vertexdrag" event will be canceled.
beforevertexdragstart
Event preceding the "vertexdragstart" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- domEvent - Source DOM event (as a DomEvent object), if there is one.
- vertexModel - Reference to the model of the draggable vertex.
- globalPixels - Coordinates of the draggable vertex, in global pixel coordinates.
If the Event.preventDefault method is called for this event, any subsequent dragging, as well as the"vertexdragstart" event, will be canceled.
Example:
// Prohibiting dragging vertexes with the index 0 in a contour with the same index.
polygon.editor.events.add("beforevertexdragstart", function (event) {
var vertexModel = event.get("vertexModel");
var pathModel = vertexModel.getParent();
if (pathModel.getIndex() == 0 && vertexModel.getIndex() == 0) {
event.preventDefault();
}
});
beforevertexdraw
Event preceding the "vertexdraw" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- parentModel - Reference to the parent data model for the vertex being added.
- vertexIndex - Index of the vertex being added.
- globalPixels - Coordinates of the vertex being added, in global pixel coordinates.
Names of methods that are accessible via Event.callMethod: - setGlobalPixels - Use this method to correct the coordinate values of the added vertex. It takes an argument with the new global pixel coordinates of the vertex as an array of two numbers.
If the Event.preventDefault method is called for this event, a subsequent "vertexdraw" event will be canceled.
drawingstart
Enabling the mode for adding new vertexes. Instance of the Event class.
drawingstop
Disabling the mode for adding new vertexes. Instance of the Event class.
edgedrag
Dragging an interim placemark. Instance of the Event class. Names of fields that are available via the Event.get method:
- pixelOffset - Array of two numbers that describe the pixel offset at this step.
- edgeModel - Reference to the model of the draggable placemark.
- globalPixels - Coordinates of the draggable placemark, in global pixel coordinates.
edgedragend
End of dragging an interim placemark. Instance of the Event class. Names of fields that are available via the Event.get method:
- edgeModel - Reference to the model of the draggable placemark.
- globalPixels - Coordinates of the draggable placemark, in global pixel coordinates.
edgedragstart
Start of dragging an interim placemark. Instance of the Event class. Names of fields that are available via the Event.get method:
- domEvent - Source DOM event (as a DomEvent object), if there is one.
- edgeModel - Reference to the model of the draggable placemark.
- globalPixels - Coordinates of the draggable placemark, in global pixel coordinates.
editingstart
Enabling the mode for editing vertexes. Instance of the Event class.
editingstop
Disabling the mode for editing vertexes. Instance of the Event class.
framingstart
Enabling the zoom mode. Instance of the Event class.
framingstop
Disabling the zoom mode. Instance of the Event class.
vertexadd
Adding a new vertex. Instance of the Event class. Names of fields that are available via the Event.get method:
- parentModel - Reference to the parent data model for the vertex that was added.
- vertexIndex - Index of the vertex that was added.
- globalPixels - Coordinates of the vertex that was added, in global pixel coordinates.
vertexdrag
Dragging a vertex. Instance of the Event class. Names of fields that are available via the Event.get method:
- pixelOffset - Array of two numbers that describe the pixel offset at this step.
- vertexModel - Reference to the model of the draggable vertex.
- globalPixels - Coordinates of the draggable vertex, in global pixel coordinates.
vertexdragend
End of vertex dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
- vertexModel - Reference to the model of the draggable vertex.
- globalPixels - Coordinates of the draggable vertex, in global pixel coordinates.
vertexdragstart
Start of vertex dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
- domEvent - Source DOM event (as a DomEvent object), if there is one.
- vertexModel - Reference to the model of the draggable vertex.
- globalPixels - Coordinates of the draggable vertex, in global pixel coordinates.
vertexdraw
Drawing a new vertex. This event usually precedes the add vertex event, and occurs when the mouse moves and the mode for adding new vertexes is enabled. Based on data passed in this event, guide lines are displayed in vertex drawing mode. Instance of the Event class. Names of fields that are available via the Event.get method:
- parentModel - Reference to the parent data model for the vertex being added.
- vertexIndex - Index of the vertex being added.
- globalPixels - Coordinates of the vertex being added, in global pixel coordinates.
Methods details
getModel
{vow.Promise} getModel()
Returns the promise object, which is confirmed by the model object at the time it is actually created, or is rejected with one of the following error messages:
- Canceled - Editing mode is disabled until the model is actually created.
- Editor wasn't started - Editing mode is not enabled.
getModelSync
{geometryEditor.model.RootPolygon|null} getModelSync()
Returns the editor's model, or null if it is missing at the time of the call.
getView
{vow.Promise} getView()
Returns the promise object, which is confirmed by the representation object at the time it is actually created, or is rejected with one of the following error messages:
- Canceled - Editing mode is disabled until the representation is actually created.
- Editor wasn't started - Editing mode is not enabled.
getViewSync
{geometryEditor.view.MultiPath|null} getViewSync()
Returns the editor's representation, or null if it is missing at the time of the call.
startDrawing
{vow.Promise} startDrawing()
Enables drawing mode (for adding new vertexes to a polygon). Enabling occurs asynchronously.
Returns the promise object, which is confirmed when drawing mode has actually started, or is rejected with one of the following error messages:
- Canceled - Drawing mode is disabled until it is actually started.
startEditing
{vow.Promise} startEditing()
Enables edit mode (for adding new vertexes to a polygon). Enabling occurs asynchronously.
Returns the promise object, which is confirmed when editing mode has actually started, or is rejected with one of the following error messages:
- Canceled - Editing mode is disabled until it is actually started.
startFraming
{vow.Promise} startFraming()
Enables the zoom mode for a polygon. Enabling occurs asynchronously.
Returns the promise object that is confirmed when zoom mode actually starts.
stopDrawing
{} stopDrawing()
Disables drawing mode (for adding new vertexes to a polygon).
stopEditing
{} stopEditing()
Disables edit mode.
stopFraming
{} stopFraming()
Disables the zoom mode.
Mandatory parameter/option.