Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenLayers - relocate the Zoom and Pan controls

I'm trying to reposition the PanPanel and ZoomPanel controls on my map to the bottom left corner rather than the top left. I see that I can add options, but as much as I've tried, I can't find a way to tell it to stay to the bottom left, even when the window is resized.

I am also not sure how I will tell them to stack like they do normally when I tell them to reposition relative to the bottom left.

I changed the images that make up both panels, so now there's a bit more room between pan and zoom panels than I want, so I'm also trying to get them to come closer to each other.

On top of looking into using options on the controls, I also tried creating a style for the id of the div that surrounds both panels, but the value of the id in the div is "OpenLayers.Map_2_OpenLayers_Container", which contains a '.'. Far as I know, that's not a legal id for styling. Anyway, it didn't work. On top of which I don't think I can trust the name to always be the same, with continued work on this page causing a lot of additions over time.

Any ideas?

like image 534
bmahf Avatar asked Nov 26 '25 07:11

bmahf


2 Answers

Try:

new OpenLayers.Control.YourControlXXXX({
    moveTo: function (px) {
        if ((px != null) && (this.div != null)) {
            this.div.style.left = yourLeft + "px";
            this.div.style.bottom = (yourBottom+controlHeigth) + "px";
        }
    },
    ... other options
})

ummm! I see that these controls are more modern than I thought, are positioned by CSS so try:

.olControlPanPanel {
    bottom: 55px; /* not 0px */
    top: auto;
}

NOTE: try as: div.olControlPanPanel {... to force the priority of CSS if you are not sure where position are loaded de css of OL.

like image 163
xamamano -jorix- Avatar answered Nov 27 '25 20:11

xamamano -jorix-


So I found the problem. First I wasn't setting top to auto. Since it was set in the style.css file to 10px, and when I changed it in the style.css file it to auto the bottom worked. But then my css file wasn't working. I found an OpenLayers example for Pan and Zoom, and eventually found that the difference between what I was doing and what they were doing was that I hadn't loaded the style.css file explicitly at the beginning of the page. So it seems that the OpenLayers Map, when it is created, causes the style.css file to be read late, after my css was read, and so it overrode my override. When I did an early load (beginning of the page) it worked perfectly.

Seems that the attribution control, created when I create a map Layer, must read the current CSS, since the map hasn't yet been created on the page, and so it never needed for me to do the early load. If I remove the early load, it still takes the changes made from my css file. But removing the early load causes the Pan and Zoom controls to no longer respond to my changes, so I assume this means that the Map object is reading the styling after the late load of the style.css file, which at that point has already overridden my css.

Go figure...

like image 22
bmahf Avatar answered Nov 27 '25 21:11

bmahf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!