I love maps and mapping applications. As I was digging into WPF, I became aware of the MapPoint Web Service SDK and thought it would be a nice idea to put them together. I started by having the MapPoint Render Service plot pushpins on a map and return the rendered result to my WPF app, but I quickly discovered that I was making lots of web service calls. It just wasn't practical to call out to the cloud every time I wanted to change the points on the map - there had to be a better way.
As I looked through the SDK samples, I found it. There's a sample with a sealed class called PointConversion. This class has a few static methods that handle the transformation to and from (x,y) pixel coordinates to (lat,long) pairs. If you've studied map projections, you understand that this is a non-trivial computation, but if you want your points to be plotted in the right place, you also understand that getting it right is essential. Using this technique, I could plot points in WPF that aligned with their geocoded (lat,long) values.
As you can see, my WPF application makes heavy use of client side conversion to plot point on the map without having to call out to the cloud. I thought this would be a good place to start with my porting exercise. So I picked up the class from my WPF app (which I renamed PointConverter) and dropped it on my Silverlight app. Therein, I discovered the first of the differences I had to cope with. It turns out that the MapPoint Web Service SDK Sample's class has a dependency on System.Drawing's Size class and MapPoint's PixelCoord and LatLong classes. When I went to add a reference to System.Drawing.dll, I was presented with the following:
Yep - System.Drawing is among the missing. Fortunately, Size is pretty simple, so I made one of my own and added it to the project. I also discovered that my web reference MapPoint didn't generate the PixelCoord and LatLong classes as I had expected, so I made my own there as well. Once I had that done, I was able to convert (x,y) pixel coordinates to (lat,long) pairs (and vice-versa) with vigor and alacrity. I've posted the Silverlight friendly PointConverter with the absolute minimal roll-your-own support structures bundled up into a single file here, but use at your own risk! This has been marginally tested - no warranties expressed or implied!
The interaction of Silverlight with web services promises to be the next interesting topic. As I went to debug the app, Orcas prompted me with the following:
I'll need to be making some web service calls to render maps and do other data related work - we'll see how that works out in my next posting.