Guest User

Untitled

a guest
Oct 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. private ArcGISMapImageSublayer _fileGeodatabaseSublayer;
  2. private LocalServer _LocalServer;
  3.  
  4. public MainWindow()
  5. {
  6. InitializeComponent();
  7. Initialize();
  8. }
  9. private async void Initialize()
  10. {
  11. // Create a map and add it to the view
  12. MyMapView.Map = new Map(BasemapType.Topographic, 39.7294, -104.8319, 12);
  13.  
  14. try
  15. {
  16. // Start the local server instance
  17. await LocalServer.Instance.StartAsync();
  18. }
  19. catch (InvalidOperationException ex)
  20. {
  21. MessageBox.Show(String.Format("Please ensure that local server is installed prior to using the sample. See instructions in readme.md or metadata.json. Message: {0}", ex.Message), "Local Server failed to start");
  22. }
  23. }
  24. private void m_Button_Click(object sender, RoutedEventArgs e)
  25. {
  26. string filePath = "D:\test\test.gdb";
  27. string fileName = "featureclass1";
  28. StartLocalMapService(fileName, filePath);
  29. }
  30. private async void StartLocalMapService(string fileName, string filePath)
  31. {
  32. // any mpk file - don't know why
  33. string mapServiceUrl = System.IO.Path.GetDirectoryName(filePath) + "\mpk_blank.mpk";
  34.  
  35. // Create the local map service
  36. var localMapService = new LocalMapService(mapServiceUrl);
  37. FileGeodatabaseWorkspace ws = new FileGeodatabaseWorkspace("file_wkspc", filePath);
  38. TableSublayerSource source = new TableSublayerSource(ws.Id, fileName);
  39. _fileGeodatabaseSublayer = new ArcGISMapImageSublayer(0, source);
  40. localMapService.SetDynamicWorkspaces(new List<DynamicWorkspace>()
  41. {
  42. ws
  43. });
  44. localMapService.StatusChanged += localMapService_StatusChanged;
  45. await localMapService.StartAsync();
  46. }
  47. private async void localMapService_StatusChanged(object sender, StatusChangedEventArgs e)
  48. {
  49. if (e.Status == LocalServerStatus.Started)
  50. {
  51. if (!(sender is LocalMapService localService))
  52. {
  53. return;
  54. }
  55. ArcGISMapImageLayer imageryLayer = new ArcGISMapImageLayer(localService.Url);
  56. imageryLayer.LoadStatusChanged += (q, ex) =>
  57. {
  58. // Add the layer to the map once loaded
  59. if (ex.Status == Esri.ArcGISRuntime.LoadStatus.Loaded)
  60. {
  61. // Create a default symbol style
  62. SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 3);
  63. // Apply the symbol style with a renderer
  64. _fileGeodatabaseSublayer.Renderer = new SimpleRenderer(lineSymbol);
  65. imageryLayer.Sublayers.Add(_fileGeodatabaseSublayer);
  66. }
  67. };
  68. await imageryLayer.LoadAsync();
  69. MyMapView.Map.OperationalLayers.Clear();
  70. // Add the image layer to the map
  71. MyMapView.Map.OperationalLayers.Add(imageryLayer);
  72. }
  73. }
Add Comment
Please, Sign In to add comment