private void SetUpZoom() { if (ZoomLevelStack != null) { System.Collections.Generic.List <double> resolutions = new System.Collections.Generic.List <double>(); foreach (Layer layer in Map.Layers) { if (layer is TiledMapServiceLayer) { TiledMapServiceLayer tlayer = layer as TiledMapServiceLayer; if (tlayer.TileInfo == null || tlayer.TileInfo.Lods == null) { continue; } var res = from t in tlayer.TileInfo.Lods select t.Resolution; resolutions.AddRange(res); } } if (resolutions.Count < 1) { return; } resolutions.Sort(); layerResolutions = resolutions.Distinct().Reverse().ToArray(); StackPanel sp = ZoomLevelStack; int min = 0; int max = layerResolutions.Length - 1; int numLevels = max + 1 - min; double levelWidth = (100 / numLevels); for (int i = min; i <= max; i++) { SolidColorBrush brush = setLevelBrush(i); Border levelBorder = new Border() { BorderThickness = new Thickness(0.5), CornerRadius = new CornerRadius(1), Width = levelWidth, Height = 14, BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)), Background = brush, Tag = i }; levelBorder.MouseLeftButtonDown += levelBorder_MouseLeftButtonDown; levelBorder.MouseMove += levelBorder_MouseMove; levelBorder.MouseLeftButtonUp += levelBorder_MouseLeftButtonUp; sp.Children.Add(levelBorder); } sp.MouseLeave += new MouseEventHandler(sp_MouseLeave); zoomSetUp = true; } }
/// <summary> /// Sets up the parameters of the ZoomSlider /// </summary> public void SetupZoom() { System.Collections.Generic.List <double> resolutions = new System.Collections.Generic.List <double>(); foreach (Layer layer in Map.Layers) { if (layer is TiledMapServiceLayer) { TiledMapServiceLayer tlayer = layer as TiledMapServiceLayer; if (tlayer.TileInfo == null || tlayer.TileInfo.Lods == null) { continue; } var res = from t in tlayer.TileInfo.Lods select t.Resolution; resolutions.AddRange(res); } } resolutions.Sort(); layerResolutions = resolutions.Distinct().Reverse().ToArray(); int count = layerResolutions.Length; if (ZoomSlider != null) { if (count > 0) { ZoomSlider.Minimum = 0; ZoomSlider.Maximum = count - 1; Map.MaximumResolution = layerResolutions[0]; Map.MinimumResolution = layerResolutions[count - 1]; double level = getValueFromMap(Map.Extent); if (level >= 0) { ZoomSlider.Value = level; } ZoomSlider.Visibility = Visibility.Visible; _resolutionsDefined = true; } else { ZoomSlider.Visibility = Visibility.Collapsed; } } }
private void switchBaseMapLayer(TiledMapServiceLayer baseMapLayer, Envelope newExtent, List<Layer> oldBasemapLayers) { if (Map == null) return; // 1. Save the operational layers (We assume a single base layer) System.Collections.Generic.Stack<Layer> layers = new System.Collections.Generic.Stack<Layer>(); for (int i = Map.Layers.Count - 1; i >= 0; i--) { Layer l = Map.Layers[i]; if (oldBasemapLayers.Contains(l)) continue; Map.Layers.RemoveAt(i); layers.Push(l); } // 2. Clear the layers collection Map.Layers.Clear(); // 3. Set the extent bool spatialReferenceUnchanged = Map.SpatialReference.Equals(newExtent.SpatialReference); Map.Extent = newExtent; // 4a. Set layer id if this is not set if (string.IsNullOrEmpty(baseMapLayer.ID) || (!string.IsNullOrEmpty(baseMapLayer.ID) && Map.Layers[baseMapLayer.ID] != null)) baseMapLayer.ID = Guid.NewGuid().ToString("N"); // 4. Add the new base map Map.Layers.Add(baseMapLayer); // 5. Re-add the operational layers while (layers.Count > 0) { Layer layer = layers.Pop(); if (!spatialReferenceUnchanged) { //reproject graphics layers that are not feature layers // Feature layers support reprojection if (layer is GraphicsLayer && !(layer is FeatureLayer)) { GraphicsLayer graphicsLayer = layer as GraphicsLayer; if (graphicsLayer.Graphics.Count > 0) { GeometryServiceOperationHelper helper = new GeometryServiceOperationHelper( new ConfigurationStoreHelper().GetGeometryServiceUrl(ConfigurationStore)); helper.ProjectGraphicsCompleted += (o, e) => { GraphicsLayer targetLayer = e.UserState as GraphicsLayer; if (targetLayer != null) { targetLayer.Graphics.Clear(); foreach (Graphic graphic in e.Graphics) targetLayer.Graphics.Add(graphic); } }; helper.ProjectGraphics(graphicsLayer.Graphics, newExtent.SpatialReference, graphicsLayer); } // update the map spatial reference on custom layers ICustomGraphicsLayer customGraphicsLayer = layer as ICustomGraphicsLayer; if (customGraphicsLayer != null) customGraphicsLayer.MapSpatialReference = Map.SpatialReference; else { HeatMapLayerBase heatMapLayer = layer as HeatMapLayerBase; if (heatMapLayer != null) heatMapLayer.MapSpatialReference = Map.SpatialReference; } } else { HeatMapLayerBase heatMapLayer = layer as HeatMapLayerBase; if (heatMapLayer != null && heatMapLayer.HeatMapPoints.Count > 0) { GeometryServiceOperationHelper helper = new GeometryServiceOperationHelper(new ConfigurationStoreHelper().GetGeometryServiceUrl(ConfigurationStore)); helper.ProjectPointsCompleted += (o, e) => { PointCollection points = new PointCollection(); foreach (MapPoint item in e.Points) { if (item != null) points.Add(item); } heatMapLayer.HeatMapPoints = points; heatMapLayer.MapSpatialReference = points[0].SpatialReference; heatMapLayer.Refresh(); }; helper.ProjectPoints(heatMapLayer.HeatMapPoints, newExtent.SpatialReference); } } } Map.Layers.Add(layer); } }