예제 #1
0
        /// <summary>
        /// Removes all xMapServer base layers.
        /// </summary>
        /// <param name="layers"> The LayerCollection instance. </param>
        public static void RemoveXMapBaseLayers(this LayerCollection layers)
        {
            var idx = layers.IndexOf(layers[BackgroundLayerName]);

            BaseLayerSuccessor = layers.Count > idx + 1 ? layers[idx + 1].Name : null;

            idx = layers.IndexOf(layers[LabelsLayerName]);
            LabelLayerPredecessor = idx > 0 ? layers[idx - 1].Name : null;

            layers.Remove(layers[BackgroundLayerName]);
            layers.Remove(layers[LabelsLayerName]);
        }
        public static bool HasNonBasemapLayerBeforeAfterIndex(Layer layer, LayerCollection collection, bool before)
        {
            if (layer == null || collection == null)
                return false;

            int index = collection.IndexOf(layer);
            if (index < 0) //layer not found
                return false;

            if (before)
            {
                for(int i = index - 1; i >= 0; i--)
                {
                    if (!(bool)collection[i].GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty))
                        return true;
                }
            }
            else
            {
                if (index < collection.Count - 1)
                {
                    for (int i = index + 1; i < collection.Count; i++)
                    {
                        if (!(bool)collection[i].GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty))
                            return true;
                    }
                }

            }
            return false;
        }
예제 #3
0
        /// <summary>
        /// Inserts the xMapServer base layers, i.e. the background layers for areas like forests, rivers, population areas, et al,
        /// and their corresponding labels.
        /// </summary>
        /// <param name="layers">The LayerCollection instance, used as an extension. </param>
        /// <param name="meta">Meta information for xMapServer, further details can be seen in the <see cref="XMapMetaInfo"/> description. </param>
        public static void InsertXMapBaseLayers(this LayerCollection layers, XMapMetaInfo meta)
        {
            var baseLayer = new TiledLayer(BackgroundLayerName)
            {
                TiledProvider  = new XMapTiledProvider(meta.Url, meta.User, meta.Password, XMapMode.Background),
                Copyright      = meta.CopyrightText,
                Caption        = MapLocalizer.GetString(MapStringId.Background),
                IsBaseMapLayer = true,
                Icon           = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Background.png")
            };

            if (BaseLayerSuccessor != null && layers[BaseLayerSuccessor] != null)
            {
                layers.Insert(layers.IndexOf(layers[BaseLayerSuccessor]), baseLayer);
            }
            else
            {
                // add tile layer
                layers.Add(baseLayer);
                BaseLayerSuccessor = null;
            }

            // don't add overlay layer for Decarta-powered maps (basemap is completely rendered on tiles)
            if (XServerUrl.IsDecartaBackend(meta.Url))
            {
                return;
            }

            var labelLayer = new UntiledLayer(LabelsLayerName)
            {
                UntiledProvider = new XMapTiledProvider(meta.Url, meta.User, meta.Password, XMapMode.Town),
                MaxRequestSize  = meta.MaxRequestSize,
                Caption         = MapLocalizer.GetString(MapStringId.Labels),
                Icon            = ResourceHelper.LoadBitmapFromResource("Ptv.XServer.Controls.Map;component/Resources/Labels.png")
            };

            if (LabelLayerPredecessor != null && layers[LabelLayerPredecessor] != null && layers.IndexOf(layers[LabelLayerPredecessor]) < layers.Count)
            {
                layers.Insert(layers.IndexOf(layers[LabelLayerPredecessor]) + 1, labelLayer);
            }
            else
            {
                // add label layer
                layers.Add(labelLayer);
                LabelLayerPredecessor = null;
            }
        }
예제 #4
0
        public void PromoteLayer(Layer selectedLayer)
        {
            // Find the collection the layer is in.
            LayerCollection owningCollection = IncludedLayers.Contains(selectedLayer) ? IncludedLayers : ExcludedLayers;

            // Get the current index (position) of the layer.
            int layerIndex = owningCollection.IndexOf(selectedLayer);

            // Skip if the layer can't be moved because it is already at the top.
            if (layerIndex < 1)
            {
                return;
            }

            // Move the layer by removing it and re-adding it at its old position minus 1.
            owningCollection.Remove(selectedLayer);
            owningCollection.Insert(layerIndex - 1, selectedLayer);
        }
        public static bool HasNonBasemapLayerBeforeAfterIndex(Layer layer, LayerCollection collection, bool before)
        {
            if (layer == null || collection == null)
            {
                return(false);
            }

            int index = collection.IndexOf(layer);

            if (index < 0) //layer not found
            {
                return(false);
            }

            if (before)
            {
                for (int i = index - 1; i >= 0; i--)
                {
                    if (!(bool)collection[i].GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                if (index < collection.Count - 1)
                {
                    for (int i = index + 1; i < collection.Count; i++)
                    {
                        if (!(bool)collection[i].GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
예제 #6
0
        // when layers are added/removed
        private void Layers_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            LayerCollection layers = (LayerCollection)sender;

            // Put updating of measurable layers in a throttle timer, meaning that this logic will
            // only be invoked once if the CollectionChanged event fires multiple times within two
            // tenths of a second.  This is necessary because changing to a basemap in a different
            // spatial reference results in clearing and rebuilding the layers collection.
            if (_updateMeasurableLayersThrottler == null)
            {
                _updateMeasurableLayersThrottler = new ThrottleTimer(20, () =>
                {
                    // Check whether all layers are initialized
                    if (layers.Any(l => !l.IsInitialized))
                    {
                        layers.LayersInitialized += Layers_LayersInitialized; // Wait for initialization
                    }
                    else
                    {
                        UpdateMeasurableLayers(); // Update measurable layers collection now
                    }
                });
            }
            _updateMeasurableLayersThrottler.Invoke();

            // Check whether layers were added
            if (e.NewItems != null)
            {
                // Hook into visibility changed events for added layers
                foreach (Layer layer in e.NewItems)
                {
                    layer.PropertyChanged += Layer_PropertyChanged;

                    if (layer is ArcGISDynamicMapServiceLayer)
                    {
                        ISublayerVisibilitySupport subLayerSupport = layer as ISublayerVisibilitySupport;
                        subLayerSupport.VisibilityChanged += SubLayerSupport_VisibilityChanged;
                    }
                }
            }

            // Check whether layers were removed
            if (e.OldItems != null)
            {
                // Unhook from visibility changed events for removed layers
                foreach (Layer layer in e.OldItems)
                {
                    layer.PropertyChanged -= Layer_PropertyChanged;

                    if (layer is ArcGISDynamicMapServiceLayer)
                    {
                        ISublayerVisibilitySupport subLayerSupport = layer as ISublayerVisibilitySupport;
                        subLayerSupport.VisibilityChanged -= SubLayerSupport_VisibilityChanged;
                    }
                }
            }

            // If draw layer has been added to the map, check whether it is the top-most
            if (layers.Contains(DrawLayer) && layers.IndexOf(DrawLayer) != layers.Count - 1)
            {
                // Draw layer is not top-most.  Move it to the top by removing and re-adding it.  Wrap in
                // a begin invoke call so the collection is modified outside the CollectionChanged event.
                Map.Dispatcher.BeginInvoke(() =>
                {
                    layers.Remove(DrawLayer);
                    layers.Add(DrawLayer);
                });
            }
        }