ComponentOne Maps for WPF provides lot of features including smooth zooming, panning, and mapping between screen and geographical coordinates. In this blog article, I am providing small information to restrict users from Zooming beyond a specific value in the Map. By default, C1Map has zooming index of 21 and this blog will prevent zooming beyond zoom level of 10. Following code snippet implements the restriction.


Private Sub c1Maps_ZoomChanged(sender As Object, e As C1.WPF.PropertyChangedEventArgs(Of Double)) Handles c1Maps.ZoomChanged  
  If e.NewValue > 10 Then  
    c1Maps.Zoom = e.OldValue  
  End If  
End Sub  

Now this looks pretty easy. Isn't it. So where is the catch !!! After implementing this code, if you run the sample and zoom inside the Map through mouse double click or using mouse wheel, you still see everything working correctly and Map getting restricted to Zoom level of set value 10. However, if you use the vertical Zoom scrollbar and click on the thumb, you would notice the discrepancy. C1Map will allow the users to scroll beyond the value of 10. Even though this will not cause the Map to zoom in. However, UI interaction does not synchronize with the actual Zoom value. Next step is to synchronize the scrolling range of Zoom scrollbar with the C1Map Zoom index. This implementation requires modifying the existing template for C1Map. These are the two templates files available for C1Map.

  • Generic.xaml
  • ZoomScrollBar.xaml

The default template files are available with the installer and saved at the given location. C:\Program Files\ComponentOne\Studio for WPF\C1WPFMaps\XAML As the name suggests, ZoomScrollBar.xaml defines the various rendering styles to be applied on the Zoom Scrollbar. Whereas generic.xaml defines the style and templates for other Map Objects. Since we need to change only the scrollbar style, we need the content from 'ZoomScrollBar.xaml ' and part of the 'generic.xaml'. Zoom scrollbar is part of the C1MapToolsLayer object and we have to modify the template item for this. Template content for C1MapToolsLayer defines the scrollbar object. We have to only set the Maximum property to 10 for the scrollbar. Once you have the XAML snippet in place, and you run the sample; you will notice the change in the scrollbar marks. Zooming with the mouse and scrollbar would remain in synchronization with each other. MapZoom This brings to the end of the blog implementation. You can refer to the attached sample application for complete functionality. Download Sample