Exemplo n.º 1
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();                      

                    });
                }
            }
Exemplo n.º 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();
                });
            }
        }
        /// <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;
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
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;
            }
        }
        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;
            }
        }
Exemplo n.º 7
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);
                });
            }
        }
Exemplo n.º 8
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);
                    });
                }
            }
        /// <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;
        }
Exemplo n.º 10
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");
            }
        }
Exemplo n.º 11
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");


                });
            }
        }
Exemplo n.º 12
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");
                });
            }
        }
		/// <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;
			}
		}