コード例 #1
0
        // Download the tile cache
        private async void ExportTilesButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                panelUI.IsEnabled   = false;
                panelTOC.Visibility = Visibility.Collapsed;
                progress.Visibility = Visibility.Visible;

                string tilePath        = Path.Combine(Path.GetTempPath(), TILE_CACHE_FOLDER);
                var    downloadOptions = new DownloadTileCacheParameters(tilePath)
                {
                    OverwriteExistingFiles = true
                };

                var localTiledLayer = MyMapView.Map.Layers.FirstOrDefault(lyr => lyr.ID == LOCAL_LAYER_ID);
                if (localTiledLayer != null)
                {
                    MyMapView.Map.Layers.Remove(localTiledLayer);
                }


                var result = await _exportTilesTask.GenerateTileCacheAndDownloadAsync(
                    _genOptions, downloadOptions, TimeSpan.FromSeconds(5), CancellationToken.None,
                    new Progress <ExportTileCacheJob>((job) => // Callback for reporting status during tile cache generation
                {
                    Debug.WriteLine(getTileCacheGenerationStatusMessage(job));
                }),
                    new Progress <ExportTileCacheDownloadProgress>((downloadProgress) => // Callback for reporting status during tile cache download
                {
                    Debug.WriteLine(getDownloadStatusMessage(downloadProgress));
                }));


                localTiledLayer = new ArcGISLocalTiledLayer(result.OutputPath)
                {
                    ID = LOCAL_LAYER_ID
                };
                MyMapView.Map.Layers.Insert(1, localTiledLayer);

                _onlineTiledLayer.IsVisible = false;
                _aoiOverlay.IsVisible       = true;

                if (MyMapView.Scale < _genOptions.MinScale)
                {
                    await MyMapView.SetViewAsync(MyMapView.Extent.GetCenter(), _genOptions.MinScale);
                }

                panelTOC.Visibility    = Visibility.Visible;
                panelExport.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                panelUI.IsEnabled   = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"
                ConfigService config = new ConfigService();
                this.myModel = config.LoadJSON();

                Messenger.Default.Register <Esri.ArcGISRuntime.Controls.MapView>(this, (mapView) =>
                {
                    this.mapView          = mapView;
                    this.mapView.MaxScale = 500;

                    ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(this.TilePackage);
                    localTiledLayer.ID = "SF Basemap";
                    localTiledLayer.InitializeAsync();

                    this.mapView.Map.Layers.Add(localTiledLayer);

                    this.CreateLocalServiceAndDynamicLayer();
                    this.CreateFeatureLayers();
                });
            }
        }
コード例 #3
0
            /// <summary>
            /// Initializes a new instance of the MainViewModel class.
            /// </summary>
            public MainViewModel()
            {
                if (IsInDesignMode)
                {
                    // Code runs in Blend --> create design time data.
                }
                else
                {
                    // Code runs "for real"
                    ConfigService config = new ConfigService();
                    this.myModel = config.LoadJSON();

                    Messenger.Default.Register<Esri.ArcGISRuntime.Controls.MapView>(this, (mapView) =>
                    {
                        this.mapView = mapView;
                        this.mapView.MaxScale = 500;

                        ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(this.TilePackage);
                        localTiledLayer.ID = "SF Basemap";
                        localTiledLayer.InitializeAsync();

                        this.mapView.Map.Layers.Add(localTiledLayer);

                        this.CreateLocalServiceAndDynamicLayer();
                        this.CreateFeatureLayers();                      

                    });
                }
            }
        // Download the tile cache
        private async void ExportTilesButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                panelTOC.Visibility = Visibility.Collapsed;
                progress.Visibility = Visibility.Visible;

                var downloadOptions = new DownloadTileCacheParameters(ApplicationData.Current.TemporaryFolder)
                {
                    OverwriteExistingFiles = true
                };

                var localTiledLayer = MyMapView.Map.Layers.FirstOrDefault(lyr => lyr.ID == LOCAL_LAYER_ID);
                if (localTiledLayer != null)
                {
                    MyMapView.Map.Layers.Remove(localTiledLayer);
                }

                var result = await _exportTilesTask.GenerateTileCacheAndDownloadAsync(
                    _genOptions, downloadOptions, TimeSpan.FromSeconds(5), CancellationToken.None,
                    new Progress <ExportTileCacheJob>((job) =>                    // Callback for reporting status during tile cache generation
                {
                    Debug.WriteLine(getTileCacheGenerationStatusMessage(job));
                }),
                    new Progress <ExportTileCacheDownloadProgress>((downloadProgress) =>                    // Callback for reporting status during tile cache download
                {
                    Debug.WriteLine(getDownloadStatusMessage(downloadProgress));
                }));

                localTiledLayer = new ArcGISLocalTiledLayer(result.OutputPath)
                {
                    ID = LOCAL_LAYER_ID
                };
                MyMapView.Map.Layers.Insert(1, localTiledLayer);

                _onlineTiledLayer.IsVisible = false;

                if (MyMapView.Scale < _genOptions.MinScale)
                {
                    // Get current viewpoints extent from the MapView
                    var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
                    var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;
                    await MyMapView.SetViewAsync(viewpointExtent.GetCenter(), _genOptions.MinScale);
                }


                panelTOC.Visibility    = Visibility.Visible;
                panelExport.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
