Harry Wood
home
>
maps
>
examples
> openlayers >
OpenLayers Vector Marker
OpenLayers Vector Marker
Confusingly it's better to use a Vector layer than the old Marker layer type, even if you wanted markers. Vector layers are more flexible
<html> <head><title>OpenLayers Vector Marker Example</title></head> <body> <div id="mapdiv"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.11/lib/OpenLayers.js"></script> <script> map = new OpenLayers.Map("mapdiv"); map.addLayer(new OpenLayers.Layer.OSM()); epsg4326 = new OpenLayers.Projection("EPSG:4326"); //WGS 1984 projection projectTo = map.getProjectionObject(); //The map projection (Spherical Mercator) var lonLat = new OpenLayers.LonLat( -0.1279688, 51.5077286 ).transform(epsg4326, projectTo); var zoom=16; map.setCenter (lonLat, zoom); //The vector layer var vectorLayer = new OpenLayers.Layer.Vector("Overlay"); //Make the feature a plain OpenLayers marker var feature = new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point( -0.1279688, 51.5077286 ).transform(epsg4326, projectTo), {description:'This is the value of<br>the description attribute'} , {externalGraphic: './img/marker.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset:-12, graphicYOffset:-25 } ); vectorLayer.addFeatures(feature); map.addLayer(vectorLayer); </script> </body></html>
view directly
Home
Blog
About
Maps
Other
Contact