GeoObject
Extends IGeoObject.
Geo object. Can be displayed as a placemark, polyline, polygon, etc., depending on the geometry type. You can also use auxiliary classes for simplified creation of geo objects with a specific geometry type.
See PlacemarkPolylinePolygonCircleRectangle
Constructor | Fields | Events | Methods
Constructor
GeoObject([feature[, options]])
Parameters:
Parameter |
Default value |
Description |
— |
Type: Object Geo object description. |
|
— |
Type: IGeometry|IGeometryJson Geo object geometry. Can be either set directly by the object, or in the form of an object of the JSON representation of the geometry. Examples of classes and objects that can represent a geometry - geometry.Point, geometry.json.Point. |
|
— |
Type: IDataManager|Object Geo object data. Can be set as a class instance implementing the IDataManager interface, or as a hash. When options are set to default values, the following data fields are interpreted by a geo object:
|
|
— |
Type: Object Geo object options. Using this parameter, you can set options for the geo object itself, as well as for its parts:
|
|
"default#circle" |
Type: String|Function Key identifier from overlay.storage or the overlay class. The generator function accepts three parameters:
|
|
"pointer" |
Type: String Type of cursor over a geo object. |
|
false |
Type: Boolean Checks whether the geo object can be dragged. |
|
true |
Type: Boolean Whether the shape is filled. |
|
"0066ff99" |
Type: String Fill color. |
|
— |
Type: String Background image. When this option is enabled in stretch mode, the "fillColor" value is ignored. |
|
'stretch' |
Type: String Type of background fill. Accepts one of two values:
|
|
1 |
Type: Number Fill transparency. |
|
true |
Type: Boolean Checks whether the geo object has the "balloon" field. |
|
true |
Type: Boolean Checks whether the geo object has the "hint" field. |
|
true |
Type: Boolean Hide the icon when opening the balloon. |
|
188 |
Type: Number Maximum width of the placemark caption. |
|
— |
Type: String Icon color. This option is used for standard icons in browsers that support SVG. |
|
— |
Type: Function|String Layout for icon contents. (Type: constructor for an object with the ILayout interface, or its key in the storage). |
|
— |
Type: Number[] Pixel offset for the icon contents relative to the parent element. Used in the default#imageWithContent layout. |
|
— |
Type: Number[] Padding for the icon contents. |
|
— |
Type: Number[] Size of contents. Used in the default#imageWithContent layout. |
|
[[0, 0], [{imageWidth}, {imageHeight}]] |
Type: Number[][] A rectangular area (the upper-left and lower-right corners are specified) that will be cut from the source image file and scaled to icon size (for example, for using sprites). By default, the entire source picture is used. |
|
— |
Type: String URL of the icon's graphic file. Used only in combination with layouts (iconLayout) 'default ' #image' and 'default#imageWithContent'. |
|
— |
Type: Number[] Pixel offset for the icon image inside the parent element. |
|
— |
Type: IShape|null The hotspot shape. If not set, the rectangular shape based on the size and offset of the icon will be calculated automatically. The coordinates of the figure geometry are counted from the anchor point. Used only in combination with layouts (iconLayout) 'default ' #image' and 'default#imageWithContent'. |
|
— |
Type: Number[] Size of the icon, in pixels. |
|
— |
Type: Function|String Icon layout. (Type: constructor for an object with the ILayout interface, or its key in the storage). |
|
— |
Type: Number Maximum height of an icon with contents. |
|
— |
Type: Number Maximum width of an icon with contents. |
|
[0, 0] |
Type: Number[] Pixel offset of the upper-left corner of the icon relative to the geographic anchor point of a placemark. |
|
false |
Type: Boolean Flag for whether the icon has a shadow. |
|
[[0, 0], [{imageWidth}, {imageHeight}]] |
Type: Number[][] A rectangular area (the upper-left and lower-right corners are specified) that will be cut from the source image file and scaled to shadow size (for example, for using sprites). By default, the entire source picture is used. |
|
— |
Type: String URL of the graphic file for the icon shadow. Used only in combination with layouts (iconShadowLayout) 'default ' #image' and 'default#imageWithContent'. |
|
— |
Type: Number[] Pixel offset for the icon shadow image inside the parent element. |
|
— |
Type: Number[] Size of the icon shadow. |
|
— |
Type: Function|String Layout for the icon shadow. (Type: constructor for an object with the ILayout interface, or its key in the storage). |
|
— |
Type: Number[] The pixel offset of the icon shadow relative to its set position. |
|
— |
Type: Boolean Enables to automatically modify z-index of the geo object depending on its state. By default, takes the true value for geometry.Point and false for other geometries. |
|
"default#geoObject" |
Type: String Interactivity model. Available keys and their values are listed in the description of interactivityModel.storage. |
|
"default#polyline" |
Type: String|Function Key identifier from overlay.storage or the overlay class. The generator function accepts three parameters:
|
|
1 |
Type: Number Transparency. |
|
true |
Type: Boolean Checks whether to show the balloon when the geo object is clicked on. |
|
false |
Type: Boolean Checks whether to show an empty balloon when the geo object is clicked on. |
|
false |
Type: Boolean Checks whether to show an empty hint when the mouse pointer hovers over the geo object. |
|
true |
Type: Boolean Checks whether to show a hint when the mouse pointer hovers over the geo object. |
|
true |
Type: Boolean Whether the shape has an outline. |
|
— |
Type: String The key of the pane where the geo object overlay is placed. The default value is defined by the current overlay. |
|
"default#placemark" |
Type: String|Function Key identifier from overlay.storage or the overlay class. The generator function accepts three parameters:
|
|
"default#polygon" |
Type: String|Function Key identifier from overlay.storage or the overlay class. The generator function accepts three parameters:
|
|
— |
Type: String Key for the geo object's preset options. The list of keys is provided in the description of option.presetStorage. |
|
"default#rectangle" |
Type: String|Function Key identifier from overlay.storage or the overlay class. The generator function accepts three parameters:
|
|
false |
Type: Boolean true – when dragging an object, set the cursor to "grabbing" for both the object and the map; false – only use the "grabbing" cursor on the object. |
|
"0066ffff" |
Type: String|String[] Color of the line or outline. You can set multiple values for a multistroke outline. |
|
1 |
Type: Number|Number[] Transparency of the line or outline. You can set multiple values for a multistroke outline. |
|
— |
Type: String|Object|String[]|Object[] Style of the line or outline. You can set multiple values for a multistroke outline. Available styles are listed in the graphics.style.stroke object. |
|
1 |
Type: Number|Number[] Thickness of the line or outline. You can set multiple values for a multistroke outline. |
|
false |
Type: Boolean Enables synchronously adding an overlay to the map. By default, overlays are added to the map asynchronously to prevent the browser from hanging when adding a large number of geo objects. However, adding asynchronously does not allow accessing the overlay immediately after adding a geo object to the map. |
|
true |
Type: Boolean When an object is dragged to the edge of the map, the map center changes automatically. Whether to use map margins when automatically shifting the map center with map.margin.Manager. |
|
true |
Type: Boolean Checks geo object visibility. |
|
— |
Type: Number The z-index of a geo object in its normal state. Lowest priority. |
|
— |
Type: Number The z-index of a geo object with an open balloon. Highest priority. |
|
— |
Type: Number The z-index of a geo object that is being dragged. |
|
— |
Type: Number The z-index of a geo object when the mouse pointer is hovering over it. |
Examples:
1.
var myGeoObject = new ymaps.GeoObject({
// Defining a "Polyline" type of geometry.
geometry: {
type: "LineString",
coordinates: [
[55.75, 37.61], [52.51, 13.38]
]
},
// Defining the geo object data.
properties: {
hintContent: "Moscow-Berlin"
}
}, {
// Enabling the display mode as geodesic curves.
geodesic: true,
// Setting the width to 5 pixels.
strokeWidth: 5,
// Setting the line color.
strokeColor: "#F008"
});
// Adding the geo object to the map.
geoMap.geoObjects.add(myGeoObject);
2.
var myGeoObject = new ymaps.GeoObject({
// Defining a "Point" geometry.
geometry: {
type: "Point",
coordinates: [55.75, 37.61]
},
// Defining the geo object data.
properties: {
hintContent: "Moscow",
balloonContentHeader: "Moscow",
balloonContentBody: "Capital of Russia",
population: 11848762
}
}, {
// Setting the preset for a placemark with a dot and no content.
preset: "islands#redDotIcon",
// Enabling dragging.
draggable: true,
// Overriding the layout for the content in the lower part of the balloon.
balloonContentFooterLayout: ymaps.templateLayoutFactory.createClass(
'population: {{ properties.population }}, coordinates: {{ geometry.coordinates }}'
),
// Disabling the delay for closing the popup hint.
hintCloseTimeout: null
});
// Adding the geo object to the map.
geoMap.geoObjects.add(myGeoObject);
Fields
Name |
Type |
Description |
Balloon for a geo object. |
||
Editor for the geo object geometry. |
||
Event manager. |
||
IGeometry|null |
Geo object geometry. |
|
Geo object hint. |
||
Geo object options manager. |
||
Geo object data manager. |
||
State of the geo object. Defined by the following fields:
|
Events
Name |
Description |
Closing the balloon. Instance of the Event class. |
|
Opening a balloon on a geo object. Instance of the Event class. |
|
Event preceding the "drag" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Event preceding the "dragstart" event. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Single left-click on the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
Calls the element's context menu. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
Double left-click on the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
Dragging a geo object. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
End of geo object dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Start of geo object dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Change in the state of the editor for the geo object's geometry. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
Change to the geo object geometry. Instance of the Event class. Names of fields that are available via the Event.get method:
Inherited from IGeoObject. |
|
Closing the hint. Instance of the Event class. |
|
Opening a hint on a geo object. Instance of the Event class. |
|
Map reference changed. Data fields:
Inherited from IParentOnMap. |
|
Pressing the mouse button over the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
Pointing the cursor at the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
Moving the cursor off of the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
Moving the cursor over the object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
Letting go of the mouse button over an object. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
|
End of multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface. Inherited from IDomEventEmitter. |
|
Repeating event during multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface with information about touches. Defines the touches property, which contains a list of touches. Every touch is described by an object that contains the following fields:
Inherited from IDomEventEmitter. |
|
Start of multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface with information about touches. Defines the touches property, which contains a list of touches. Every touch is described by an object that contains the following fields:
Inherited from IDomEventEmitter. |
|
Change to the object options. Inherited from ICustomizable. |
|
Change to the geo object overlay. Instance of the Event class. Names of fields that are available via the Event.get method:
Inherited from IGeoObject. |
|
The parent object reference changed. Data fields:
Inherited from IChild. |
|
Change to the geo object data. Instance of the Event class. Names of fields that are available via the Event.get method:
Inherited from IGeoObject. |
|
Mouse wheel scrolling. When using, keep in mind that mouse events are emulated when a touch screen is used. Instance of the MapEvent class. More information is available in domEvent.manager. Inherited from IDomEventEmitter. |
Methods
Name |
Returns |
Description |
getMap() |
Returns reference to the map. Inherited from IParentOnMap. |
|
Returns the promise object, which is confirmed by the overlay object at the time it is actually created, or is rejected with an appropriate error message. Inherited from IGeoObject. |
||
IOverlay|null |
The method provides synchronous access to the overlay. Inherited from IGeoObject. |
|
IParentOnMap|null |
Returns link to the parent object, or null if the parent element was not set. Inherited from IChildOnMap. |
|
Sets the parent object. If the null value is passed, the manager element will only be deleted from the current parent object. Inherited from IChildOnMap. |
Fields details
balloon
{geoObject.Balloon} balloon
Balloon for a geo object.
editor
{IGeometryEditor} editor
Editor for the geo object geometry.
Example:
// Start editing the geo object geometry.
geoObject.editor.startEditing();
// ...
// Finish editing.
geoObject.editor.stopEditing();
events
{event.Manager} events
Event manager.
geometry
{IGeometry|null} geometry
Geo object geometry.
Example:
// When changing the coordinates of a geo object's geometry, we set the map borders
// so that the geo object is covered entirely.
myMap.geoObjects.add(myGeoObject);
myGeoObject.geometry.events.add("change", function () {
myMap.setBounds(myGeoObject.geometry.getBounds());
});
hint
{geoObject.Hint} hint
Geo object hint.
options
{option.Manager} options
Geo object options manager.
properties
{data.Manager} properties
Geo object data manager.
Example:
// When changing data, output a custom ID
// if the object's "synchronized" field is set to false.
myGeoObject.properties.events.add("change", function () {
if (!myGeoObject.properties.get("synchronized")) {
console.log(myGeoObject.properties.get("myID"));
}
});
state
{data.Manager} state
State of the geo object. Defined by the following fields:
- active: Boolean - Indicates that a balloon is open on the geo object.
- hover: Boolean - Indicates that the mouse is currently pointed at the geo object.
- drag: Boolean - Indicates that the geo object is being dragged
Events details
balloonclose
Closing the balloon. Instance of the Event class.
balloonopen
Opening a balloon on a geo object. Instance of the Event class.
beforedrag
Event preceding the "drag" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- position - Coordinates relative to the document. Array in the format [pageX, pageY].
- pixelOffset - Array of two numbers that describe the pixel offset at this step.
- domEvent - Source DOM event (as a DomEvent object), if there is one.
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 drag event will be canceled.
Example:
// Allowing dragging the geo object only along the horizontal axis.
geoObject.events.add("beforedrag", function (event) {
var originalOffset = event.get("pixelOffset");
event.callMethod("setPixelOffset", [originalOffset[0], 0]);
});
beforedragstart
Event preceding the "dragstart" event. Instance of the Event class. Names of fields that are available via the Event.get method:
- position - Coordinates relative to the document. Array in the format [pageX, pageY].
- domEvent - Source DOM event (as a DomEvent object), if there is one.
If the Event.preventDefault method is called for this event, any subsequent dragging, as well as the "dragstart" event, will be canceled.
drag
Dragging a geo object. Instance of the Event class. Names of fields that are available via the Event.get method:
- position - Coordinates relative to the document. Array in the format [pageX, pageY].
- pixelOffset - Array of two numbers that describe the pixel offset at this step.
- domEvent - Source DOM event (as a DomEvent object), if there is one.
dragend
End of geo object dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
- position - Coordinates relative to the document. Array in the format [pageX, pageY].
- domEvent - Source DOM event (as a DomEvent object), if there is one.
dragstart
Start of geo object dragging. Instance of the Event class. Names of fields that are available via the Event.get method:
- position - Coordinates relative to the document. Array in the format [pageX, pageY].
- domEvent - Source DOM event (as a DomEvent object), if there is one.
editorstatechange
Change in the state of the editor for the geo object's geometry. Instance of the Event class. Names of fields that are available via the Event.get method:
- originalEvent - Original event of the geometry editor.
hintclose
Closing the hint. Instance of the Event class.
hintopen
Opening a hint on a geo object. Instance of the Event class.