コード例 #5
0
        private async void MapsCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            EngineeringMap emap = MapsCB.SelectedItem as EngineeringMap;

            if (emap == null)
            {
                return;
            }

            List <LayerDef> lyrsDef = emap.LocalGdbLayersDef;
            LayerDef        lyrDef  = lyrsDef.Find(x => x.Name == _lyrName);

            if (lyrDef == null)
            {
                return;
            }

            // load tiled layer
            //
            string file = _prjDef.LocalTilePath + "\\" + emap.LocalTileFileName1;

            if (File.Exists(file))
            {
                ArcGISLocalTiledLayer newLayr = new ArcGISLocalTiledLayer(file);
                newLayr.ID          = "TiledLayer1";
                newLayr.DisplayName = "TileLayer1";
                Map.Layers.Add(newLayr);
                //if (newLayr.FullExtent != null)
                //{
                //    MyMapView.SetView(newLayr.FullExtent);
                //}
            }

            // load the specified layer
            //
            file = _prjDef.LocalFilePath + "\\" + emap.LocalGeoDbFileName;
            if (File.Exists(file))
            {
                // Open geodatabase
                Geodatabase gdb = await Geodatabase.OpenAsync(file);

                IEnumerable <GeodatabaseFeatureTable> featureTables =
                    gdb.FeatureTables;
                foreach (var table in featureTables)
                {
                    if (table.Name == _lyrName)
                    {
                        // Add the feature layer to the map
                        await GdbHelper.addGeodatabaseLayer(Map, lyrDef, table);

                        MyMapView.SetView(table.Extent);
                        break;
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Initializes ViewModel
        /// </summary>
        protected override async Task InitializeAsync()
        {
            // Create map with layers and set startup location
            var map = new Map()
            {
                InitialExtent = new Envelope(-13636132.3698584, 4546349.82732426, -13633579.1021618, 4547513.1599185, SpatialReferences.WebMercator)
            };

            Map = map;

            // Basemap layer local tile package.
            var basemap = new ArcGISLocalTiledLayer()
            {
                ID          = "Basemap",
                DisplayName = "Basemap",
                //ServiceUri = "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"
                Path = @"../../../../Data/TileCaches/Layers.tpk"
            };

            // Initialize layer in Try - Catch
            Exception exceptionToHandle = null;

            try
            {
                await basemap.InitializeAsync();

                map.Layers.Add(basemap);

                // Uncomment to this to create online layers and comment offline layers to test online editing
                //await CreateOnlineOperationalLayersAsync();

                var operationalLayers = await CreateOfflineOperationalLayersAsync(@"../../../../Data/Databases/LocalWildfire.geodatabase");

                foreach (var layer in operationalLayers)
                {
                    Map.Layers.Add(layer);
                }
            }
            catch (Exception exception)
            {
                // Exception is thrown ie if layer url is not found - ie. {"Error code '400' : 'Invalid URL'"}
                exceptionToHandle = exception;
            }

            if (exceptionToHandle != null)
            {
                // Initialization failed, show message and return
                await MessageService.Instance.ShowMessage(string.Format(
                                                              "Could not create basemap. Error = {0}", exceptionToHandle.ToString()),
                                                          "An error occured");

                return;
            }
            IsInitialized = true;
        }
コード例 #7
0
ファイル: MapTileSourceBehavior.cs プロジェクト: robotil/gcs
        private Layer CreateStaticLayer()
        {
            Layer layer = null;

            if (!string.IsNullOrWhiteSpace(Path) && File.Exists(Path))
            {
                layer =
                    AssociatedObject.Layers.FirstOrDefault(
                        l => !String.IsNullOrWhiteSpace(l.ID) && l.ID.Equals(ID)) as ArcGISLocalTiledLayer;

                if (layer != null)
                {
                    return(null);               // no need to add it is already added
                }
                layer = new ArcGISLocalTiledLayer(Path);
                //layer = new ArcGISTiledMapServiceLayer() { Url = Path };

                OnAddLayer();

                layer.ID = ID;

                layer.Initialized          += OnLayerInitalized;
                layer.InitializationFailed += (o, e) =>
                {
                    OnDone();
                };
            }
            else if (!string.IsNullOrWhiteSpace(Path))
            {
                layer =
                    AssociatedObject.Layers.FirstOrDefault(
                        l => !String.IsNullOrWhiteSpace(l.ID) && l.ID.Equals(ID)) as ArcGISLocalTiledLayer;

                if (layer != null)
                {
                    return(null);               // no need to add it is already added
                }
                //layer = new ArcGISLocalTiledLayer(Path);
                layer = new ArcGISTiledMapServiceLayer()
                {
                    Url = Path
                };

                OnAddLayer();

                layer.ID = ID;

                layer.Initialized          += OnLayerInitalized;
                layer.InitializationFailed += (o, e) =>
                {
                    OnDone();
                };
            }
            return(layer);
        }
 private async void MyMapView_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         var tpk = await GetSingleFileAsync(@"basemaps\campus.tpk");
         var layer = new ArcGISLocalTiledLayer(tpk) { ID = "local_basemap" };
         MyMapView.Map.Layers.Add(layer);
     }
     catch (Exception ex)
     {
         var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
     }
 }
コード例 #9
0
ファイル: MainWindow.xaml.cs プロジェクト: punker76/NVGViewer
        private async void LoadLocalTiledLayerAsync()
        {
            const string filePath = @"Data\Basemap.tpk";

            if (File.Exists(filePath))
            {
                var localTiledLayer = new ArcGISLocalTiledLayer(filePath);
                localTiledLayer.ID = @"LocalBasemap";
                await localTiledLayer.InitializeAsync();

                FocusMapView.Map.Layers.Add(localTiledLayer);
            }
        }
コード例 #10
0
        public MainWindow()
        {
            InitializeComponent();

            //Get the path to the .tpk in the Resources folder
            appPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            tpkFilePath = Path.Combine(appPath, "Resources");
            tpkFullPath = Path.Combine(tpkFilePath, "CharlotteMap.tpk");


            tiledLyr = new ArcGISLocalTiledLayer(tpkFullPath);

            MyMapView.Map.Layers.Add(tiledLyr);
        }
コード例 #11
0
        /// <summary>
        /// Executes ViewModel initialization logic. Called when ViewModel is created from base view model.
        /// </summary>
        protected override async Task InitializeAsync()
        {
            // Create map with layers
            Map = new Map()
            {
                InitialExtent = new Envelope(-14161146.113642, 3137996.40676956, -7626168.31478212, 6574986.2928574)
            };

            // Basemap layer from ArcGIS Online hosted service
            var basemap = new ArcGISLocalTiledLayer()
            {
                ID          = "Basemap",
                DisplayName = "Basemap",
                Path        = @"../../../../Data/TileCaches/Topographic.tpk"
            };

            // Initialize layer in Try - Catch
            Exception exceptionToHandle = null;

            try
            {
                await basemap.InitializeAsync();

                Map.Layers.Add(basemap);

                // Open geodatbase and find States feature table
                var geodatabase = await Geodatabase.OpenAsync(@"../../../../Data/Databases/usa.geodatabase");

                _featureTable = geodatabase.FeatureTables.First(x => x.Name == "States");

                // Create graphics layer for start and endpoints
                CreateGraphicsLayers();
                IsInitialized = true;
            }
            catch (Exception exception)
            {
                // Exception is thrown ie if layer url is not found - ie. {"Error code '400' : 'Invalid URL'"}
                exceptionToHandle = exception;
            }

            if (exceptionToHandle != null)
            {
                // Initialization failed, show message and return
                await MessageService.Instance.ShowMessage(string.Format(
                                                              "Could not create basemap. Error = {0}", exceptionToHandle.ToString()),
                                                          "An error occured");

                return;
            }
        }
コード例 #12
0
        // Download the tile cache
        private async void ExportTilesButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                panelUI.IsEnabled   = false;
                panelTOC.Visibility = Visibility.Collapsed;
                progress.Visibility = Visibility.Visible;

                string tilePath        = Path.Combine(Path.GetTempPath(), TILE_CACHE_FOLDER);
                var    downloadOptions = new DownloadTileCacheParameters(tilePath)
                {
                    OverwriteExistingFiles = true
                };

                var result = await _exportTilesTask.GenerateTileCacheAndDownloadAsync(
                    _genOptions, downloadOptions, TimeSpan.FromSeconds(5), CancellationToken.None);

                var localTiledLayer = mapView.Map.Layers.FirstOrDefault(lyr => lyr.ID == LOCAL_LAYER_ID);
                if (localTiledLayer != null)
                {
                    mapView.Map.Layers.Remove(localTiledLayer);
                }

                localTiledLayer = new ArcGISLocalTiledLayer(result.OutputPath)
                {
                    ID = LOCAL_LAYER_ID
                };
                mapView.Map.Layers.Insert(1, localTiledLayer);

                _onlineTiledLayer.IsVisible = false;

                if (mapView.Scale < _genOptions.MinScale)
                {
                    await mapView.SetViewAsync(mapView.Extent.GetCenter(), _genOptions.MinScale);
                }

                panelTOC.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                panelUI.IsEnabled   = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
コード例 #13
0
ファイル: IS3View.cs プロジェクト: linxy5326/iS3-Desktop
 public void addLocalTiledLayer(string filePath, string id)
 {
     if (File.Exists(filePath))
     {
         ArcGISLocalTiledLayer localTiledLayer =
             new ArcGISLocalTiledLayer(filePath);
         localTiledLayer.ID          = id;
         localTiledLayer.DisplayName = id;
         _map.Layers.Add(localTiledLayer);
     }
     else
     {
         string error = string.Format(_fileNotExist, filePath);
         ErrorReport.Report(error);
     }
 }
        private async void MyMapView_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var tpk = await GetSingleFileAsync("basemap.tpk");

                var layer = new ArcGISLocalTiledLayer(tpk)
                {
                    ID = "local_basemap"
                };
                MyMapView.Map.Layers.Add(layer);
            }
            catch (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
        }
