Size s = new Size(pixelWidth, pixelHeight); Canvas croot = new Canvas(); croot.Height = pixelHeight; croot.Width = pixelWidth; ESRI.ArcGIS.Client.Map map = new Map(); map.Progress += new EventHandler<ProgressEventArgs>(map_Progress); map.Height = pixelHeight; map.Width = pixelWidth; map.Layers = ClonedGraphicsLayerCollection; map.Extent = e.RequiredImageInformation.RequiredExtent.Extent; map.Measure(s); map.OnApplyTemplate(); map.UpdateLayout(); croot.Children.Add(map); croot.UpdateLayout(); croot.Measure(s); croot.OnApplyTemplate(); croot.UpdateLayout();
public GraphicsLayer CreateGraphicsLayer() { GraphicsLayer graphicsLayer = new GraphicsLayer(); foreach (Graphic g in MapGraphics) { graphicsLayer.Graphics.Add(g); } //graphicsLayer.Graphics = MapGraphics as GraphicCollection; return graphicsLayer; }
private void btnPrint_Click(object sender, RoutedEventArgs e) { //Initialize the view model for the map print. MapPrintViewViewModel viewModel = new MapPrintViewViewModel(); //Get the current base map. ArcGISTiledMapServiceLayer layer = MyMap.Layers[0] as ArcGISTiledMapServiceLayer; viewModel.BaseMapURL = layer.Url; //Get the current map extent. viewModel.CurrentExtent = MyMap.Extent; //Get a collection of visible dynamic layers. foreach (Layer dLayer in MyMap.Layers) { try { if (dLayer is ArcGISDynamicMapServiceLayer) { ArcGISDynamicMapServiceLayer dynamicLayer = dLayer as ArcGISDynamicMapServiceLayer; //If the dynamic layer is currently visible, add it to the print map. //if (dynamicLayer.VisibleLayers != null) if (dynamicLayer.VisibleLayers.Count() > 0) { //dynamicLayers.Add(dynamicLayer); viewModel.VisibleLayers.Add(new MapPrintViewViewModel.DynamicMapLayerInformation(dynamicLayer.MapName, dynamicLayer.Url, dynamicLayer.Opacity, dynamicLayer.VisibleLayers)); } } } catch { } try { if (dLayer is GraphicsLayer) { GraphicsLayer graphicsLayer = dLayer as GraphicsLayer; //viewModel.MapGraphics = graphicsLayer.Graphics; foreach (Graphic g in graphicsLayer.Graphics) { Graphic clonedGraphic = new Graphic(); clonedGraphic.Geometry = ((ESRI.ArcGIS.Client.Geometry.Polygon)g.Geometry).Clone(); foreach (KeyValuePair<string, object> o in g.Attributes) { clonedGraphic.Attributes.Add(o.Key, o.Value); } clonedGraphic.Symbol = g.Symbol; viewModel.MapGraphics.Add(clonedGraphic); } } } catch { } } MapPrintView printView = new MapPrintView(); printView.DataContext = viewModel; printView.BuildMap(); //If there are layers to build a legend for, build the legend. if (viewModel.VisibleLayers != null && viewModel.VisibleLayers.Count > 0) { printView.CreateLegend(); } printView.Show(); }
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.