[OpenLayers-Users] OL Map setcenter problem with IE

Emmanuele Sordini emmanuele.sordini at gmail.com
Tue Mar 10 10:04:11 EDT 2009


On Fri, Mar 6, 2009 at 2:09 PM, Christopher Schmidt
<crschmidt at metacarta.com> wrote:
>
> Sounds like you may be initializing the map before IE has completely
> drawn the div, and Google therefore gets a size of 0 initialized at some
> point.

That was exactly my reasoning on the problem.

> At the end of your function, try a map.updateSize() to kick the
> map; it may help.

It did help, but putting it at the end of the init() function (i.e.
exactly where the setCenter() call I mentioned in my first post was
located) wasn't enough. Instead, using a 1-second delayed
timeout/callback with a map.updateSize() did the trick. Here's the
code snippet, just in case it may come in handy for someone else:

    var timeoutId = null;
[...]

    function redrawCallback() {    	
        if (map != null) {
        	map.updateSize();
        }

        if (timeoutId != null) {
            window.clearTimeout(timeoutId);
        }
    }
[...]

and at the end of the init() function:

timeoutId = window.setTimeout(redrawCallback, 1000);

The only drawback with this approach is that you see the map "flicker"
for a while. But it's the only way I found around the problem. I just
wonder why FF and IE are showing such a different behavior...

Thanks
Emmanuele



More information about the Users mailing list