コード例 #15
0
ファイル: IS3View2D.cs プロジェクト: flyong/iS3-Transplant
 public void addLocalTiledLayer(string DestnationPath, string id)
 {
     if (File.Exists(DestnationPath))
     {
         ArcGISLocalTiledLayer localTiledLayer =
             new ArcGISLocalTiledLayer(DestnationPath);
         localTiledLayer.ID          = id;
         localTiledLayer.DisplayName = id;
         //默认全关
         localTiledLayer.IsVisible = false;
         _map.Layers.Add(localTiledLayer);
     }
     else
     {
         string error = string.Format(_fileNotExist, DestnationPath);
         // ErrorReport.Report(error);
     }
 }
コード例 #16
0
        public MainWindow()
        {
            // License setting and ArcGIS Runtime initialization is done in Application.xaml.cs.

            InitializeComponent();

            MyMap.Layers.LayersInitialized += (s, e) =>
            {
                graphicsLayer = MyMap.Layers["ExtentGraphicsLayer"] as GraphicsLayer;

                ArcGISLocalTiledLayer localTiledLayer = MyMap.Layers["EastCoastUS"] as ArcGISLocalTiledLayer;

                // Add graphic to represent Initial Extent
                Graphic initialExtentGraphic = new Graphic()
                {
                    Symbol = new SimpleFillSymbol()
                    {
                        BorderBrush     = Brushes.Green,
                        BorderThickness = 5
                    },
                    Geometry = localTiledLayer.InitialExtent,
                };
                initialExtentGraphic.Attributes["MapTipText"] = "Initial Extent";
                graphicsLayer.Graphics.Add(initialExtentGraphic);

                // Add graphic to represent Full Extent
                Graphic fullExtentGraphic = new Graphic()
                {
                    Symbol = new SimpleFillSymbol()
                    {
                        BorderBrush     = Brushes.Red,
                        BorderThickness = 5
                    },
                    Geometry = localTiledLayer.FullExtent,
                };
                fullExtentGraphic.Attributes["MapTipText"] = "Full Extent";
                graphicsLayer.Graphics.Add(fullExtentGraphic);

                MyMap.ZoomTo(initialExtentGraphic.Geometry);
            };
        }
