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.
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
var size = new OpenLayers.Size(10,17);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.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.
| 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. |
| moveTo | Move the marker to the new location. |
| 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. |
{OpenLayers.Icon} The icon used by this marker.
{OpenLayers.LonLat} location of object
{OpenLayers.Events} the event handler.
{OpenLayers.Map} the map this marker is attached to
| lonlat | {OpenLayers.LonLat} the position of this marker |
| icon | {OpenLayers.Icon} the icon for this marker |
draw: function( px )
Calls draw on the icon, and returns that output.
| px | {OpenLayers.Pixel} |
{DOMElement} A new DOM Image with this marker’s icon set at the location passed-in
moveTo: function ( px )
Move the marker to the new location.
| px | {OpenLayers.Pixel} the pixel position to move to |
OpenLayers.Marker.defaultIcon = function()
Creates a default OpenLayers.Icon.
{OpenLayers.Icon} A default OpenLayers.Icon to use for a marker
Destroy the marker.
destroy: function()
Calls draw on the icon, and returns that output.
draw: function( px )
Move the marker to the new location.
moveTo: function ( px )
{Boolean} Whether or not the marker is currently visible on screen.
onScreen:function()
Englarges the markers icon by the specified ratio.
inflate: function( inflate )
Change the opacity of the marker by changin the opacity of its icon
setOpacity: function( opacity )
Change URL of the Icon Image.
setUrl: function( url )
Hide or show the icon
display: function( display )
Creates a default OpenLayers.Icon.
OpenLayers.Marker.defaultIcon = function()