ThinkGeo.com    |     Documentation    |     Premium Support

Default Zoom Level

Hello again,


I am having difficulty being able to specify the default zoom level for the map. I am able to specify the initial extents but my zoom level at initial extents should be at the largest zoom. I do also have a restricted extent currently set that is equal to the value I use for my full extents. I would like this to be ZoomLevel01 or ZoomLevel20, whichever refers to the least zoomed in scale.


I see there is a way to set the scale for each zoom level, but it must be done on a layer by layer basis which seems odd to me as I would think all layers should be at the same scale per zoom level. I did poke around in the API help but wasn't able to peice up a solution.


Thanks again.



Nelson, 


Now ZoomLevels can only be set for every layer separately. Each layer does share the same scale, but they can belong to different zoomLevel. Just like a map can include 2 layers which belong to different projections. This feature provides more flexibility for the users, but maybe a bit extra work for your case. We will see if we can make it easier for this scenario in the future releases.
 
Another thing want to make it clear is that there are 2 kinds of zoomlevels we need to set. One is the zoomLevel of every layer you mentioned which will determine how to apply styles. The other is the viewing zoomLevel which determines what the scale will be when you move to a certain scale on panZoomBar. The default layer zoomlevel and view Zoomlevel matches and if you want to create your own ZoomLevel system, you need to make them match yourself.
 
Here is a sample how to implement it. Please have a look and let us know for any queries. 
 


Ben

200-Post4997.zip (95.6 KB)

Thank you for the example. My only question with all of this is that I will be dynamically sizing my maps based on window size and so I am curious how I can obtain the CurrentExtent.width programmtically from within JS.  
  
 It seems without this javascrip code in place, none of the .net scale setting code seems to be affected.

Nelson, 
  
 Here is the javascript to get the CurrentExtent.Width. 
  
  
      <script type=“text/javascript”>
      var OnMapCreated = function(map) {
            map.events.register(‘resize’, map, function() {
                  alert(this.getExtent().getWidth());
            })
      }
      </script>
 
  
 The .net scale setting works. In the sample I uploaded in the previous message, the default extent is within zoomLevel04; while if you customize the ZoomLevel, the default extent is within ZoomLevel01. Set different styles for different ZoomLevels and you will see the affects.   
  
 Ben 


I see what you are saying as far as different styles on different zoom levels. Unfortunately it seems like setting a scale on a zoom level is having no affect for me. Also, I am having trouble implementing your javascript into my page as it seems I can only use getExtent().getWidth() within that block registering the resize event and I at least initially for the first script you supplied. I wanted to do something like:


 


        var OnMapCreating = function(map) {

            var map_extent_width = this.getExtent().getWidth()
            // 111.245178 is Map1.CurrentExtent.Width, 640 is the width of the map control. The result is decimalDegree/pixel
            var map_width = document.getElementById('panelMapUpdateContainer').style.width;
            var maxResolution = map_extent_width / map_width;
            //alert(map_extent_width);
            var minScale = OpenLayers.Util.getScaleFromResolution(maxResolution, 'dd'); // 'dd' means decimal degree
            map.setOptions({ 'minScale': minScale });

        }


I don't think that will work thought because the script needs to fire off during load but I can't get the extent width until the map is drawn...

It would just be extremely helpful if I could pick my base zoom level because at this point I am resting at Zoom Level 14 which isn't working out very well.



Nelson, 
  
 First, there is a small bug in your code,  
 
// The following line
var map_extent_width = this.getExtent().getWidth()
// should be like this:
var map_extent_width = map.getExtent().getWidth();
 
  
 I’m a bit confused about your requirement. Just wander you want to change the drawing ZoomLevel or Viewing ZoomLevel, or both? When resizing the map, the ZoomLevel is supposed to be changed or not?  Also, you want to change the scales on server or client side? It will be great if you can provide a demo about what you want that will help a lot.  
  
 Ben 


I apologize for not being clear. Ultimately, I would like ZoomLevel01 to be one level above my full extents defined as


Dim rectFullExtents As New RectangleShape(240142, 918093, 247535, 910527)


I suppose for simplicity sake, I just wanted to approach the topic as saying I would like ZoomLevel01 to the level of my full extents


Also, I had used map.getExtent() but this hadn't worked either.