コード例 #17
0
        void LoadTiledLayer1(EngineeringMap emap)
        {
            ArcGISLocalTiledLayer tileLayr1 = Map.Layers["TiledLayer1"] as ArcGISLocalTiledLayer;

            if (tileLayr1 != null)
            {
                Map.Layers.Remove(tileLayr1);
            }

            string file = ProjDef.LocalTilePath + "\\" + emap.LocalTileFileName1;

            if (File.Exists(file))
            {
                ArcGISLocalTiledLayer newLayr = new ArcGISLocalTiledLayer(file);
                newLayr.ID          = "TiledLayer1";
                newLayr.DisplayName = "TileLayer1";
                Map.Layers.Add(newLayr);

                MyMapView.SetView(newLayr.FullExtent);
            }
        }
コード例 #18
0
        private async void GoOffline()
        {
            try
            {
                this.MyMapView.Map.Layers.Clear();

                var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var appPath      = assemblyPath.Substring(0, assemblyPath.LastIndexOf("bin"));
                var tilesPath    = appPath + "\\" + this.LocalTilesPathTextBlock.Text;

                var localTileLayer = new ArcGISLocalTiledLayer(tilesPath);
                await localTileLayer.InitializeAsync();

                this.MyMapView.Map.Layers.Add(localTileLayer);

                var localGdb = await Geodatabase.OpenAsync(this.LocalDataPathTextBlock.Text);

                var localPoiTable = localGdb.FeatureTables.FirstOrDefault();

                var localPoiLayer = new FeatureLayer(localPoiTable);
                localPoiLayer.ID          = "POI";
                localPoiLayer.DisplayName = localPoiTable.Name;
                var flamePictureMarker = new PictureMarkerSymbol();
                await flamePictureMarker.SetSourceAsync(new Uri(flameImageUrl));

                flamePictureMarker.Height = 24;
                flamePictureMarker.Width  = 24;
                var simpleRenderer = new SimpleRenderer();
                simpleRenderer.Symbol  = flamePictureMarker;
                localPoiLayer.Renderer = simpleRenderer;

                await localPoiLayer.InitializeAsync();

                this.MyMapView.Map.Layers.Add(localPoiLayer);
            }
            catch (Exception exp)
            {
                SyncStatusTextBlock.Text = exp.Message;
            }
        }
