How to create auto-scalling image lying on WP8 map

2019-05-26 10:18发布

问题:

I am trying to add multiple pushpins to the map, that disappear when you zoom out enough, to make the pushpins so little, that they are not rendered anymore.

I managed to achieve this effect with the following code:

MapPolygon shape = new MapPolygon();
GeoCoordinateCollection boundingLocations = CreateCircle(geoCoordinate, 0.1);
shape.Path = boundingLocations;
shape.FillColor = Color.FromArgb(0x55, 0xFF, 0xFF, 0x00);
shape.StrokeColor = Color.FromArgb(0xFF, 0xFF, 0x00, 0xFF);
shape.StrokeThickness = 4;
mapToDrawOn.MapElements.Add(shape);

But what I really want to do is fill the polygon with a custom image. The image has to be placed in the specific point of the map, and relate its size to the level of zoom. (just as in the above example) This is the code that I tried to use:

MapLayer layer = new MapLayer();
MapOverlay overlay = new MapOverlay();
Polygon polygon = new Polygon();
polygon.Points.Add(new Point(0, 0));
polygon.Points.Add(new Point(0, 75));
polygon.Points.Add(new Point(25, 0)); 
BitmapImage arrImg = 
    new BitmapImage(new Uri("/Images/arrow.png", UriKind.RelativeOrAbsolute));
ImageBrush imgBrush = new ImageBrush();
imgBrush.ImageSource = arrImg;
polygon.Fill = imgBrush;
overlay.Content = polygon;
//geoCoordinate is the argument of a method
overlay.GeoCoordinate = geoCoordinate;
layer.Add(overlay);
mapToDrawOn.Layers.Add(layer);

It doesn't work. The image appears in the specific point of the world, but when I zoom out, image keeps its size. I believe that the problem is caused by the lack of some Rectangle restricting the polygon, but I can't find anything to start with. Please help.

回答1:

That's not a supported feature of WP8 Maps. The idea is that once an item is added to Map.Layers it doesn't rescale with zoom in order to create a consistent look & feel. Some items do resize such as Map.MapElements Polylines and Landmarks, but those won't work for an Image.

If you want your items to scale you'll have to sign-up for Map.ZoomLevelChanged and change the scaling of your items programmatically.

If you're interested in seeing this in future releases please fill in a wpdev uservoice suggestion with your usecase and why you're interested in doing that.