Bing Maps for Windows UWP apps
Dashed line for polygons
Hi! I'm developing an application with bing maps where i'm drawing polygons on the map. Im using the class 'MapPolyline' for drawing lines between coordinates, and I can't seem to find anyway to make them dashed with the .NET library for metro apps. Can anyone help me with this?
There is unfortunately no way to have dashed lines with the built-in class. You may be able to put one together manually using the built-in line and positioning it OnViewChange using TryLocationToPixel per point though performance will most likely take a hit.
I can't say if this will be supported in future versions of this control or not. There is a workaround but it's a decent amount of work. The work around consists of inserting a canvas into a MapLayer and then drawing standard Line class which supports brushes, not MapPolylines on the canvas. This requires using the ViewChange event on the map to update the position of the line on the canvas/map. To update the position simply take the latlong coordinates for the line and convert them to pixels using the Map's TryLocationsToPixels method. This will create a list of pixel coordinates which can be used to set the position of the line. I have a code sample online that does a lot of this, although positioning an image rather than a line. You can find the sample here: http://code.msdn.microsoft.com/Binding-and-Image-to-a-01a56e48/sourcecode?fileId=107334&pathId=1304247442 http://rbrundritt.wordpress.com
I've thrown together a code sample for creating custom MapPolyline's that support dashes and Brushes: http://code.msdn.microsoft.com/Custom-MapPolylines-in-860a65f3http://rbrundritt.wordpress.com
There is unfortunately no way to have dashed lines with the built-in class. You may be able to put one together manually using the built-in line and positioning it OnViewChange using TryLocationToPixel per point though performance will most likely take a hit.
Hmm Ok.. Is it possible to reference some library that will make them dashed? I know that PresentationFramework.dll in .NET 4.5 includes some functions for this. But its not possible to import, right?
In Ricky's response he states: "There is unfortunately no way to have dashed lines with the built-in class." Will this always be the case? Given that the Bing Maps AJAX, WPF, Silver light and Phone API's can have dashed lines on poly-lines, is this something that will be addressed in a future update to the API, or is there some inherent reason why this will never be possible?
I can't say if this will be supported in future versions of this control or not. There is a workaround but it's a decent amount of work. The work around consists of inserting a canvas into a MapLayer and then drawing standard Line class which supports brushes, not MapPolylines on the canvas. This requires using the ViewChange event on the map to update the position of the line on the canvas/map. To update the position simply take the latlong coordinates for the line and convert them to pixels using the Map's TryLocationsToPixels method. This will create a list of pixel coordinates which can be used to set the position of the line. I have a code sample online that does a lot of this, although positioning an image rather than a line. You can find the sample here: http://code.msdn.microsoft.com/Binding-and-Image-to-a-01a56e48/sourcecode?fileId=107334&pathId=1304247442 http://rbrundritt.wordpress.com
I've thrown together a code sample for creating custom MapPolyline's that support dashes and Brushes: http://code.msdn.microsoft.com/Custom-MapPolylines-in-860a65f3http://rbrundritt.wordpress.com
Related Links
How to check Permission for Location Tracking?
MapManager - extends Bing Maps for Metro with tappable annotations (pushpins) and callouts
Is it possible to remove copyright names at bottom of map?
How to use the responsed xml information into my app?
Resetting or Removing some or all MapUIElementCollection elements from Map.
How to lock navigation on Bing Maps Metro Style?
Tile X,Y position vs quadkey
Calulate Distances with Bing ???
Set transparence for a polygon?
Best way to scroll the map by a given amount
Draw image on map?
Any examples of using Bing REST services in a C# Metro App?
[Bingmaps] [Javascript\HTML] How to disable infinite horizontal scrolling?
How to overlay a polygon on Bing basemap ?
Map Children Image size very large?
SetPositionRectangle On Metro Bing Control