12

I'm thinking about making a simple map control in WPF, and am thinking about the design of the basic map interface and am wondering if anyone has some good advice for this.

What I'm thinking of is using a ScrollViewer (sans scroll bars) as my "view port" and then stacking everything up on top of a canvas. From Z-Index=0 up, I'm thinking:

  1. Base canvas for lat/long calculations, control positioning, Z-Index stacking.
  2. Multiple Grid elements to represent the maps at different zoom levels. Using a grid to make tiling easier.
  3. Map objects with positional data.
  4. Map controls (zoom slider, overview, etc).
  5. Scroll viewer with mouse move events for panning and zooming.

Any comments suggestions on how I should be building this?

Dylan
  • 2,392
  • 6
  • 26
  • 34

10 Answers10

9

If you're looking for a good start, you can use the foundation of code supplied by the SharpMap project and build out from there. If I recall there were a few people already working on a WPF renderer for SharpMap, so you may also have some code to begin with.

I've personally used SharpMap in a C# 2.0 application that combined GIS data with real time GPS data, and it was very successful. SharpMap provided me the transformation suite to handle GIS data, along with the mathematical foundation to work with altering GIS information. It should be relatively straightforward to use the non-rendering code with a WPF frontend, as they already have presentation separated from the data.

(EDIT: added more details about how I used SharpMap)

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
user7116
  • 63,008
  • 17
  • 141
  • 172
  • 1
    I took a look at SharpMap, but unfortunately it's not ready for production yet for our deployment. It was unable to load some ESRI Shape files, which is something we use quite heavily. – Dylan Sep 30 '08 at 22:54
5

It is probably a roundabout way of going about it, but you might find some useful stuff in the javascript and XAML from SilverlightEarth.com which a Silverlight 1.0-based map-tile-client. It can load VE, Google, Yahoo (there is a DeepZoom version that can load OpenStreetMap, Moon and Mars too; but since it uses MSI it doesn't really help on the WPF 3/3.5 front).

Although the javascript is a little untidy, you can clearly see it is creating a Silverlight 1.0 Xaml (dynamically sized) Canvas, filling it with tiles (Image controls) and handling zoom in/out and pan requests. You would need to make sense of all the javascript and convert it to C# - the XAML should mostly come into WPF unaltered. I have tested this Silverlight 1.0 with a Deep Zoom tile pyramid (and here) so the concepts are applicable (ie. not just for maps).

I know this works because I have done it myself to build the map viewer in Geoquery2008.com (screenshot) which is WPF/c#. Unfortunately the Geoquery2008 assemblies are obfuscated, but you might still glean some ideas or useful code via DASM/Reflector. It is still a beta so I wouldn't claim it is 100% done. I hadn't really thought of factoring out the map code into a separate control but may I will look into that if another one doesn't appear...

Incidentally I also started off with the ScrollViewer, but am planning to ditch it and mimic the javascript more closely so it's easier to re-use Image objects when panning/zooming (by gaining more control over the process than ScrollViewer provides).

These MSDN pages on the Virtual Earth tile system and the Deep Zoom file format and related links is probably also a useful reference.

Finally - I guess you've seen since this post that DeepZoom/MultiScaleImage is likely to be in .NET 4.0/Studio 2010.

Conceptdev
  • 3,261
  • 1
  • 21
  • 23
1

It does not fall on my field of work at all, but you may have a look at MapWindow GIS, which has an Open Source ActiveX object that provides a lot of mapping and GIS features. Here is a post explaining how to embed it on WPF applications:

http://www.mapwindow.org/phorum/read.php?13,13484

amercader
  • 4,490
  • 2
  • 24
  • 26
1

Don't know if you use ESRI software, but I hear there developing a Silverlight API for there stack so you might want to hold off.

Donny V.
  • 22,248
  • 13
  • 65
  • 79
1

Download Bing Maps WPF Control sdk(Microsoft.Maps.MapControl.WPF.dll).Add as dll as referance,then change the XAML as below

**

<Window x:Class="WPFTestApplication.InsertPushpin"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
    Width="1024" Height="768">
    <Grid x:Name="LayoutRoot" Background="White">
        <m:Map CredentialsProvider="INSERT_YOUR_BING_MAPS_KEY" 
               Center="47.620574,-122.34942" ZoomLevel="12">
            <m:Pushpin Location="47.620574,-122.34942"/>
        </m:Map>
    </Grid>
</Window>

**

abhijithkp
  • 141
  • 1
  • 3
1

Your desire to create a WPF mapping tool is similar to mine, which lead me to ask this question about DeepZoom (aka MultiScaleImage) from Silverlight. I want a WPF version. The accepted answer provides a link to a very good starting point (similar to your described thought process).

Community
  • 1
  • 1
Ray Hayes
  • 14,896
  • 8
  • 53
  • 78
1

Virtual Earth has something favour to WPF

Jobi Joy
  • 49,102
  • 20
  • 108
  • 119
  • Unfortunately that won't work for me because it uses an embedded web host, and I need this to work in an XBAP in partial-trust. Which, unless I'm building it wrong, will not work. – Dylan Oct 06 '08 at 20:55
0

The main question is how you store and access the items you are going to put in the map (assuming this isn't just a picture display). Lookup scenegraph for some ideas.

Also if you want it to be more than a toy image viewer the lat long to XY scaling can get 'interesting'

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
0

Don't build it yourself - use the WPF Bing Maps Control http://www.bing.com/community/site_blogs/b/maps/archive/2012/01/12/announcing-the-bing-maps-windows-presentation-foundation-control-v1.aspx

Gary Barrett
  • 1,764
  • 5
  • 21
  • 33
0

the Bing Maps Windows Presentation Foundation Control v1 is best map control in WPF.

Support for tile layers – you can now overlay your own tile layers atop the map control.
Turning off the base tile layer – this is useful for when you don’t need/want to use our base map tiles and instead would prefer to use your own without overlaying them atop of ours.The control won’t request the tiles which reduces downloads and improves rendering performance.
SSL Support – since many of you are using the WPF control in secure applications, you can now make tile and service request over SSL without issue.
Hiding the scale bar – if you don’t want a scale bar (perhaps your map is small and the scale bar clutters the map) you can turn it off. In fact, the only elements you can’t turn off are the Bing logo and the copyrights.
New copyright service – provides accurate copyright for our data vendors. Additional inertia – inertia is now enabled for the mouse and is on by default for touch.
Miscellaneous bug fixes – thanks for the feedback on the MSDN Forums, the Bing Maps Blog, e-mail and Twitter. Good finds people.

Mehrdad
  • 405
  • 1
  • 6
  • 10