Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style Point vector as Marker in Openlayers?

It seems like getting onDrag for Markers on OpenLayers isn't possible (this and this, as examples)

So I would like to use a vector layer, and then add points to it instead of markers.

My problem is that the vector points doesn't look like the markers.

Can I assign an icon to a point feature?

I want the functionality of a vector point, with the look of a marker. comparation

like image 737
jperelli Avatar asked Apr 14 '12 22:04

jperelli


People also ask

How do you remove layers from OpenLayers?

forEach(layer => map. removeLayer(layer)); Alternatively, you can also use the layer collection's internal forEach() method for similar results.


1 Answers

Add style object with externalGraphic property to your vector layer config:

var layer= new OpenLayers.Layer.Vector("example", {
    maxExtent: new OpenLayers.Bounds(-200,-200,200,200),
    style: {
        externalGraphic: 'http://www.openlayers.org/dev/img/marker.png', 
        graphicWidth: 21, 
        graphicHeight: 25,
        graphicYOffset: -24
    }
});

The graphicYOffset shifts the marker appropriately so that the perceived tip of it corresponds to the location on the map.

like image 135
drnextgis Avatar answered Oct 06 '22 00:10

drnextgis