ThinkGeo.com    |     Documentation    |     Premium Support

Utilizing a Map that auto sizes in Beta 2

Up until today I have been using Beta 1. It seems that I downloaded the beta the day before the new release came out.


Either way, I am creating a site that utilizes a resizing map. the javascript used to resize it is called  as well as on resize of course. With Beta 1 everything has worked as expected.


With the newly installed Beta 2, If my map control exceeds a certain height, all of a sudden my zoom level becomes changed... I know, this sounds very strange.


After some tearing apart of my code, I realized it is the RestrictedExtent that seems to be causing my problem:



Dim rectFullExtents As New RectangleShape(240142, 918093, 247535, 910527)
GeoMap.CurrentExtent = rectFullExtents
GeoMap.RestrictedExtent = rectFullExtents


 


When doing this if the height of my control exceeds 528px, I am seemingly brought down a zoom level. When this occurs, I can not use my Full Extent button to push out. This leaves me to beleive that something is up with the way the RestrictedExtent of the map object is being affected by the javascript to resize my object...


Here is the Javascript:



        function pageY(elem) {

            return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;

        }

        function pageX(elem) {

            return elem.offsetParent ? (elem.offsetLeft + pageX(elem.offsetParent)) : elem.offsetLeft;

        }

        var buffer = 25;

        //scroll bar buffer

        function resizeSidebarMap() {

            //var toolbar_height = document.getElementById('Panel1').style.height;

            var headertoolbar_height = 103;
            var sidebar_width = 300;

            var height = document.documentElement.clientHeight;
            var width = document.documentElement.clientWidth;

            height -= pageY(document.getElementById('panelMapUpdateContainer')) + buffer;
            width -= pageX(document.getElementById('panelMapUpdateContainer')) + 3;
            //height -= headertoolbar_height;

            height = (height < 0) ? 0 : height;
            width = (width < 0) ? 0 : width;

            document.getElementById('panelHeader').style.width = sidebar_width + width + 2 + 'px';
            document.getElementById('panelToolbar').style.width = sidebar_width + width + 2 + 'px';
            document.getElementById('panelSidebar').style.height = height + 'px';
            document.getElementById('panelMapUpdateContainer').style.height = height + 'px';
            document.getElementById('panelMapUpdateContainer').style.width = width + 'px';
            document.getElementById('panelFooter').style.width = sidebar_width + width + 2 + 'px';

            //resizeDebug();

        }


Nelson,


We couldn't recreate this problem. Here is our test demo and it works fine. Can you have a look at that to see if I misunderstand you in some point?


Ben.



199-Post4998.zip (4.17 KB)

Thank you once again. I am able to recreate the error. The issue is seems specifically related to onresize. So, using your example, add onresize="resizeSidebarMap();" to your body element. I meant to put that in my original post but I think I placed it as HTML and so it was discarded in the posting; apologies. 



The idea is to dynamically reside the map based on the resize event. 



These are the steps I take to reproduce the error after the above edit: 



1. Zoom out as far as possible, or full extent. Ensure the map height is short, maybe 200 px to be safe?. 

2. Pan the map south and to either left or right corner so as not to make the map appear to be exibiting my descirbed erroneous behavior. 

3. Concentrate on the current zoom level on the zoom bar. 

4. Drag the window so as to expand the height of the control. I think it will still be 528px where the zoom level is changd and it is apparent on the map and zoom bar. 

5. Try to zoom out; you no longer can. 

6. Shrink the height back down to less than the culprit height and try to zoom out; You now can! 



If you can not recreate this then maybe I have done something wrong when upgrading from Beta 1 to Beta 2. I hope not! 



Edit: With your example, the zoom level is affected multiple times. Please start off by shrinking th window height as little as possible and then stretching it out height-wise. You will see multiple zoom changes and the restriction to zoom out as the window expands. 



Also, it is possible I am not understanding the purpose of the restricted extent. I wanted to acheive the inability to pan outside of the full extents of my map regardless of its size. I think this is how I would employ that but am not 100% sure. 



Thanks again!



Nelson, 



It’s a bug that when working with RestrictedExtent, scale is snapped to match the nearest Zoomlevel while it should not. We will fix this in the next version and thanks for point it out. 



For now to work around, please try the following javascript to keep the current scale. 




var openLayersMap = Map1.GetOpenLayersMap();
//get the current scale
var zoom = openLayersMap.getZoom();

// ……
// have your logic here
//……

// retrieve the scale
openLayersMap.zoomTo(zoom);




Ben



I couldn't quite get it to work but it's not breaking my app or anything. For now I'll just leave the RestrictedExtent commented out and work around it in the mean time. Thanks again.



That’s good. Let me know for more queries.