private void cboPlacement_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MyMap == null)
            {
                return;
            }

            ArcGISDynamicMapServiceLayer dynamicLayer =
                MyMap.Layers["PopulationDynamicLayer"] as ArcGISDynamicMapServiceLayer;
            LabelPlacement placment = new LabelPlacement();

            switch (cboPlacement.SelectedIndex)
            {
            case 0:
                placment = LabelPlacement.PointLabelPlacementAboveCenter;
                break;

            case 1:
                placment = LabelPlacement.PointLabelPlacementAboveLeft;
                break;

            case 2:
                placment = LabelPlacement.PointLabelPlacementAboveRight;
                break;

            case 3:
                placment = LabelPlacement.PointLabelPlacementBelowCenter;
                break;

            case 4:
                placment = LabelPlacement.PointLabelPlacementBelowLeft;
                break;

            case 5:
                placment = LabelPlacement.PointLabelPlacementBelowRight;
                break;

            case 6:
                placment = LabelPlacement.PointLabelPlacementCenterCenter;
                break;

            case 7:
                placment = LabelPlacement.PointLabelPlacementCenterLeft;
                break;

            case 8:
                placment = LabelPlacement.PointLabelPlacementCenterRight;
                break;
            }

            foreach (LabelClass lClass in dynamicLayer.LayerDrawingOptions[0].LabelClasses)
            {
                lClass.LabelPlacement = placment;
            }

            dynamicLayer.Refresh();
        }
Exemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            dynamicLayer = (ArcGISDynamicMapServiceLayer)MyMap.Layers[0];

            LabelClassCollection lcc = getLabelClassCollection();

            LayerDrawingOptionsCollection options = new LayerDrawingOptionsCollection();
            options.Add(new LayerDrawingOptions() { LayerID = 0, ShowLabels = true, LabelClasses = lcc });

            dynamicLayer.LayerDrawingOptions = options;

            dynamicLayer.Refresh();
        }
Exemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            dynamicLayer = (ArcGISDynamicMapServiceLayer)MyMap.Layers[0];

            LabelClassCollection lcc = getLabelClassCollection();

            LayerDrawingOptionsCollection options = new LayerDrawingOptionsCollection();

            options.Add(new LayerDrawingOptions()
            {
                LayerID = 0, ShowLabels = true, LabelClasses = lcc
            });

            dynamicLayer.LayerDrawingOptions = options;

            dynamicLayer.Refresh();
        }
        private void RefreshLayer(Layer layer, EventHandler refreshCompletedHander, EventHandler <TaskFailedEventArgs> refreshFailedHandler)
        {
            _isRefreshing = true;
            FeatureLayer featureLayer = layer as FeatureLayer;

            if (featureLayer != null && !string.IsNullOrEmpty(featureLayer.Url))
            {
                // temporarly unhook the AttributeDisplay's layer while we refresh feature layer
                if (View.Instance != null && View.Instance.AttributeDisplay != null && View.Instance.AttributeDisplay.FeatureDataGrid != null)
                {
                    ToggleTableCommand.SetTableVisibility(Visibility.Collapsed);

                    // Set FeatureDataGrid layer to null so that we don't incur the overhead
                    // of all the UpdateItemSource calls as the AttributeTable Graphics layer is
                    // being set to null.
                    View.Instance.AttributeDisplay.FeatureDataGrid.GraphicsLayer = null;
                    // Set the FilterSource to null to prevent potential GraphicsLayer reference exceptions
                    View.Instance.AttributeDisplay.FeatureDataGrid.FilterSource = null;
                    // Now set the AttributeDisplay GraphicsLayer to null so that it
                    // unhooks all the bindings and events
                    View.Instance.AttributeDisplay.GraphicsLayer = null;

                    // Hook up to the UpdateCompleted/UpdateFailed events so that the layer
                    // can be reset to the SelectedLayer
                    featureLayer.UpdateCompleted -= OnFeatureLayerUpdateCompleted;
                    featureLayer.UpdateCompleted += OnFeatureLayerUpdateCompleted;
                    featureLayer.UpdateFailed    -= OnFeatureLayerUpdateFailed;
                    featureLayer.UpdateFailed    += OnFeatureLayerUpdateFailed;
                }

                if (refreshCompletedHander != null)
                {
                    featureLayer.UpdateCompleted -= refreshCompletedHander;
                    featureLayer.UpdateCompleted += refreshCompletedHander;
                }
                if (refreshFailedHandler != null)
                {
                    featureLayer.UpdateFailed -= refreshFailedHandler;
                    featureLayer.UpdateFailed += refreshFailedHandler;
                }
                featureLayer.Update();
                return;
            }

            ArcGISDynamicMapServiceLayer dynamicLayer = layer as ArcGISDynamicMapServiceLayer;

            if (dynamicLayer != null)
            {
                dynamicLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ArcGISTiledMapServiceLayer tiledLayer = layer as ArcGISTiledMapServiceLayer;

            if (tiledLayer != null)
            {
                // Tiled layers do not support refreshing
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ArcGISImageServiceLayer imageServiceLayer = layer as ArcGISImageServiceLayer;

            if (imageServiceLayer != null)
            {
                imageServiceLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            ICustomGraphicsLayer customGraphicsLayer = layer as ICustomGraphicsLayer;

            if (customGraphicsLayer != null)
            {
                customGraphicsLayer.ForceRefresh(refreshCompletedHander, refreshFailedHandler);
                return;
            }


            HeatMapLayerBase heatMapLayer = layer as HeatMapLayerBase;

            if (heatMapLayer != null)
            {
                heatMapLayer.Update();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }

            GeoRssLayer geoRssLayer = Layer as GeoRssLayer;

            if (geoRssLayer != null)
            {
                geoRssLayer.Update();
                return;
            }

            WmsLayer wmsLayer = Layer as WmsLayer;

            if (wmsLayer != null)
            {
                wmsLayer.Refresh();
                return;
            }

            GraphicsLayer graphicsLayer = layer as GraphicsLayer;

            if (graphicsLayer != null)
            {
                graphicsLayer.Refresh();
                if (refreshCompletedHander != null)
                {
                    refreshCompletedHander.Invoke(layer, EventArgs.Empty);
                }
                return;
            }
        }
        public static void SetProxyUrl(Layer layer, string proxyUrl)
        {
            ArcGISDynamicMapServiceLayer dmsLayer = layer as ArcGISDynamicMapServiceLayer;
            string url = null;

            if (dmsLayer != null)
            {
                if (dmsLayer.ProxyURL != proxyUrl)
                {
                    url = dmsLayer.Url;
                    try
                    {
                        dmsLayer.Url = "";
                    }
                    catch { }
                    dmsLayer.ProxyURL = proxyUrl;
                    dmsLayer.Url      = url;
                    dmsLayer.Refresh();
                }
                return;
            }
            ArcGISImageServiceLayer isLayer = layer as ArcGISImageServiceLayer;

            if (isLayer != null)
            {
                if (isLayer.ProxyURL != proxyUrl)
                {
                    url = isLayer.Url;
                    try
                    {
                        isLayer.Url = "";
                    }
                    catch { }
                    isLayer.ProxyURL = proxyUrl;
                    isLayer.Url      = url;
                    isLayer.Refresh();
                }
                return;
            }
            ArcGISTiledMapServiceLayer tmsLayer = layer as ArcGISTiledMapServiceLayer;

            if (tmsLayer != null)
            {
                if (tmsLayer.ProxyURL != proxyUrl)
                {
                    url = tmsLayer.Url;
                    try
                    {
                        tmsLayer.Url = "";
                    }
                    catch { }
                    tmsLayer.ProxyURL = proxyUrl;
                    tmsLayer.Url      = url;
                    tmsLayer.Refresh();
                }
                return;
            }
            FeatureLayer fLayer = layer as FeatureLayer;

            if (fLayer != null)
            {
                if (fLayer.ProxyUrl != proxyUrl)
                {
                    fLayer.ProxyUrl = proxyUrl;
                    fLayer.Update();
                }
                return;
            }
            HeatMapFeatureLayer hmfLayer = layer as HeatMapFeatureLayer;

            if (hmfLayer != null)
            {
                if (hmfLayer.ProxyUrl != proxyUrl)
                {
                    hmfLayer.ProxyUrl = proxyUrl;
                    hmfLayer.Update();
                }
                return;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize Living Maps and Feature Layers
        /// </summary>
        private void InitializeLiveMaps(MapConfig mapConfig)
        {
            if (mapConfig == null || mapConfig.LivingMaps == null)
            {
                return;
            }

            if (mapConfig.LivingMaps != null)
            {
                foreach (LivingMapLayer livingMap in mapConfig.LivingMaps)
                {
                    if (livingMap.ServiceType == ArcGISServiceType.Cached)
                    {
                        CreateArcGISMapLayer(livingMap, livingMap.Opacity);
                    }
                    else if (livingMap.ServiceType == ArcGISServiceType.Dynamic)
                    {
                        ArcGISDynamicMapServiceLayer agisDynamicMap = CreateArcGISMapLayer(livingMap, livingMap.Opacity) as ArcGISDynamicMapServiceLayer;

                        if (livingMap.RefreshRate > 0)
                        {
                            agisDynamicMap.DisableClientCaching = true;
                            DispatcherTimer refreshTimer = new DispatcherTimer()
                            {
                                Interval = TimeSpan.FromSeconds(livingMap.RefreshRate)
                            };
                            refreshTimer.Tick += (o, e) => { agisDynamicMap.Refresh(); };
                            refreshTimer.Start();
                        }
                    }
                    else if (livingMap.ServiceType == ArcGISServiceType.Feature)
                    {
                        FeatureLayer agisFeatureLayer = CreateArcGISMapLayer(livingMap, livingMap.Opacity) as FeatureLayer;

                        if (livingMap.FeatureLayerConfig != null)
                        {
                            agisFeatureLayer.Geometry = (livingMap.FeatureLayerConfig.EnvelopeFilter == null) ? null : (livingMap.FeatureLayerConfig.EnvelopeFilter.ToEnvelope());
                            agisFeatureLayer.Where    = livingMap.FeatureLayerConfig.WhereString;

                            if (livingMap.FeatureLayerConfig.UseCluster)
                            {
                                agisFeatureLayer.Clusterer = new FlareClusterer()
                                {
                                    Radius            = 15,
                                    MaximumFlareCount = 5,
                                    FlareBackground   = this.CurrentApp.Resources[SymbolResources.FLARE_BACKGROUND] as Brush,
                                    FlareForeground   = this.CurrentApp.Resources[SymbolResources.FLARE_FOREGROUND] as Brush,
                                    Gradient          = this.CurrentApp.Resources[SymbolResources.CLUSTER_GRADIENT] as LinearGradientBrush
                                };
                            }

                            if (!string.IsNullOrEmpty(livingMap.FeatureLayerConfig.SymbolImage))
                            {
                                agisFeatureLayer.Renderer = new SimpleRenderer()
                                {
                                    Symbol = new PictureMarkerSymbol()
                                    {
                                        Source = new BitmapImage(new Uri(livingMap.FeatureLayerConfig.SymbolImage, UriKind.Relative))
                                    }
                                };
                            }

                            if (!string.IsNullOrEmpty(livingMap.FeatureLayerConfig.OutFields))
                            {
                                string[] fields = livingMap.FeatureLayerConfig.OutFields.Split(',');
                                foreach (string field in fields)
                                {
                                    agisFeatureLayer.OutFields.Add(field);
                                }
                            }
                        }

                        if (livingMap.RefreshRate > 0)
                        {
                            agisFeatureLayer.DisableClientCaching = true;
                            DispatcherTimer refreshTimer = new DispatcherTimer()
                            {
                                Interval = TimeSpan.FromSeconds(livingMap.RefreshRate)
                            };
                            refreshTimer.Tick += (o, e) => { agisFeatureLayer.Refresh(); };
                            refreshTimer.Start();
                        }
                    }
                }
            }
        }