WinRT Bing.Maps - how add a image with a lat/lon bounding box?

I am able to add an image to my map just fine via code.

However when I zoom in/out, the image stays the same. I would like it scale relative to the map.

In the WPF version of the Map, you could use an ImageBrush for a MapPolygon and it would be constrained to the bounding box.

I tried the solution from this SO question, but it seems to have no effect on the Image.

                imageLayer.Children.Clear();
                MapLayer.SetPosition(_vm.RadarImage, new Location(_vm.Overlay.LatN, _vm.Overlay.LonW));
                imageLayer.Children.Add(_vm.RadarImage);

                shapeLayer.Shapes.Clear();
                var rect = new MapPolygon();
                rect.Locations.Add(new Location(_vm.Overlay.LatN, _vm.Overlay.LonW));
                rect.Locations.Add(new Location(_vm.Overlay.LatS, _vm.Overlay.LonW));
                rect.Locations.Add(new Location(_vm.Overlay.LatS, _vm.Overlay.LonE));
                rect.Locations.Add(new Location(_vm.Overlay.LatN, _vm.Overlay.LonE));
                rect.FillColor = Colors.Green;

                shapeLayer.Shapes.Add(rect);

                mappy.SetView(new LocationRect(new Location(_vm.Overlay.LatN + 0.0001, _vm.Overlay.LonW + 0.0001), new Location(_vm.Overlay.LatS - 0.0001, _vm.Overlay.LonE - 0.0001)));

This is the correct scaling.

Correct iamge placement

When you zoom once via the Navigation, you can see the image is now larger than the Polygon

Zoomed once

Upvotes: 0

Views: 579

Answers (1)

rbrundritt
rbrundritt

Reputation: 18003

There isn't a simple solution for this. I have put together a sample app that shows one approach to do this. You can find it here: http://code.msdn.microsoft.com/Binding-and-Image-to-a-01a56e48 What I did was add a Canvas to the map, and then use the map to calculate the pixel coordinates of the bounding box for the image. I then used these pixel coordinates to scale and position the image on the canvas overtop the map. I've done something similar to create custom polygons that support image brushes in the past but haven't uploaded that code sample yet.

Upvotes: 1

Related Questions