コード例 #19
0
            /// <summary>
            /// Initializes a new instance of the MainViewModel class.
            /// </summary>
            public MainViewModel()
            {
                if (IsInDesignMode)
                {
                    // Code runs in Blend --> create design time data.
                }
                else
                {
                    // Code runs "for real"
                    ConfigService config = new ConfigService();
                    this.myModel = config.LoadJSON();
                    this.SearchRelayCommand = new RelayCommand<string>(Search);
                    this.SelectByRectangleRelayCommand = new RelayCommand(SelectByRectangle);
                    this.AddPointRelayCommand = new RelayCommand(AddPoint);

                    Messenger.Default.Register<Esri.ArcGISRuntime.Controls.MapView>(this, (mapView) =>
                    {
                        this.mapView = mapView;
                        this.mapView.MaxScale = 500;

                        ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(this.TilePackage);
                        localTiledLayer.ID = "SF Basemap";
                        localTiledLayer.InitializeAsync();

                        this.mapView.Map.Layers.Add(localTiledLayer);

                        this.CreateLocalServiceAndDynamicLayer();
                        this.CreateFeatureLayers();

                        this.graphicsLayer = new Esri.ArcGISRuntime.Layers.GraphicsLayer();
                        this.graphicsLayer.ID = "Results";
                        this.graphicsLayer.InitializeAsync();
                        this.mapView.Map.Layers.Add(this.graphicsLayer);
                    });
                }
            }
コード例 #20
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"
                ConfigService config = new ConfigService();
                this.myModel                       = config.LoadJSON();
                this.SearchRelayCommand            = new RelayCommand <string>(Search);
                this.SelectByRectangleRelayCommand = new RelayCommand(SelectByRectangle);
                this.AddPointRelayCommand          = new RelayCommand(AddPoint);

                Messenger.Default.Register <Esri.ArcGISRuntime.Controls.MapView>(this, (mapView) =>
                {
                    this.mapView          = mapView;
                    this.mapView.MaxScale = 500;

                    ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(this.TilePackage);
                    localTiledLayer.ID = "SF Basemap";
                    localTiledLayer.InitializeAsync();

                    this.mapView.Map.Layers.Add(localTiledLayer);

                    this.CreateLocalServiceAndDynamicLayer();
                    this.CreateFeatureLayers();

                    this.graphicsLayer    = new Esri.ArcGISRuntime.Layers.GraphicsLayer();
                    this.graphicsLayer.ID = "Results";
                    this.graphicsLayer.InitializeAsync();
                    this.mapView.Map.Layers.Add(this.graphicsLayer);
                });
            }
        }
コード例 #21
0
		/// <summary>
		/// Executes ViewModel initialization logic. Called when ViewModel is created from base view model. 
		/// </summary>
		protected override async Task InitializeAsync()
		{
			// Create map with layers
			Map = new Map()
				{
					InitialExtent = new Envelope(-14161146.113642, 3137996.40676956, -7626168.31478212, 6574986.2928574)
				};		

			// Basemap layer from ArcGIS Online hosted service
			var basemap = new ArcGISLocalTiledLayer()
			{
				ID = "Basemap",
				DisplayName = "Basemap",
				Path = @"../../../../Data/TileCaches/Topographic.tpk"
			};

			// Initialize layer in Try - Catch 
			Exception exceptionToHandle = null;
			try
			{
				await basemap.InitializeAsync();
				Map.Layers.Add(basemap);

				// Open geodatbase and find States feature table
				var geodatabase = await Geodatabase.OpenAsync(@"../../../../Data/Databases/usa.geodatabase");
				_featureTable = geodatabase.FeatureTables.First(x => x.Name == "States");

				// Create graphics layer for start and endpoints
				CreateGraphicsLayers();
				IsInitialized = true;
			}
			catch (Exception exception)
			{
				// Exception is thrown ie if layer url is not found - ie. {"Error code '400' : 'Invalid URL'"} 
				exceptionToHandle = exception;
			}

			if (exceptionToHandle != null)
			{
				// Initialization failed, show message and return
				await MessageService.Instance.ShowMessage(string.Format(
					"Could not create basemap. Error = {0}", exceptionToHandle.ToString()),
					"An error occured");
				return;
			}
		}
