7

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

Community
  • 1
  • 1
jperelli
  • 6,988
  • 5
  • 50
  • 85

1 Answers1

10

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.

Andrew Mao
  • 35,740
  • 23
  • 143
  • 224
drnextgis
  • 2,194
  • 1
  • 25
  • 32
  • Two cavents: 1) If you attach that to the whole layer, how do you style individual points? 2) The tip of the point is not really aligned with the actual location, how do you shift it up properly? – Andrew Mao Jun 20 '13 at 18:19