Exemplo n.º 1
0
        private async void Initialize()
        {
            // Create a map and add it to the view
            MyMapView.Map = new Map(Basemap.CreateStreetsWithReliefVector());

            try
            {
                // Start the local server instance
                await LocalServer.Instance.StartAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Local Server load failed");
                return;
            }

            // Load the sample data and get the path
            string myfeatureServicePath = await GetFeatureLayerPath();

            // Create the feature service to serve the local data
            _localFeatureService = new LocalFeatureService(myfeatureServicePath);

            // Listen to feature service status changes
            _localFeatureService.StatusChanged += _localFeatureService_StatusChanged;

            // Start the feature service
            try
            {
                await _localFeatureService.StartAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "The feature service failed to load");
            }
        }
        private async Task CreateServices()
        {
            try
            {
                // Arrange the data before starting the services
                string mapServicePath = await GetMpkPath();

                string featureServicePath = await GetFeatureLayerPath();

                string geoprocessingPath = await GetGpPath();

                // Create each service but don't start any
                _localMapService           = new LocalMapService(mapServicePath);
                _localFeatureService       = new LocalFeatureService(featureServicePath);
                _localGeoprocessingService = new LocalGeoprocessingService(geoprocessingPath);

                // Subscribe to status updates for each service
                _localMapService.StatusChanged           += (o, e) => { UpdateUiWithServiceUpdate("Map Service", e.Status); };
                _localFeatureService.StatusChanged       += (o, e) => { UpdateUiWithServiceUpdate("Feature Service", e.Status); };
                _localGeoprocessingService.StatusChanged += (o, e) => { UpdateUiWithServiceUpdate("Geoprocessing Service", e.Status); };

                // Enable the UI to select services
                comboServiceSelect.IsEnabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to create services");
            }
        }
        private async void Initialize()
        {
            // Create a map and add it to the view
            MyMapView.Map = new Map(Basemap.CreateStreetsWithReliefVector());

            try
            {
                // Start the local server instance
                await LocalServer.Instance.StartAsync();
            }
            catch (Exception ex)
            {
                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");
                return;
            }

            // Load the sample data and get the path
            string myfeatureServicePath = GetFeatureLayerPath();

            // Create the feature service to serve the local data
            _localFeatureService = new LocalFeatureService(myfeatureServicePath);

            // Listen to feature service status changes
            _localFeatureService.StatusChanged += _localFeatureService_StatusChanged;

            // Start the feature service
            try
            {
                await _localFeatureService.StartAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "The feature service failed to load");
            }
        }
Exemplo n.º 4
0
        public async void Initialize_LocalServer()
        {
            try
            {
                // 1.LocalServer 모듈 시작...
                // LocalServer must not be running when setting the data path.
                if (LocalServer.Instance.Status == LocalServerStatus.Started)
                {
                    await LocalServer.Instance.StopAsync();
                }

                if (LocalServer.Instance.Status == LocalServerStatus.Stopped)
                {
                    // Set the local data path - must be done before starting. On most systems, this will be C:\EsriSamples\AppData.
                    // This path should be kept short to avoid Windows path length limitations.
                    string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName;
                    string tempDataPath     = BizUtil.GetDataFolder("EsriLocalServer", "AppData");

                    Directory.CreateDirectory(tempDataPath); // CreateDirectory won't overwrite if it already exists.
                    LocalServer.Instance.AppDataPath = tempDataPath;

                    // Start the local server instance
                    await LocalServer.Instance.StartAsync();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Please ensure that local server is installed prior to using the sample. See instructions in readme.md. Message: {0}", ex.Message), "Local Server failed to start");
                return;
            }


            // 2.서버상에 LocalFeatureService 서비스시작..
            // Load the sample data and get the path
            if (_localFeatureService == null)
            {
                string myfeatureServicePath = GetFeatureLayerPath();

                // Create the feature service to serve the local data
                _localFeatureService = new LocalFeatureService(myfeatureServicePath);
                //_localFeatureService.MaxRecords = 3000; //피처서비스 최대 표현레코드 수

                // Listen to feature service status changes
                _localFeatureService.StatusChanged += _localFeatureService_StatusChanged;

                // Start the feature service
                try
                {
                    await _localFeatureService.StartAsync();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "The feature service failed to load");
                }
            }
        }