コード例 #22
0
		// Download the tile cache
		private async void ExportTilesButton_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				panelTOC.Visibility = Visibility.Collapsed;
				progress.Visibility = Visibility.Visible;

				var downloadOptions = new DownloadTileCacheParameters(ApplicationData.Current.TemporaryFolder)
				{
					OverwriteExistingFiles = true
				};

				var localTiledLayer = MyMapView.Map.Layers.FirstOrDefault(lyr => lyr.ID == LOCAL_LAYER_ID);
				if (localTiledLayer != null)
					MyMapView.Map.Layers.Remove(localTiledLayer);
				
				var result = await _exportTilesTask.GenerateTileCacheAndDownloadAsync(
					_genOptions, downloadOptions, TimeSpan.FromSeconds(5), CancellationToken.None, 
					new Progress<ExportTileCacheJob>((job) => // Callback for reporting status during tile cache generation
					{
						Debug.WriteLine(getTileCacheGenerationStatusMessage(job));
					}),
					new Progress<ExportTileCacheDownloadProgress>((downloadProgress) => // Callback for reporting status during tile cache download
					{
						Debug.WriteLine(getDownloadStatusMessage(downloadProgress));
					}));

				localTiledLayer = new ArcGISLocalTiledLayer(result.OutputPath) { ID = LOCAL_LAYER_ID };
				MyMapView.Map.Layers.Insert(1, localTiledLayer);

				_onlineTiledLayer.IsVisible = false;

                if (MyMapView.Scale < _genOptions.MinScale) 
                {
                    // Get current viewpoints extent from the MapView
                    var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
                    var viewpointExtent = currentViewpoint.TargetGeometry.Extent;
                    await MyMapView.SetViewAsync(viewpointExtent.GetCenter(), _genOptions.MinScale);
                }
					

				panelTOC.Visibility = Visibility.Visible;
				panelExport.Visibility = Visibility.Collapsed;

			}
			catch (Exception ex)
			{
				var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
			}
			finally
			{
				progress.Visibility = Visibility.Collapsed;
			}
		}
        // Download the tile cache
        private async void ExportTilesButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                panelUI.IsEnabled = false;
                panelTOC.Visibility = Visibility.Collapsed;
                progress.Visibility = Visibility.Visible;

                string tilePath = Path.Combine(Path.GetTempPath(), TILE_CACHE_FOLDER);
                var downloadOptions = new DownloadTileCacheParameters(tilePath)
                {
                    OverwriteExistingFiles = true
                };

                var result = await _exportTilesTask.GenerateTileCacheAndDownloadAsync(
                    _genOptions, downloadOptions, TimeSpan.FromSeconds(5), CancellationToken.None);

                var localTiledLayer = mapView.Map.Layers.FirstOrDefault(lyr => lyr.ID == LOCAL_LAYER_ID);
                if (localTiledLayer != null)
                    mapView.Map.Layers.Remove(localTiledLayer);

                localTiledLayer = new ArcGISLocalTiledLayer(result.OutputPath) { ID = LOCAL_LAYER_ID };
                mapView.Map.Layers.Insert(1, localTiledLayer);

                _onlineTiledLayer.IsVisible = false;

                if (mapView.Scale < _genOptions.MinScale)
                    await mapView.SetViewAsync(mapView.Extent.GetCenter(), _genOptions.MinScale);

                panelTOC.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                panelUI.IsEnabled = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
コード例 #24
0
ファイル: IS3View.cs プロジェクト: iS3-Project/iS3
 public void addLocalTiledLayer(string filePath, string id)
 {
     if (File.Exists(filePath))
     {
         ArcGISLocalTiledLayer localTiledLayer =
             new ArcGISLocalTiledLayer(filePath);
         localTiledLayer.ID = id;
         localTiledLayer.DisplayName = id;
         _map.Layers.Add(localTiledLayer);
     }
     else
     {
         string error = string.Format(_fileNotExist, filePath);
         ErrorReport.Report(error);
     }
 }
