ThinkGeo.com    |     Documentation    |     Premium Support

How to disable MVC Edition ZoomLevelSnapping

Hi.


Desktop edition allows to set  ZoomLevelSnapping to None.


How I can set Mvc edition zoom level snapping to None?


Any workaround?


When user zooms the area of interest on the map, that area can not zoom to the selection specified, next zoom level will display


that area too close.


 Before selection:



Selecting area of interest:



Area of interest after selection does not zoom to the selection:



Area of interest at next zoom level, zooms in too far:




Hi Sergei, 
  
 Sorry but I need to say that MVC Edition doesn’t provide any API to do the ZoomLevelSnapping. I guess  you can try using custom zoom levelSet for the map to make sure it can zoom to the proper scale. 
  
 Thanks, 
 Johnny

Johnny,


thank you for reply.


I  increased number of zoom levels to 120 and still can not achieve zooming to the selected area.


Navigate to Australia and below it you will see that iceland.


What is missing in my code?


I used code from the sample "Zoom In To a Feature Clicked"



@Imports ThinkGeo.MapSuite.Core
@Imports ThinkGeo.MapSuite.MvcEdition
<script language="javascript" type="text/javascript">
    function zoomToFeature(e) {
        var param = { x: e.worldXY.lon, y: e.worldXY.lat };

        Map1.ajaxCallAction('@ViewContext.RouteData.Values("Controller").ToString()', 'ZoomToShape', param, callback);
    }

    function callback(result) {
        var parameters = result.get_responseData().split("|");
        var extent = parameters[0].split(",");
        var bbox = new OpenLayers.Bounds(extent[0], extent[1], extent[2], extent[3]);
        Map1.zoomToExtent(bbox);
        document.getElementById("dataInfoDiv").innerHTML = parameters[1];
    }
</script>

    @Code Html.RenderPartial("SourceCode") End CODE
    
        
            Click on a country to zoom to it.
            
        
    


    @Code
      With Html.ThinkGeo().Map("Map1", New System.Web.UI.WebControls.Unit("100%"), 510)
        .MapBackground(New BackgroundLayer(New GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"))))
        .CurrentExtent(-125, 72, 50, -46)
        .MapUnit(GeographyUnit.DecimalDegree)
        .CustomOverlays(Sub(overlays)
                                                                                   
                            Dim worldLayer As New ShapeFileFeatureLayer(Server.MapPath("~/App_Data/cntry02.shp"))
                            Dim highlightLayer As New InMemoryFeatureLayer()
                            
                            Dim levels As Integer = 120
                            Dim initialScale As Double = worldLayer.ZoomLevelSet.ZoomLevel01.Scale
                              
                            Dim colors As System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.GeoColor) = GeoColor.GetColorsInQualityFamily(GeoColor.StandardColors.Red, GeoColor.StandardColors.Blue, levels, ColorWheelDirection.Clockwise)
                            Dim zls As New ZoomLevelSet
                            Dim divider As Double = 1

                            For level = 1 To levels
                              zls.CustomZoomLevels.Add(New ZoomLevel(initialScale / (divider)))
                              divider = divider * 2
                            Next
                              
                            worldLayer.ZoomLevelSet = zls
                            For idx As Integer = 0 To levels - 1
                              worldLayer.ZoomLevelSet.CustomZoomLevels(idx).DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, colors(idx)), colors(idx))
                            Next
                            
                            zls = New ZoomLevelSet
                            divider = 1
                            For level = 1 To levels
                              zls.CustomZoomLevels.Add(New ZoomLevel(initialScale / (divider)))
                              divider = divider * 2
                            Next
                              
                            highlightLayer.ZoomLevelSet = zls
                            
                            For idx As Integer = 0 To levels - 1
                              highlightLayer.ZoomLevelSet.CustomZoomLevels(idx).DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, colors(idx)), GeoColor.GeographicColors.DeepOcean) 
                              highlightLayer.ZoomLevelSet.CustomZoomLevels(idx).DefaultTextStyle = TextStyles.Country1("CNTRY_NAME")
                            Next
                               
                            zls = New ZoomLevelSet
                            divider = 1
                            For level = 1 To levels
                              zls.CustomZoomLevels.Add(New ZoomLevel(initialScale / (divider)))
                              divider = divider * 2
                            Next
                              
                            .ZoomLevelSet(zls)
                            
                            overlays.LayerOverlay("CountryOverlay").IsBaseOverlay(False).Layer("WorldLayer", worldLayer)
                            overlays.LayerOverlay("HighlightOverlay").IsBaseOverlay(False).TileType(TileType.SingleTile).Layer("HighlighLayer", highlightLayer)
                        End Sub)
        .OnClientClick("zoomToFeature")
        .Render()
      End With
    End Code



Hi Sergei,


 


Thanks for your code snippet, it seems you only set the ZoomLevelSet of WorldLayer and higlightLayer but Map, you should make sure the zoomLevelSet of Map is same as its layers, see code below,



@Code
        Dim levels As Integer = 40
        Dim initialScale As Double = 590591790
                              
        Dim colors As System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.GeoColor) = GeoColor.GetColorsInQualityFamily(GeoColor.StandardColors.Red, GeoColor.StandardColors.Blue, levels, ColorWheelDirection.Clockwise)
        Dim zls As New ZoomLevelSet
        Dim divider As Double = 1

        For level = 1 To levels
            Dim zoomLevel = New ZoomLevel(initialScale / (divider))
            zoomLevel.IsActive = True
            zoomLevel.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
            zoomLevel.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, colors(level - 1)), colors(level - 1))
            zls.CustomZoomLevels.Add(zoomLevel)
            divider = divider * 1.5
        Next
        
        
        With Html.ThinkGeo().Map("Map1", New System.Web.UI.WebControls.Unit("100%"), 510)
            .MapBackground(New BackgroundLayer(New GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"))))
            .CurrentExtent(-125, 72, 50, -46)
            .MapUnit(GeographyUnit.DecimalDegree)
            .CustomOverlays(Sub(overlays)

                                    Dim worldLayer As New ShapeFileFeatureLayer(Server.MapPath("~/App_Data/cntry02.shp"))
                                    worldLayer.ZoomLevelSet = zls
                                    
                                    overlays.LayerOverlay("CountryOverlay").IsBaseOverlay(False).Layer("WorldLayer", worldLayer)
                            End Sub)
            .OnClientClick("zoomToFeature")

            //notice this one
            .ZoomLevelSet(zls)

            .Render()
            End With
End Code


Regards,


Edgar



 



Edgar,


thank you for reply.


In my code I assigned zoom level set within .CustomOverlays(Sub(overlays)




                            .ZoomLevelSet(zls)
                            
                            overlays.LayerOverlay("CountryOverlay").IsBaseOverlay(False).Layer("WorldLayer", worldLayer)
                            overlays.LayerOverlay("HighlightOverlay").IsBaseOverlay(False).TileType(TileType.SingleTile).Layer("HighlighLayer", highlightLayer)
                        End Sub)
        .OnClientClick("zoomToFeature")
        .Render()
      End With
    End Code


I moved .ZoomLevelSet(zls) call per your change, changing multiplication factor also affects zoom level set calculation.
I found out that map requires the same zoom level set when I started to use navigation bar.       


Looks like fine tuning is required for zoom level snapping... 



Your help is appreciated. Thanks again.




Sergei, 
  
 You’re welcome, if you have any questions please let us know. 
  
 Regards, 
 Edgar