Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating markers using this method :

var markers = new OpenLayers.Layer.Markers( "Markers" );
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('',size,offset);
`enter code here`markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon));

Now , I want to rotate the marker 90 degrees to the left (or right). How can I do it? I was able to find example to rotate a feature , but I'm not using a feature.. I'm using a marker.


share|improve this question
A comment to the code you have posted. According to the OpenLayers documentation, using a layer of the class OpenLayer.Layer.Vector instead of the class OpenLayer.Layer.Marker is preferable ( – dariapra Nov 12 '12 at 11:21
Thank you daria , will update code now. Will this enable me to rotate markers? – Alophind Nov 12 '12 at 11:29
Although I don't know the example you are talking about (I have been unable to find it), I guess that it should work. I think it because with new code the vector layer will be populated with features; with the current code you don't have - from a programming point of view - features. – dariapra Nov 12 '12 at 11:49
This is the example i was talking about – Alophind Nov 12 '12 at 13:08
up vote 1 down vote accepted

As @dariapra mentioned. Your better off using a vector feature so you can take advantage of the rotation property.

You will find no drawbacks from switching over. You will see that using the more flexible feature vector will be more convenient.

Use the externalGraphic style property to designate the marker image.

share|improve this answer

I think this boils down to how you can rotate the marker image using JavaScript as I don't think there's a way of using OpenLayers to do this.

There's a neat CSS3 way of rotating images here: And there's plenty of JavaScript libraries that will do this for might find you're using a library (e.g. JQuery) that has this capability for you already.

One last thing. Rotating images can sometimes look a bit messy when done on the fly so the other alternative is to display your features as a vector - though whether this works for you will depend what your icon looks like and whether you can get a decent vector representation of it.

Hope this helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.