コード例 #25
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"
                ConfigService config = new ConfigService();
                this.myModel = config.LoadJSON();
                this.AddStopsRelayCommand = new RelayCommand(AddStops);

                Messenger.Default.Register<Esri.ArcGISRuntime.Controls.MapView>(this, (mapView) =>
                {
                    this.mapView = mapView;
                    this.mapView.MaxScale = 500;

                    ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(this.TilePackage);
                    localTiledLayer.ID = "SF Basemap";
                    localTiledLayer.InitializeAsync();

                    this.mapView.Map.Layers.Add(localTiledLayer);

                    this.CreateLocalServiceAndDynamicLayer();
                    this.CreateFeatureLayers();


                    //============================
                    // Create a new renderer to symbolize the routing polyline and apply it to the GraphicsLayer
                    SimpleLineSymbol polylineRouteSymbol = new SimpleLineSymbol();
                    polylineRouteSymbol.Color = System.Windows.Media.Colors.Red;
                    polylineRouteSymbol.Style = Esri.ArcGISRuntime.Symbology.SimpleLineStyle.Solid;
                    polylineRouteSymbol.Width = 4;
                    SimpleRenderer polylineRouteRenderer = new SimpleRenderer();
                    polylineRouteRenderer.Symbol = polylineRouteSymbol;

                    // Create a new renderer to symbolize the start and end points that define the route and apply it to the GraphicsLayer
                    SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol();
                    stopSymbol.Color = System.Windows.Media.Colors.Green;
                    stopSymbol.Size = 12;
                    stopSymbol.Style = SimpleMarkerStyle.Circle;
                    SimpleRenderer stopRenderer = new SimpleRenderer();
                    stopRenderer.Symbol = stopSymbol;
                   
                    // create the route results graphics layer
                    this.routeGraphicsLayer = new GraphicsLayer();
                    this.routeGraphicsLayer.ID = "RouteResults";
                    this.routeGraphicsLayer.DisplayName = "Routes";
                    this.routeGraphicsLayer.Renderer = polylineRouteRenderer;
                    this.routeGraphicsLayer.InitializeAsync();
                    
                    this.mapView.Map.Layers.Add(this.routeGraphicsLayer);

                    // create the stops graphics layer
                    this.stopsGraphicsLayer = new GraphicsLayer();
                    this.stopsGraphicsLayer.ID = "Stops";
                    this.stopsGraphicsLayer.DisplayName = "Stops";
                    this.stopsGraphicsLayer.Renderer = stopRenderer;
                    this.stopsGraphicsLayer.InitializeAsync();
                    this.mapView.Map.Layers.Add(this.stopsGraphicsLayer);

                    // Offline routing task.
                    routeTask = new LocalRouteTask(@"C:\ArcGISRuntimeBook\Data\Networks\RuntimeSanFrancisco.geodatabase", "Streets_ND");


                });
            }
        }