It is hard to expose my site to the internet at the moment because our external ips are basically entirely preoccupied and port forwarding isn't allowing me to piggy back the site at the moment. Also, I could privately send you the project but I doubt it will help you too much as we are employing a MySQL back-end to storage our layer configs, etc. So you will be largely left without any connected data or for that matter a means to substitute it. I am tryig to set up a city web site and so the zoom level that is being used by default is simply already zoomed into level 14 which doesn't leave me much when it comes to zooming in. This means for layers I would like to toggle based on zoom level, I really only have 6 levels of flexibility and could really use the extra ones...


 


Edit: Here's an URL to the site I am trying to demo: maps.plotplans.com/


Sometimes I get an unspecified error when loading the page for the first time but there is not enough info to figure out why... likely it is unrelated to this thread topic, however.



Nelson,


Here is a new sample where we change the viewing ZoomLevel01 to the layer’s full extent. Sure you can set it to any RectangleShape if you want.
 
I didn’t change the drawing ZoomLevel in this sample, please reference the first sample if you want to implement that. I think now you can zoom in much more on your cities layer. Any queries please let us know. 
 
BTW: the link you provided cannot be opened, there is a “RunTime Error”.
 
Ben

213-Post4997.zip (97 KB)

In the future, will there be a more intuitive way of interfacing with the ZoomLevels? I think it should be easy to get all of the layers to display at the same scale and select my default zoom level with respect to the zoomlevel bar. Using the above two examples you have given me, I have been able to bring my zoom level bar to an acceptable level of zoom levels for my data but now my zoomlevel styles are now seemingly applied independantly of the zoom level I am actually at. So now I can not tell what is zoomlevel01 without experiementing. I feel as though ZoomLevel01 should always be ZoomLevel01 and 20 as 20. This seems like setting the zoom bar to my liking on a per site basis will require a lot of experimenting unneccesarily.

Nelson, 
  
 Currently, we don’t recommend users to change the default zoomlevel, for doing this, viewing scale and drawing scale should be synchronized with each other, which are a bit difficult, and easy to make mistake. Also, we don’t see a good way how to provide user the ability to do it, if we just provide one property to let the user change the whole zoomLevel system, it might be easy but less flexibility if users want to change every zoomLevel themselves.  
  
 We will work on this and try to create some good APIs for this case. Thanks for bringing it back to me; I think we will have a good way to handle this in the future. 
  
 Ben. 


I think the ability to specify what scale your zoomlevel draws at would be a good way to syncronize drawing scale and zoom scale. This is what I had thought the original intention was, in fact but changing scale for any zoomlevel seems to not really have any affect on my drawing scale or otherwise unless I am not looking for the right detail. The code provided to loop through the zoom levels and divide the given scale by 2 didn’t seem to really affect the zoom levels at all.  
  
 For fear of sounding ignorant also, it is also extremly hard for me to think of wanting to display two layers simulatenously at different scales so it seems if that is something desired it should be possible also, but it shouldn’t override the ability to to syncronize drawing zoomleve and scale zoomlevel which i think is a fundamental function of gis software…

Nelson,


I agree on your idea about making drawing zoomlevel and scale zoomlevel synchronized in an easier way. I think one prerequisite for that is to make sure every layer shares the same zoomlevel, otherwise zoombar has no idea which layer’s zoomlevel it will follow. We will figure out if we will remove the ability that every layer customs its zoomlevel and how we will do it.


Also here I want to explain more about the ZoomLevel. You know we have 20 default zoomLevels, each of them is a range but what we can set is only one scale, not an upperLimit and a LowerLimit. From that we can see ZoomLevel cannot work independently, it only works when it is within a ZoomLevelSet. 

Here is how we get the limits for a zoomLevel. For example, we have some codes like following.


zoomLevelSet.ZoomLevel03=80 

zoomLevelSet.ZoomLevel04=40 

zoomLevelSet.ZoomLevel05=20 

zoomLevelSet.ZoomLevel06=10


We can say from that the ZoomLevel04.UpperLimit = (80 + 40 ) / 2 = 60

ZoomLevel04.LowerLimit = (40 + 20) / 2 = 30


Similarly, ZoomLevel05.UpperLimit = 30 and ZoomLevel05.LowerLimit=15.

We cannot get the range of ZoomLevel03 and ZoomLevel06 just from the above code.


You mentioned changing the ZoomLevel scales didn’t seems to affect the ZoomLevels.  Here is a sample where you can find if you comment the code of Changing the ZoomLevelSet, result will be different. Just wonder if I misunderstand something about the “affect” you means, maybe you didn’t mean the appearance but something else?


Use the Default ZoomLevel


 


Change the Default ZoomLevel

 



 


Thanks,
 
Ben

239-Post4997_3.zip (93.9 KB)