Creating a pushpin on Surface without the "button" background and pointer?

Jul 9, 2010 at 1:20 PM
Hi guys! Is there a way to create a pushpin on Surface without the "button" background? We want to place vehicles on the map, transformed with a rotation reflecting their heading, but having the button background around the icon for the vehicle would definitely clutter the map too much. Is there an easy way to have a pushpin on the map that does not have the surrounding Surface button and tooltip pointer? This is on for a Microsoft Surface SP1...
Coordinator
Jul 9, 2010 at 3:20 PM
Hi Acme, What you'll want to do is create your own custom PushPin that derives from VEPushPin. Create a custom control but replace CarPushPin : Control with CarPushPin : VEPushPin. Then customize the XAML (in Themes/Generic.xaml initially) to display your car and orient it and whatever else you need. You can make it look however you want and add custom properties (for the car image and orientation) and it will still get placed on the map as long as you set the latitude and longitude. Take a look at how SurfaceVEPushPin and the CustomPushPin in the DataBindingSample application are implemented. You'll probably want to override GetAnchorOffset (similar to in CustomPushPin.cs) and specify the anchor as the center point: protected override Point GetAnchorOffset() { return new Point(this.ActualWidth / 2, this.ActualHeight / 2); } Josh
Jul 9, 2010 at 7:07 PM
joshb wrote:
Hi Acme, Take a look at how SurfaceVEPushPin and the CustomPushPin in the DataBindingSample application are implemented. You'll probably want to override GetAnchorOffset (similar to in CustomPushPin.cs) and specify the anchor as the center point:

Hmmm... where's the DataBindingSample application? I didn't see it in the .zip file download (I got the source projects). Also, it doesn't appear that GetAnchorOffset is a method of VEPushPin?
Jul 9, 2010 at 7:37 PM
I seem to be having troubles adding a pushpin programatically, too... it works when I include it in XAML, but using this code, it doesn't seem to do anything (the pushpin does not appear on the map): Dim p As New AC p.Latitude = 28.5333333333333 p.Longitude = -81.35 p.Altitude = 5000 map.AddLayer("maplayer") map.AddShape(p, "maplayer") The AC class is the custom VEPushPin class I made. Again, I can add that same shape via XAML, but adding it programatically with the above code yields no results... Thanks for your help on this, by the way... great work :)
Coordinator
Jul 9, 2010 at 8:03 PM
First, get the latest source code from the source code tab. It has the DataBindingSample and other enhancements. Second, don't use the AddLayer or AddShape methods. Just add your pushpin to map.Items, or if you are using data binding, add it to the collection that maps.ItemsSource points to.
Jul 14, 2010 at 11:10 AM
Hey Josh! Thanks a ton, that was enough to get me going! Do you know if there's any additional documentation anywhere on the GetAnchorOffset specifics? The reason I ask is that I have a custom pushpin I've made that is an aircraft icon with a label at the bottom, but I'd like to make sure I take the best route to calculate the anchor offset as the center of the aircraft icon and not as the center of the whole control (aircraft and label). I also really need to customize it so that I can tap the icon and have it slide out an "info box" to the right of the aircraft icon, but still keep the center of the aircraft as the anchor. FYI, I'm putting together a flight tracker for Surface that I intend to release into the public once it's finished, so I really appreciate any help you can offer! :)
Coordinator
Jul 19, 2010 at 9:53 PM

GetAnchorOffset() is called when the pushpin logic wants to figure out what point relative to the top left of the pushpin the latitude/longitude should be located. The default implementation returns ActualWidth/2 and ActualHeight. This makes the lat/long be centered over the bottom center of the control. If you want it to be centered over the center of the control, in your derived pushpin just override this method and return new Point(ActualWidth/2, ActualHeight/2), or whatever other point you want. If you have an infobox that slides out you'll need to account for that.