コード例 #26
0
		private async Task LoadOfflineMap(OfflineMapItem offlineMapItem)
		{
			_currentOfflineMapItem = offlineMapItem;
			var basemapName = GetBasemapNameFromDirectory(offlineMapItem.OfflineMapPath);
			var arcGisLocalTiledLayer =
				new ArcGISLocalTiledLayer(string.Format("{0}\\{1}{2}", offlineMapItem.OfflineMapPath, basemapName,
					OfflineMapItem.BasemapFilenameExtension));
			arcGisLocalTiledLayer.DisplayName = basemapName;
			var offlineMap = new Map();
			offlineMap.Layers.Add(arcGisLocalTiledLayer);

			var files = Directory.GetFiles(offlineMapItem.OfflineMapPath,
				string.Format("*{0}", OfflineMapItem.GeodatabaseFilenameExtension));
			foreach (var file in files)
			{
				var gdbFile = file.Replace("/", @"\");
				var featureLayerList = await CreateOfflineFeatureLayersAsync(gdbFile);

				foreach (var featureLayer in featureLayerList)
				{
					var geodatabaseFeatureTable = featureLayer.FeatureTable as GeodatabaseFeatureTable;
					featureLayer.DisplayName = geodatabaseFeatureTable.ServiceInfo.Name;
					featureLayer.IsVisible = geodatabaseFeatureTable.ServiceInfo.DefaultVisibility;
					offlineMap.Layers.Add(featureLayer);
				}

				break;
			}

			var mapView = new MapView {Map = offlineMap};
			CurrentEsriMapView = mapView;
			CurrentEsriMapView.MapViewTapped += CurrentEsriMapViewTapped;
			await Task.Delay(TimeSpan.FromSeconds(2));
		}
コード例 #27
0
        private async void TryLoadLocalLayers()
        {
            try
            {
                if (string.IsNullOrEmpty(this.localGeodatabasePath))
                {
                    throw new Exception("Local features do not yet exist. Please generate them first.");
                }

                if (string.IsNullOrEmpty(this.localTileCachePath))
                {
                    throw new Exception("Local tiles do not yet exist. Please generate them first.");
                }

                // create a local tiled layer
                var basemapLayer = new ArcGISLocalTiledLayer(this.localTileCachePath);

                // open the local geodatabase, get the first (only) table, create a FeatureLayer to display it
                var localGdb = await Geodatabase.OpenAsync(this.localGeodatabasePath);
                var gdbTable = localGdb.FeatureTables.FirstOrDefault();
                var operationalLayer = new FeatureLayer(gdbTable);

                // give the feature layer an ID so it can be found later
                operationalLayer.ID = "Sightings";

                await basemapLayer.InitializeAsync();
                await operationalLayer.InitializeAsync();

                // see if there was an exception when initializing the layer
                if (basemapLayer.InitializationException != null || operationalLayer.InitializationException != null)
                {
                    // unable to load one or more of the layers, throw an exception
                    throw new Exception("Could not initialize local layers");
                }

                // add the local layers to the map
                MyMapView.Map.Layers.Add(basemapLayer);
                MyMapView.Map.Layers.Add(operationalLayer);

            }
            catch (Exception exp)
            {
                MessageBox.Show("Unable to load local layers: " + exp.Message, "Load Layers");
            }
        }
コード例 #28
0
        /// <summary>
        /// Initializes ViewModel
        /// </summary>
		protected override async Task InitializeAsync()
        {
            // Create map with layers and set startup location
            var map = new Map()
            {
                InitialExtent = new Envelope(-13636132.3698584, 4546349.82732426, -13633579.1021618, 4547513.1599185, SpatialReferences.WebMercator)
            };
            Map = map;

            // Basemap layer local tile package. 
			var basemap = new ArcGISLocalTiledLayer()
            {
                ID = "Basemap",
                DisplayName = "Basemap",
				//ServiceUri = "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"
				Path = @"../../../../Data/TileCaches/Layers.tpk"
            };

            // Initialize layer in Try - Catch 
            Exception exceptionToHandle = null;
            try
            {
                await basemap.InitializeAsync();
                map.Layers.Add(basemap);
                
                // Uncomment to this to create online layers and comment offline layers to test online editing
                //await CreateOnlineOperationalLayersAsync();

				var operationalLayers = await CreateOfflineOperationalLayersAsync(@"../../../../Data/Databases/LocalWildfire.geodatabase");
				foreach (var layer in operationalLayers)
				{
					Map.Layers.Add(layer);
				}
            }
            catch (Exception exception)
            {
                // Exception is thrown ie if layer url is not found - ie. {"Error code '400' : 'Invalid URL'"} 
                exceptionToHandle = exception;
            }

            if (exceptionToHandle != null)
            {
                // Initialization failed, show message and return
                await MessageService.Instance.ShowMessage(string.Format(
                    "Could not create basemap. Error = {0}", exceptionToHandle.ToString()),
                    "An error occured");
                return;
            }
			IsInitialized = true;
        }
コード例 #29
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real"
                ConfigService config = new ConfigService();
                this.myModel = config.LoadJSON();
                this.AddStopsRelayCommand = new RelayCommand(AddStops);

                Messenger.Default.Register <Esri.ArcGISRuntime.Controls.MapView>(this, (mapView) =>
                {
                    this.mapView          = mapView;
                    this.mapView.MaxScale = 500;

                    ArcGISLocalTiledLayer localTiledLayer = new ArcGISLocalTiledLayer(this.TilePackage);
                    localTiledLayer.ID = "SF Basemap";
                    localTiledLayer.InitializeAsync();

                    this.mapView.Map.Layers.Add(localTiledLayer);

                    this.CreateLocalServiceAndDynamicLayer();
                    this.CreateFeatureLayers();


                    //============================
                    // Create a new renderer to symbolize the routing polyline and apply it to the GraphicsLayer
                    SimpleLineSymbol polylineRouteSymbol = new SimpleLineSymbol();
                    polylineRouteSymbol.Color            = System.Windows.Media.Colors.Red;
                    polylineRouteSymbol.Style            = Esri.ArcGISRuntime.Symbology.SimpleLineStyle.Solid;
                    polylineRouteSymbol.Width            = 4;
                    SimpleRenderer polylineRouteRenderer = new SimpleRenderer();
                    polylineRouteRenderer.Symbol         = polylineRouteSymbol;

                    // Create a new renderer to symbolize the start and end points that define the route and apply it to the GraphicsLayer
                    SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol();
                    stopSymbol.Color            = System.Windows.Media.Colors.Green;
                    stopSymbol.Size             = 12;
                    stopSymbol.Style            = SimpleMarkerStyle.Circle;
                    SimpleRenderer stopRenderer = new SimpleRenderer();
                    stopRenderer.Symbol         = stopSymbol;

                    // create the route results graphics layer
                    this.routeGraphicsLayer             = new GraphicsLayer();
                    this.routeGraphicsLayer.ID          = "RouteResults";
                    this.routeGraphicsLayer.DisplayName = "Routes";
                    this.routeGraphicsLayer.Renderer    = polylineRouteRenderer;
                    this.routeGraphicsLayer.InitializeAsync();

                    this.mapView.Map.Layers.Add(this.routeGraphicsLayer);

                    // create the stops graphics layer
                    this.stopsGraphicsLayer             = new GraphicsLayer();
                    this.stopsGraphicsLayer.ID          = "Stops";
                    this.stopsGraphicsLayer.DisplayName = "Stops";
                    this.stopsGraphicsLayer.Renderer    = stopRenderer;
                    this.stopsGraphicsLayer.InitializeAsync();
                    this.mapView.Map.Layers.Add(this.stopsGraphicsLayer);

                    // Offline routing task.
                    routeTask = new LocalRouteTask(@"C:\ArcGISRuntimeBook\Data\Networks\RuntimeSanFrancisco.geodatabase", "Streets_ND");
                });
            }
        }