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); }
public void InsertWithNormalConditions() { // 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); // act layerCollection.Insert(1, layer3); // assert var list = layerCollection.ToList(); Assert.AreEqual(3, list.Count()); Assert.NotNull(list[0]); Assert.AreEqual("Layer1", list[0].Name); Assert.NotNull(list[1]); Assert.AreEqual("Layer3", list[1].Name); Assert.NotNull(list[2]); Assert.AreEqual("Layer2", list[2].Name); }
public void InsertLayer(ILayer layer, int index) { Layers.Insert(index, layer); layerCollection.Insert(index + 1, layer); OnLayersChanged(EventArgs.Empty); }
public void AddLayer(ILayer layer, bool init = true) { if (init) { Layers.Add(layer); layerCollection.Add(layer); } else { // todo: refactor code, remove hardcoded ints // 3 is number of standard layers (hexagons, land, alerts) // layers determinines the order in the TOC if (Layers.Count == 1) { Layers.Add(layer); } else { Layers.Insert(1, layer); } // layercollection is the order in drawing, draw always above the baselayers layerCollection.Insert(2, layer); } OnLayersChanged(EventArgs.Empty); }
/// <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; } }
public void PromoteLayer(LayerCollection owningCollection, int position) { // Skip if the layer can't be moved up because it is already at the top. if (position < 1) { return; } // Move the layer by removing it from its current position and adding it at the next lower position. Layer selectedLayer = owningCollection[position]; owningCollection.RemoveAt(position); owningCollection.Insert(position - 1, selectedLayer); }
public void DemoteLayer(LayerCollection owningCollection, int position) { // Skip if the layer can't be moved because its already at the bottom. if (position == owningCollection.Count - 1) { return; } // Move the layer by removing it from its current position and inserting it at the next higher position. Layer selectedLayer = owningCollection[position]; owningCollection.RemoveAt(position); owningCollection.Insert(position + 1, selectedLayer); }
public override void MoveRow(UITableView tableView, NSIndexPath sourceIndexPath, NSIndexPath destinationIndexPath) { // Find the source and destination lists (based on the section of the source and destination index). LayerCollection source = sourceIndexPath.Section == 0 ? IncludedLayers : ExcludedLayers; LayerCollection destination = destinationIndexPath.Section == 0 ? IncludedLayers : ExcludedLayers; // Find the layer that is being moved. Layer movedLayer = source[sourceIndexPath.Row]; // Remove the layer from the source list and insert into the destination list. source.RemoveAt(sourceIndexPath.Row); destination.Insert(destinationIndexPath.Row, movedLayer); // Reload the table now that the data has changed. tableView.ReloadData(); }
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); }
private void ListBoxItem_OnDrop(object sender, DragEventArgs e) { // This method is called when the user finishes dragging while over the listbox. // Find the source and destination list boxes. ListBox sourceBox = FindParentListBox(_originatingListBoxItem); if (sourceBox == null) { // Return if the source isn't valid - happens when duplicate events are raised. return; } // Find the list box that the item was dropped on (i.e. dragged to). ListBox destinationBox = FindParentListBox((UIElement)sender); // Get the data that is being dropped. Layer draggedData = (Layer)e.Data.GetData(typeof(ArcGISMapImageLayer)); // Find where in the respective lists the items are. int indexOfRemoved = sourceBox.Items.IndexOf(draggedData); int indexOfInsertion; // Sender is the control that the item is being dropped on. Could be a listbox or a listbox item. if (sender is ListBoxItem) { // Find the layer that the item represents. Layer targetData = ((ListBoxItem)sender).DataContext as Layer; // Find the position of the layer in the listbox. indexOfInsertion = destinationBox.Items.IndexOf(targetData); } else if (destinationBox != sourceBox) { // Drop the item at the end of the list if the user let go of the item on the empty space in the box rather than the list item. // This works because both the listbox and its individual listbox items participate in drag and drop. indexOfInsertion = destinationBox.Items.Count - 1; } else { return; } // Find the appropriate source and destination boxes. LayerCollection sourceList = sourceBox == IncludedListBox ? _viewModel.IncludedLayers : _viewModel.ExcludedLayers; LayerCollection destinationList = destinationBox == IncludedListBox ? _viewModel.IncludedLayers : _viewModel.ExcludedLayers; // Return if there is nothing to do. if (sourceList == destinationList && indexOfRemoved == indexOfInsertion) { return; } if (sourceBox == destinationBox && indexOfRemoved < indexOfInsertion) { indexOfInsertion -= 1; } // Perform the move. sourceList.RemoveAt(indexOfRemoved); destinationList.Insert(indexOfInsertion + 1, draggedData); }
public static LayerCollection InsertLayer(this LayerCollection self, int index, ILayer layer) { self.Insert(index, layer); return(self); }