Exemplo n.º 5
0
        private async void Initialize()
        {
            // Create a map and add it to the view
            MyMapView.Map = new Map(Basemap.CreateStreetsWithReliefVector());

            try
            {
                // LocalServer must not be running when setting the data path.
                if (LocalServer.Instance.Status == LocalServerStatus.Started)
                {
                    await LocalServer.Instance.StopAsync();
                }

                // Set the local data path - must be done before starting. On most systems, this will be C:\EsriSamples\AppData.
                // This path should be kept short to avoid Windows path length limitations.
                string tempDataPathRoot = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.Windows)).FullName;
                string tempDataPath     = Path.Combine(tempDataPathRoot, "EsriSamples", "AppData");
                Directory.CreateDirectory(tempDataPath); // CreateDirectory won't overwrite if it already exists.
                LocalServer.Instance.AppDataPath = tempDataPath;

                // Start the local server instance
                await LocalServer.Instance.StartAsync();
            }
            catch (Exception ex)
            {
                var localServerTypeInfo = typeof(LocalMapService).GetTypeInfo();
                var localServerVersion  = FileVersionInfo.GetVersionInfo(localServerTypeInfo.Assembly.Location);

                MessageBox.Show($"Please ensure that local server {localServerVersion.FileVersion} is installed prior to using the sample. The download link is in the description. Message: {ex.Message}", "Local Server failed to start");
                return;
            }

            // Load the sample data and get the path
            string myfeatureServicePath = GetFeatureLayerPath();

            // Create the feature service to serve the local data
            _localFeatureService = new LocalFeatureService(myfeatureServicePath);

            // Listen to feature service status changes
            _localFeatureService.StatusChanged += _localFeatureService_StatusChanged;

            // Start the feature service
            try
            {
                await _localFeatureService.StartAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "The feature service failed to load");
            }
        }
        private async void StopServerButtonClicked(object sender, RoutedEventArgs e)
        {
            // Update the UI
            btnServiceStart.IsEnabled        = false;
            btnServiceStop.IsEnabled         = false;
            LocalServerStartButton.IsEnabled = true;
            LocalServerStopButton.IsEnabled  = false;

            // Stop the server
            await LocalServer.Instance.StopAsync();

            // Clear references to the services
            _localFeatureService       = null;
            _localMapService           = null;
            _localGeoprocessingService = null;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 创建本地要素服务,并加载底图
        /// </summary>
        /// <param name="myMapView"></param>
        public async void CreateLocalFeatureService(MapView myMapView)
        {
            try
            {
                //读取配置文件路径
                var localFeatureLocation = ConfigurationSettings.AppSettings["LocalFeatureLocation"];
                var featureLayersCount   = Convert.ToInt32(ConfigurationSettings.AppSettings["FeatureLayersCount"]);
                //启动本地要素服务
                var localFeatureService = new LocalFeatureService(localFeatureLocation);
                await localFeatureService.StartAsync();

                //保存LocalFeatureUrl
                Global.LocalFeatureUrl = localFeatureService.UrlFeatureService;
                //加载Layers
                for (var i = 0; i < featureLayersCount; i++)
                {
                    var featureTable = new ServiceFeatureTable
                    {
                        ServiceUri = localFeatureService.UrlFeatureService + string.Format("/{0}", i)
                    };
                    await featureTable.InitializeAsync(myMapView.SpatialReference);

                    if (featureTable.IsInitialized)
                    {
                        var flayer = new FeatureLayer
                        {
                            ID           = featureTable.Name, //table.Name,
                            FeatureTable = featureTable,
                            DisplayName  = featureTable.Name
                        };
                        myMapView.Map.Layers.Add(flayer);
                        var extent = featureTable.ServiceInfo.Extent;
                        await myMapView.SetViewAsync(extent.Expand(1.10));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 8
0
        async Task addLocalMapFile(string DestnationPath)
        {
            if (File.Exists(DestnationPath))
            {
                IsBusy = true;

                _localFeatureService = new LocalFeatureService(DestnationPath, _maxRecords);
                await _localFeatureService.StartAsync();

                IsBusy = false;
                ArcGISDynamicMapServiceLayer dynamicServiceLayer =
                    new ArcGISDynamicMapServiceLayer();
                dynamicServiceLayer.ID          = "localMap";
                dynamicServiceLayer.DisplayName = "localMap";
                dynamicServiceLayer.ServiceUri  = _localFeatureService.UrlMapService;
                _map.Layers.Add(dynamicServiceLayer);
            }
            else
            {
                string error = string.Format(_fileNotExist, DestnationPath);
                // MessageBox.Show(error);
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            AddRecordButton.IsEnabled = false;

            // Create the LocalFeatureService and set MaxRecords property
            _localFeatureService = new LocalFeatureService(@"..\Maps-and-Data\CitiesOverOneMillion.mpk")
            {
                MaxRecords = 100000,
            };

            // Register an event handler for the PropertyChanged Event
            _localFeatureService.PropertyChanged += (s, propertyChangedEventArgs) =>
            {
                // Get the property
                var property = _localFeatureService.GetType().GetProperty(propertyChangedEventArgs.PropertyName);

                // Get the Value
                var value = property.GetValue(_localFeatureService, null);

                if (value == null)
                {
                    return;
                }

                // Get the property type
                string varType = value.GetType().ToString();

                // Display the property info
                switch (varType)
                {
                case "System.Collections.ObjectModel.ReadOnlyCollection`1[ESRI.ArcGIS.Client.Local.LayerDetails]":
                    statusDisplay.Items.Insert(0, propertyChangedEventArgs.PropertyName + ": " + _localFeatureService.FeatureLayers.Count.ToString());
                    break;

                default:
                    statusDisplay.Items.Insert(0, propertyChangedEventArgs.PropertyName + ": " + value.ToString());
                    break;
                }

                // Display the error
                if (_localFeatureService.Error != null)
                {
                    statusDisplay.Items.Insert(0, "Error: " + _localFeatureService.Error.Message);
                }
            };

            // Start the LocalFeatureService
            _localFeatureService.StartAsync(x =>
            {
                // Create a new FeatureLayer (to contain the table)
                _featureLayerTable = new FeatureLayer()
                {
                    Url = _localFeatureService.UrlFeatureService + "/1",
                    ID  = "EditTable",
                    DisableClientCaching = true,
                    AutoSave             = false,
                    //Do not use ESRI.ArcGIS.Client.FeatureLayer.QueryMode.OnDemand
                    Mode      = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.Snapshot,
                    OutFields = new OutFields()
                    {
                        "*"
                    },
                };

                /*
                 * Register a series of inline event handlers...
                 */

                // Register an handler for the InitializationFailed event
                _featureLayerTable.InitializationFailed += (s, e) =>
                {
                    statusDisplay.Items.Insert(0, _featureLayerTable.InitializationFailure.Message);
                };

                // Register a handler for the Initialized event (raised by an explicit Initialize call)
                _featureLayerTable.Initialized += (s, e) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer Initialized Event Raised");
                    statusDisplay.Items.Insert(0, "FeatureLayer contains: " + _featureLayerTable.Graphics.Count.ToString() + " features"); //This will be 0.
                    _featureLayerTable.Update();
                };

                // Register a handler for the UpdateCompleted event (raised by an explicit Update call)
                _featureLayerTable.UpdateCompleted += (senderObj, eventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer UpdateCompleted Event Raised");
                    statusDisplay.Items.Insert(0, "FeatureLayer contains: " + _featureLayerTable.Graphics.Count.ToString() + " features"); //This will be the total number (n) graphic features (up to service query limit).
                    AddRecordButton.IsEnabled = true;
                };

                // Register a handler for the Begin Save Edits event (raised by the explicit Save Edits call)
                _featureLayerTable.BeginSaveEdits += (s1, beginEditEventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer BeginSaveEdits Event Raised");
                };

                // Register a handler for the End Save Edits event (raised by server response)
                _featureLayerTable.EndSaveEdits += (s2, endEditEventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "## Edit Successful ##");
                    // Edit was successful - call Update to trigger a refresh and display the number of features
                    _featureLayerTable.Update();
                };

                // Register a handler for the Save Edits Failed event (raised by server response)
                _featureLayerTable.SaveEditsFailed += (s3, taskFailedEventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer SaveEditsFailed Event Raised: " + taskFailedEventArgs.Error.Message);
                };

                // Finally... call the Initialize method to kick everything off...
                _featureLayerTable.Initialize();
            });
        }
Exemplo n.º 10
0
        public MainWindow()
        {
            InitializeComponent();

            AddRecordButton.IsEnabled = false;

            // Create the LocalFeatureService and set MaxRecords property
            _localFeatureService = new LocalFeatureService(@"..\Maps-and-Data\CitiesOverOneMillion.mpk")
            {
                MaxRecords = 100000,
            };

            // Register an event handler for the PropertyChanged Event
            _localFeatureService.PropertyChanged += (s, propertyChangedEventArgs) =>
            {
                // Get the property
                var property = _localFeatureService.GetType().GetProperty(propertyChangedEventArgs.PropertyName);

                // Get the Value
                var value = property.GetValue(_localFeatureService, null);

                if (value == null)
                    return;

                // Get the property type
                string varType = value.GetType().ToString();

                // Display the property info
                switch (varType)
                {
                    case "System.Collections.ObjectModel.ReadOnlyCollection`1[ESRI.ArcGIS.Client.Local.LayerDetails]":
                        statusDisplay.Items.Insert(0, propertyChangedEventArgs.PropertyName + ": " + _localFeatureService.FeatureLayers.Count.ToString());
                        break;
                    default:
                        statusDisplay.Items.Insert(0, propertyChangedEventArgs.PropertyName + ": " + value.ToString());
                        break;
                }

                // Display the error
                if (_localFeatureService.Error != null)
                    statusDisplay.Items.Insert(0, "Error: " + _localFeatureService.Error.Message);
            };

            // Start the LocalFeatureService
            _localFeatureService.StartAsync(x =>
            {
                // Create a new FeatureLayer (to contain the table)
                _featureLayerTable = new FeatureLayer()
                {
                    Url = _localFeatureService.UrlFeatureService + "/1",
                    ID = "EditTable",
                    DisableClientCaching = true,
                    AutoSave = false,
                    //Do not use ESRI.ArcGIS.Client.FeatureLayer.QueryMode.OnDemand
                    Mode = ESRI.ArcGIS.Client.FeatureLayer.QueryMode.Snapshot,
                    OutFields = new OutFields() { "*" },
                };

                /*
                * Register a series of inline event handlers...
                */

                // Register an handler for the InitializationFailed event
                _featureLayerTable.InitializationFailed += (s, e) =>
                {
                    statusDisplay.Items.Insert(0, _featureLayerTable.InitializationFailure.Message);
                };

                // Register a handler for the Initialized event (raised by an explicit Initialize call)
                _featureLayerTable.Initialized += (s, e) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer Initialized Event Raised");
                    statusDisplay.Items.Insert(0, "FeatureLayer contains: " + _featureLayerTable.Graphics.Count.ToString() + " features"); //This will be 0.
                    _featureLayerTable.Update();
                };

                // Register a handler for the UpdateCompleted event (raised by an explicit Update call)
                _featureLayerTable.UpdateCompleted += (senderObj, eventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer UpdateCompleted Event Raised");
                    statusDisplay.Items.Insert(0, "FeatureLayer contains: " + _featureLayerTable.Graphics.Count.ToString() + " features"); //This will be the total number (n) graphic features (up to service query limit).
                    AddRecordButton.IsEnabled = true;
                };

                // Register a handler for the Begin Save Edits event (raised by the explicit Save Edits call)
                _featureLayerTable.BeginSaveEdits += (s1, beginEditEventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer BeginSaveEdits Event Raised");
                };

                // Register a handler for the End Save Edits event (raised by server response)
                _featureLayerTable.EndSaveEdits += (s2, endEditEventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "## Edit Successful ##");
                    // Edit was successful - call Update to trigger a refresh and display the number of features
                    _featureLayerTable.Update();
                };

                // Register a handler for the Save Edits Failed event (raised by server response)
                _featureLayerTable.SaveEditsFailed += (s3, taskFailedEventArgs) =>
                {
                    statusDisplay.Items.Insert(0, "FeatureLayer SaveEditsFailed Event Raised: " + taskFailedEventArgs.Error.Message);
                };

                // Finally... call the Initialize method to kick everything off...
                _featureLayerTable.Initialize();
            });
        }
Exemplo n.º 11
0
        async Task addLocalMapFile(string filePath)
        {
            if (File.Exists(filePath))
            {
                IsBusy = true;

                _localFeatureService = new LocalFeatureService(filePath, _maxRecords);
                await _localFeatureService.StartAsync();

                IsBusy = false;
                ArcGISDynamicMapServiceLayer dynamicServiceLayer =
                    new ArcGISDynamicMapServiceLayer();
                dynamicServiceLayer.ID = "localMap";
                dynamicServiceLayer.DisplayName = "localMap";
                dynamicServiceLayer.ServiceUri = _localFeatureService.UrlMapService;
                _map.Layers.Add(dynamicServiceLayer);

            }
            else
            {
                string error = string.Format(_fileNotExist, filePath);
                MessageBox.Show(error);
            }
        }