示例#1
0
        public void RemoveByLayerType <T>() where T : ILayer
        {
            this.Layers.RemoveAll(l => l is T && l.LayerName != Current.Instance.Earthwatcher.PlayingRegion + Constants.RegionLawLayerName);

            var currentLayers = layerCollection.Where(l => l is T && !(l is BaseTileLayer) || (l.LayerName.EndsWith(Constants.RegionLawLayerName))).ToList();

            foreach (var layer in currentLayers)
            {
                layerCollection.Remove(layer);
                Current.Instance.LayerHelper.LayerCollection.Remove(layer);
            }
        }
        /// <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]);
        }
示例#3
0
        public void InsertAfterRemoving()
        {
            // arrange
            var layerCollection = new LayerCollection();
            var layer1          = new MemoryLayer()
            {
                Name = "Layer1"
            };
            var layer2 = new MemoryLayer()
            {
                Name = "Layer2"
            };
            var layer3 = new MemoryLayer()
            {
                Name = "Layer3"
            };

            layerCollection.Add(layer1);
            layerCollection.Add(layer2);

            layerCollection.Remove(layer1);

            // act
            layerCollection.Insert(1, layer3);

            // assert
            var list = layerCollection.ToList();

            Assert.AreEqual(2, list.Count());
            Assert.NotNull(list[0]);
            Assert.AreEqual("Layer2", list[0].Name);
            Assert.NotNull(list[1]);
            Assert.AreEqual("Layer3", list[1].Name);
        }
示例#4
0
        public void CopyToAfterRemovingItem()
        {
            // arrange
            var layerCollection = new LayerCollection();
            var layer1          = new MemoryLayer();
            var layer2          = new MemoryLayer();

            layerCollection.Add(layer1);
            layerCollection.Add(layer2);

            var size  = layerCollection.Count();
            var array = new ILayer[size];

            layerCollection.Remove(layer1);

            // act
            layerCollection.CopyTo(array, 0);

            // assert
            Assert.AreEqual(2, array.Length);
            Assert.NotNull(array[0], "first element not null");
            // We have no crash but the seconds element is null.
            // This might have unpleasant consequences.
            Assert.Null(array[1], "second element IS null");
        }
示例#5
0
        private void Delete_Layer_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection <DxfLayerExtended> layers = new ObservableCollection <DxfLayerExtended>(LayerList.SelectedItems.OfType <DxfLayerExtended>());

            int index = LayerList.SelectedIndex;

            for (int i = 0; i < layers.Count; i++)
            {
                DxfLayerExtended layer = layers[i];

                if (layer.Name != "0")
                {
                    LayerList.SelectedItems.Remove(layer);
                    LayerCollection.Remove(layer);
                }
                else
                {
                    MessageBox.Show("Cannot Delete Default Layer \"0\"", "Warning");
                }
            }

            if (LayerList.Items.Count > index)
            {
                LayerList.SelectedIndex = index;
            }
            else
            {
                LayerList.SelectedIndex = LayerList.Items.Count - 1;
            }
        }
示例#6
0
 /// <summary>
 /// Removes a layer from the map.
 /// </summary>
 /// <param name="layer">The layer to remove.</param>
 public void RemoveLayer(ILayer layer)
 {
     if (layer != null)
     {
         lock (Layers.LayersChangeSync)
         {
             _layers.Remove(layer);
         }
     }
 }
示例#7
0
        public void RemoveLayer(string name)
        {
            var layers = layerCollection.FindLayer(name).ToList();

            for (int i = 0; i < layers.Count(); i++)
            {
                layerCollection.Remove(layers[i]);
                Layers.Remove(layers[i]);
            }

            OnLayersChanged(EventArgs.Empty);
        }
示例#8
0
        private void UpdatePinLayer(Mapsui.Geometries.Point currentNodePoint)
        {
            LayerCollection layers = MyMapControl.Map.Layers;

            if (layers.Count > 1)
            {
                layers.Remove(pinLayer);
            }

            pinLayer = WalkerPin.CreateWalkerLayer(currentNodePoint);
            layers.Add(pinLayer);
        }
示例#9
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);
        }
示例#10
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);
                });
            }
        }