/// <summary> /// Function to get BitmapImage from RuntimeImage /// </summary> /// <param name="rtImage">Runtime Image</param> /// <returns>Bitmap Image</returns> private async Task <BitmapImage> GetImageAsync(RuntimeImage rtImage) { if (rtImage != null) { try { if (rtImage.LoadStatus != Esri.ArcGISRuntime.LoadStatus.Loaded) { await rtImage.LoadAsync(); } var stream = await rtImage.GetEncodedBufferAsync(); var image = new BitmapImage(); image.BeginInit(); stream.Seek(0, SeekOrigin.Begin); image.StreamSource = stream; image.CacheOption = BitmapCacheOption.OnLoad; image.EndInit(); return(image); } catch { return(null); } } return(null); }
/// <summary> /// Create map pin based on platform /// </summary> private async Task <PictureMarkerSymbol> CreateMapPin(string imageName) { try { Assembly assembly = typeof(StartPage).GetTypeInfo().Assembly; string imagePath = null; switch (Device.RuntimePlatform) { case Device.iOS: imagePath = "Esri.ArcGISRuntime.OpenSourceApps.MapsApp.iOS.Images." + imageName; break; case Device.Android: imagePath = "Esri.ArcGISRuntime.OpenSourceApps.MapsApp.Android.Images." + imageName; break; case Device.UWP: imagePath = "Esri.ArcGISRuntime.OpenSourceApps.MapsApp.UWP.Images." + imageName; break; } using (Stream stream = assembly.GetManifestResourceStream(imagePath)) { long length = stream.Length; var imageData = new byte[length]; stream.Read(imageData, 0, (int)length); if (imageData != null) { var rtImage = new RuntimeImage(imageData); // Image must be loaded to ensure dimensions will be available await rtImage.LoadAsync(); // OffsetY adjustment is specific to the pin marker symbol, to make sure it is anchored at the pin point, rather than center return(new PictureMarkerSymbol(rtImage) { OffsetY = rtImage.Height * PinImageScaleFactor / 2, Height = rtImage.Height * PinImageScaleFactor, Width = rtImage.Width * PinImageScaleFactor }); } return(null); } } catch (Exception ex) { // Display error message await DisplayAlert("Error", ex.ToString(), "OK"); return(null); } }
/// <summary> /// Loads the symbol images and creates symbols, applying scale factor and offsets /// </summary> private async Task ConfigureImages() { var originImage = new RuntimeImage(new Uri("pack://application:,,,/MapsApp;component/Images/Depart.png")); var destinationImage = new RuntimeImage(new Uri("pack://application:,,,/MapsApp;component/Images/Stop.png")); // Images must be loaded to ensure dimensions will be available await Task.WhenAll(originImage.LoadAsync(), destinationImage.LoadAsync()); // OffsetY adjustment is specific to the pin marker symbol, to make sure it is anchored at the pin point, rather than center. _originPinSymbol = new PictureMarkerSymbol(originImage) { OffsetY = originImage.Height * PinScaleFactor / 2, Height = originImage.Height * PinScaleFactor, Width = originImage.Width * PinScaleFactor }; _mapPinSymbol = new PictureMarkerSymbol(originImage) { OffsetY = originImage.Height * PinScaleFactor / 2, Height = originImage.Height * PinScaleFactor, Width = originImage.Width * PinScaleFactor }; _destinationPinSymbol = new PictureMarkerSymbol(destinationImage) { OffsetY = destinationImage.Height * PinScaleFactor / 2, Height = destinationImage.Height * PinScaleFactor, Width = destinationImage.Width * PinScaleFactor }; }