// Initializes the available layers based on the parent service and clears the selected layers
        private void initializeLayers()
        {
            AvailableLayers.Clear();
            SelectedLayers.Clear();

            // Make sure the service is a type that contains sublayers
            if (!(Service is FeatureService) && !(Service is MapService))
            {
                return; // Other service types don't have sublayers
            }
            // Loop through each sublayer in the service
            dynamic serviceAsDynamic = Service;

            foreach (FeatureLayerDescription layer in serviceAsDynamic.Layers)
            {
                // Create a feature layer for the sublayer
                string       id     = Guid.NewGuid().ToString("N");
                FeatureLayer fLayer = new FeatureLayer()
                {
                    Url       = string.Format("{0}/{1}", Service.Url, layer.Id),
                    OutFields = new OutFields()
                    {
                        "*"
                    },
                    ProxyUrl = ProxyUrl,
                    ID       = id
                };

                // Initialize the layer's name
                string name = !string.IsNullOrEmpty(layer.Name) ? layer.Name : id;
                MapApplication.SetLayerName(fLayer, name);

                // Add the layer to the set of available layers
                AvailableLayers.Add(fLayer);
            }
        }
Esempio n. 2
0
        private void Connect()
        {
            if (Uri.IsWellFormedUriString(WmsServerUrl, UriKind.Absolute))
            {
                if (WmsRasterLayer == null)
                {
                    InitializeWmsRasterLayer();
                }

                IsBusy = true;
                Task.Factory.StartNew(new Action(() =>
                {
                    Collection <string> styleNames       = new Collection <string>();
                    Collection <string> outputFormats    = new Collection <string>();
                    Collection <string> serverLayerNames = new Collection <string>();

                    try
                    {
                        if (!string.IsNullOrEmpty(UserName) && !string.IsNullOrEmpty(Password))
                        {
                            WmsRasterLayer.Credentials = new NetworkCredential(UserName, Password);
                        }
                        if (!WmsRasterLayer.IsOpen)
                        {
                            WmsRasterLayer.Open();
                        }
                        styleNames       = WmsRasterLayer.GetServerStyleNames();
                        outputFormats    = WmsRasterLayer.GetServerOutputFormats();
                        serverLayerNames = WmsRasterLayer.GetServerLayerNames();
                    }
                    catch (Exception ex)
                    {
                        GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            SendMessageBox(ex.Message, "Warning");
                        }));
                    }
                    finally
                    {
                        var action = new Action(() =>
                        {
                            foreach (var item in styleNames)
                            {
                                styles.Add(item);
                            }
                            foreach (var item in outputFormats)
                            {
                                formats.Add(item);
                            }
                            if (serverLayerNames.Count() > 0)
                            {
                                AvailableLayers.Clear();
                                foreach (var serverLayer in serverLayerNames)
                                {
                                    if (!string.IsNullOrEmpty(serverLayer))
                                    {
                                        AvailableLayers.Add(new WmsLayerViewModel(serverLayer));
                                    }
                                }
                            }
                            IsBusy = false;
                        });
                        if (Application.Current != null)
                        {
                            Application.Current.Dispatcher.BeginInvoke(action);
                        }
                        else
                        {
                            action();
                        }
                    }
                }));
            }
            else
            {
                SendMessageBox("The server address is not valid.", "Info");
            }
        }