Dynamic Map Width

I swear that I have seen the answer to this, however now that I am looking for it, I can not find it anyware.

I need to be able to use a width of 100% on my map. However, when I do, the map returns "upper left" and "bottom right" coordinates like it is only 100px wide. Does anyone know how to use a 100% width and get correct coordinates

Any help is greatly appreciated.

--Erick_the_Redd



Answer this question

Dynamic Map Width

  • vasudupe

    Yep i'm working in DotNetNuke so i know what your talking about.

    Haven't finished this part yet but you can work out the position of the map div on the page using this (IE only currently)

    function GetPos(obj)

    {

    var Pos = new Object();

    //todo: fix firefox hardcoded

    Pos.Left = 225;

    Pos.Top = 136;

    if (obj.offsetParent) {

    Pos.Left = obj.offsetLeft;

    Pos.Top = obj.offsetTop;

    while (obj = obj.offsetParent) {

    Pos.Left += obj.offsetLeft;

    Pos.Top += obj.offsetTop;

    }

    }

    return Pos;

    }

    John.



  • Saurabh Kulkarni

    Yeah unfortunatelly that method does not work for my case. The map is used with a templating system. So every site has some variation to its width. So to make it work I would need to deduct for stuff on the sides.

    I was just in hopes that there was a way to do it using a percent width, similair to how google does it.

    Yeah my clients may just have to suffer with one size for now.

    -- Erick_the_Redd


  • eldiener

    Hopefully soemone has a more elegant solution but i've been forced to manually detect browser resize and resize the map manually.

    Basically i have a general timer used for throttling (so i don't make millions of calls), i check if the browser dimension have changed. This gets the dims:

    GetBrowserDim: function()

    {

    var BrowserDim = new Object();

    if( typeof( window.innerWidth ) == 'number' )

    {

    //Non-IE

    BrowserDim.Width = window.innerWidth;

    BrowserDim.Height = window.innerHeight;

    }

    else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )

    {

    //IE 6+ in 'standards compliant mode'

    BrowserDim.Width = document.documentElement.clientWidth;

    BrowserDim.Height = document.documentElement.clientHeight;

    }

    else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )

    {

    //IE 4 compatible

    BrowserDim.Width = document.body.clientWidth;

    BrowserDim.Height = document.body.clientHeight;

    }

    return BrowserDim;

    }

    and then i resize the map using the following:

    var mydiv = document.getElementById(MapDiv);

    mydiv.style.width = mapwidth;

    mydiv.style.height = mapheight;

    map.Resize(mapwidth, mapheight);

    Hope it helps. If you find a better way please let me know.

    John.



  • jori0001

    To add to that the best method to trigger that you need to resize the map is to subscribe to the body onresize event. What i meant as a timer was that i also have a timer that means if a user plays with the size of there window the resize is only called every X sec rather then on every resize. But this is kind of advanced don't worry to much about it.

    John.



  • Dynamic Map Width