# OpenLayers.Marker

Instances of OpenLayers.Marker are a combination of a OpenLayers.LonLat and an OpenLayers.Icon.

Markers are generally added to a special layer called OpenLayers.Layer.Markers.

#### Example

>     var markers = new OpenLayers.Layer.Markers( "Markers" );
>     map.addLayer(markers);

>     var size = new OpenLayers.Size(21,25);
>     var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
>     var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset);
>     markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon));
>     markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon.clone()));

Note that if you pass an icon into the Marker constructor, it will take that icon and use it. This means that you should not share icons between markers -- you use them once, but you should clone() for any additional markers using that same icon.

Summary

OpenLayers.Marker | Instances of OpenLayers.Marker are a combination of a OpenLayers.LonLat and an OpenLayers.Icon.
Properties |
icon | {OpenLayers.Icon} The icon used by this marker.
lonlat | {OpenLayers.LonLat} location of object
events | {OpenLayers.Events} the event handler.
map | {OpenLayers.Map} the map this marker is attached to
Constructor |
OpenLayers.Marker |
Functions |
destroy | Destroy the marker.
draw | Calls draw on the icon, and returns that output.
erase | Erases any drawn elements for this marker.
moveTo | Move the marker to the new location.
isDrawn | {Boolean} Whether or not the marker is drawn.
onScreen | {Boolean} Whether or not the marker is currently visible on screen.
inflate | Englarges the markers icon by the specified ratio.
setOpacity | Change the opacity of the marker by changin the opacity of its icon
setUrl | Change URL of the Icon Image.
display | Hide or show the icon
defaultIcon | Creates a default OpenLayers.Icon.

### Properties

### icon

{OpenLayers.Icon} The icon used by this marker.

### lonlat

{OpenLayers.LonLat} location of object

### events

{OpenLayers.Events} the event handler.

### map

{OpenLayers.Map} the map this marker is attached to

### Constructor

### OpenLayers.Marker

#### Parameters

lonlat | {OpenLayers.LonLat} the position of this marker
icon | {OpenLayers.Icon} the icon for this marker

### Functions

### destroy

> destroy: function()

Destroy the marker. You must first remove the marker from any layer which it has been added to, or you will get buggy behavior. (This can not be done within the marker since the marker does not know which layer it is attached to.)

### draw

> draw: function( | px | )

Calls draw on the icon, and returns that output.

#### Parameters

px | {OpenLayers.Pixel}

#### Returns

{DOMElement} A new DOM Image with this marker’s icon set at the location passed-in

### erase

> erase: function()

Erases any drawn elements for this marker.

### moveTo

> moveTo: function ( | px | )

Move the marker to the new location.

#### Parameters

px | {OpenLayers.Pixel} the pixel position to move to

### isDrawn

> isDrawn: function()

#### Returns

{Boolean} Whether or not the marker is drawn.

### onScreen

> onScreen:function()

#### Returns

{Boolean} Whether or not the marker is currently visible on screen.

### inflate

> inflate: function( | inflate | )

Englarges the markers icon by the specified ratio.

#### Parameters

inflate | {float} the ratio to enlarge the marker by (passing 2 will double the size).

### setOpacity

> setOpacity: function( | opacity | )

Change the opacity of the marker by changin the opacity of its icon

#### Parameters

opacity | {float} Specified as fraction (0.4, etc)

### setUrl

> setUrl: function( | url | )

Change URL of the Icon Image.

url | {String}

### display

> display: function( | display | )

Hide or show the icon

display | {Boolean}

### defaultIcon

> OpenLayers.Marker.defaultIcon = function()

Creates a default OpenLayers.Icon.

#### Returns

{OpenLayers.Icon} A default OpenLayers.Icon to use for a marker

This class represents a longitude and latitude pair
The icon represents a graphical icon on the screen.
Instances of OpenLayers.Map are interactive maps embedded in a web page.

> destroy: function()

Destroy the marker.

> draw: function( | px | )

Calls draw on the icon, and returns that output.

> erase: function()

Erases any drawn elements for this marker.

> moveTo: function ( | px | )

Move the marker to the new location.

> isDrawn: function()

{Boolean} Whether or not the marker is drawn.

> onScreen:function()

{Boolean} Whether or not the marker is currently visible on screen.

> inflate: function( | inflate | )

Englarges the markers icon by the specified ratio.

> setOpacity: function( | opacity | )

Change the opacity of the marker by changin the opacity of its icon

> setUrl: function( | url | )

Change URL of the Icon Image.

> display: function( | display | )

Hide or show the icon

> OpenLayers.Marker.defaultIcon = function()

Creates a default OpenLayers.Icon.
This class represents a screen coordinate, in x and y coordinates
Close