Using OpenLayers is it possible to draw a rectange that will always be on one portion of map without regards to zooming and panning of map?

  • You could use a div & position it using CSS. That might be the easiest option. – Devdatta Tengshe Sep 27 '12 at 7:28
  • @DevdattaTengshe I want it to be redrawn like any layer. – kinkajou Sep 27 '12 at 8:53
  • Why do you want it to redraw, if it is not going to change its position on the screen? and you can always toggle its visibility when the map pans or zooms to give a similar effect. – Devdatta Tengshe Sep 27 '12 at 9:05
  • @DevdattaTengshe IF it's layer itself then I will be able to print it and redraw it when it's value change using timer. – kinkajou Sep 27 '12 at 9:09

It is like the car window in a race game? Here a red box

 <div style="z-index:99999999; position:fixed; 
             top:300px; right:300px; width:80px; height:80px;
             border-color:red; border-style:solid; border-width:2px;

Change position to relative (a div into the map's div) if you need it scrolling with the page, p. ex.

 position:relative; z-index:99999999; top:30px; right:-40px; 

See also z-index at map layers, CSS positioning, and box model.

  • How can I make this div movable with mouse?? – kinkajou Sep 27 '12 at 10:51
  • It is "like a STATIONARY window" :-) Well, your question is about drawing a rectangle "that will always be on certain area", so it is stationary. For "animation" (you need to post a new question!) the div must have a ID and you can use jQuery to control it. PS: about playing this question-and-answer-game, my answer is acceptable? – Peter Krauss Sep 27 '12 at 12:18

One option is to use the Vector layer, and set its isFixed property to true. This way the vector layer will not move around when the map is dragged, but is printed and redrawn with the map.

  • I will try this .. it seems good – kinkajou Oct 9 '12 at 6:09
  • "Note that setting this to true will move the layer to the bottom of the layer stack" so if I have opaque layer on top then it will block eveything :(. I Need it on the top. – kinkajou Oct 9 '12 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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