private void MapView_Loaded(object sender, RoutedEventArgs e) { var layer = new ComponentLayer(); MyMapView.Map.Layers.Add(layer); MyMapView.MaxScale = 0.001; var centerOfWorld = new MapPoint(-11692090.5488882, 4956767.39181376); CreateLine(new[] { centerOfWorld + new Vector(0, 0), centerOfWorld + new Vector(20, 0) }, layer, "20"); CreateLine(new[] { centerOfWorld + new Vector(20, 0), centerOfWorld + new Vector(40, 0) }, layer, "20"); CreateLine(new[] { centerOfWorld + new Vector(40, 0), centerOfWorld + new Vector(60, 0) }, layer, "20"); MapPoint offCenterOfWorld = centerOfWorld.MoveTo(centerOfWorld.X, centerOfWorld.Y - 25); CreateLine(new[] { offCenterOfWorld + new Vector(0, 0), offCenterOfWorld + new Vector(20, 0) }, layer, "20"); CreateLine(new[] { offCenterOfWorld + new Vector(20, 0), offCenterOfWorld + new Vector(40, 0) }, layer, "40"); CreateLine(new[] { offCenterOfWorld + new Vector(40, 0), offCenterOfWorld + new Vector(60, 0) }, layer, "60"); MapPoint offCenterOfWorld2 = centerOfWorld.MoveTo(centerOfWorld.X, centerOfWorld.Y - 50); CreateLine(new[] { offCenterOfWorld2 + new Vector(0, 0), offCenterOfWorld2 + new Vector(20, 0) }, layer, "20"); CreateLine(new[] { offCenterOfWorld2 + new Vector(21, 0), offCenterOfWorld2 + new Vector(41, 0) }, layer, "20"); CreateLine(new[] { offCenterOfWorld2 + new Vector(42, 0), offCenterOfWorld2 + new Vector(62, 0) }, layer, "20"); MyMapView.SetView(new Envelope(centerOfWorld, offCenterOfWorld2 + new Vector(60, 0)).Expand(1.4)); }
/* * private static int m_LayerCount = 0; * private void MyMapView_PropertyChanged(object sender, PropertyChangedEventArgs e) * { * DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(MapView.MapProperty, typeof(MapView)); * if (dpd != null) * { * int count = this.MyMapView.Map.Layers.Count; * if (count>m_LayerCount) * { * m_LayerCount = count; * BindTreeViewDataContent(m_LayerCount); * } * * } * } * * private async void BindTreeViewDataContent(int i) * { * IList<TreeModel> list = new List<TreeModel>(); * for (int j = 0; j < m_LayerCount; j++) { * TreeModel tree1 = new TreeModel(); * tree1.Id = this.MyMapView.Map.Layers[j].ID; * tree1.Name = this.MyMapView.Map.Layers[j ].DisplayName; * list.Add(tree1); * } * MyTreeView.ItemsSourceData = list; * } */ #endregion /// <summary> /// 缩放至图层 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void menuZoomIn_Click(object sender, RoutedEventArgs e) { if (LayersListView.SelectedItem != null) { string id = (LayersListView.SelectedItem as Layer).ID.ToString(); MyMapView.SetView(MyMapView.Map.Layers[id].FullExtent); } }
private void LayrCB_MouseDoubleClick(object sender, MouseButtonEventArgs e) { System.Windows.Controls.CheckBox chkBox = sender as System.Windows.Controls.CheckBox; // Double click => Zoom to the layer GdbLayer gdbLayer = chkBox.Tag as GdbLayer; MyMapView.SetView(gdbLayer.Extent); }
private async void MapsCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { EngineeringMap emap = MapsCB.SelectedItem as EngineeringMap; if (emap == null) { return; } List <LayerDef> lyrsDef = emap.LocalGdbLayersDef; LayerDef lyrDef = lyrsDef.Find(x => x.Name == _lyrName); if (lyrDef == null) { return; } // load tiled layer // string file = _prjDef.LocalTilePath + "\\" + emap.LocalTileFileName1; if (File.Exists(file)) { ArcGISLocalTiledLayer newLayr = new ArcGISLocalTiledLayer(file); newLayr.ID = "TiledLayer1"; newLayr.DisplayName = "TileLayer1"; Map.Layers.Add(newLayr); //if (newLayr.FullExtent != null) //{ // MyMapView.SetView(newLayr.FullExtent); //} } // load the specified layer // file = _prjDef.LocalFilePath + "\\" + emap.LocalGeoDbFileName; if (File.Exists(file)) { // Open geodatabase Geodatabase gdb = await Geodatabase.OpenAsync(file); IEnumerable <GeodatabaseFeatureTable> featureTables = gdb.FeatureTables; foreach (var table in featureTables) { if (table.Name == _lyrName) { // Add the feature layer to the map await GdbHelper.addGeodatabaseLayer(Map, lyrDef, table); MyMapView.SetView(table.Extent); break; } } } }
private void ZoomToCell(S57Cell currentCell) { if (currentCell == null) { return; } if (currentCell.Extent != null) { MyMapView.SetView(currentCell.Extent); } }
// Highlight the selected grid view item on the map private void resultsGrid_SelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e) { _graphicsOverlay.Graphics.Clear(); if (e.AddedItems != null && e.AddedItems.Count > 0) { var findItem = e.AddedItems.OfType <FindItem>().FirstOrDefault(); if (findItem != null) { _graphicsOverlay.Graphics.Add(new Graphic(findItem.Feature.Geometry, ChooseGraphicSymbol(findItem.Feature.Geometry))); MyMapView.SetView(findItem.Feature.Geometry); } } }
/// <summary> /// 缩放至全图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FullExtentBtn_OnClick(object sender, RoutedEventArgs e) { try { MyMapView.Editor.Cancel.Execute(null); } catch (Exception) { } this.MyMapView.Cursor = Cursors.Arrow; if (MyMapView.Map.Layers.Count < 0) { return; } MyMapView.SetView(MyMapView.Map.Layers[0].FullExtent); }
/// <summary> /// 添加数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void AddLayerDataBtn_OnClick(object sender, RoutedEventArgs e) { try { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Shapefiles|*.shp|Image files|*.bmp;*.png;*.sid;*.tif"; openFileDialog.RestoreDirectory = true; openFileDialog.Multiselect = false; openFileDialog.Title = "文件选取"; if (openFileDialog.ShowDialog() == true) { string item = openFileDialog.SafeFileNames[0].Split('.')[1]; WorkspaceFactoryType type = WorkspaceFactoryType.Raster; switch (item) { case "shp": type = WorkspaceFactoryType.Shapefile; break; case "bmp": case "png": case "sid": case "tif": type = WorkspaceFactoryType.Raster; break; } var dynLayer = await MapHandler.AddFileDatasetToDynamicMapServiceLayer(type, System.IO.Path.GetDirectoryName(openFileDialog.FileName), new List <string>(openFileDialog.SafeFileNames), this.MyMapView.Map.Layers.Count); // Add the dynamic map service layer to the map if (dynLayer != null) { dynLayer.DisplayName = dynLayer.DynamicLayerInfos[0].Name; MyMapView.Map.Layers.Add(dynLayer); MyMapView.SetView(dynLayer.FullExtent.Extent.Expand(0.5)); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); } }
private async void QueryComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { progress.Visibility = Visibility.Visible; results.Visibility = Visibility.Collapsed; resultsGrid.ItemsSource = null; _graphicsOverlay.Graphics.Clear(); QueryTask queryTask = new QueryTask( new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5")); var stateName = (string)(QueryComboBox.SelectedItem as Graphic).Attributes["STATE_NAME"]; Query query = new Query(string.Format("STATE_NAME = '{0}'", stateName)) { OutFields = OutFields.All, ReturnGeometry = true, OutSpatialReference = MyMapView.SpatialReference }; var result = await queryTask.ExecuteAsync(query); var featureSet = result.FeatureSet; if (featureSet != null && featureSet.Features.Count > 0) { var graphic = featureSet.Features.First() as Graphic; _graphicsOverlay.Graphics.Add(graphic); var selectedFeatureExtent = graphic.Geometry.Extent; Envelope displayExtent = selectedFeatureExtent.Expand(1.3); MyMapView.SetView(displayExtent); resultsGrid.ItemsSource = graphic.Attributes .Select(attr => new Tuple <string, string>(attr.Key, attr.Value.ToString())); results.Visibility = Visibility.Visible; } } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } finally { progress.Visibility = Visibility.Collapsed; } }
private async Task GetAttributes() { QueryTask queryTask = new QueryTask(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5")); var qryText = (string)(QueryComboBox.SelectedItem as Graphic).Attributes["STATE_NAME"]; Query query = new Query(qryText) { OutFields = OutFields.All, ReturnGeometry = true, OutSpatialReference = MyMapView.SpatialReference }; try { ResultsGrid.ItemsSource = null; progress.IsActive = true; var result = await queryTask.ExecuteAsync(query); var featureSet = result.FeatureSet; // If an item has been selected GraphicsLayer graphicsLayer = MyMapView.Map.Layers["MyGraphicsLayer"] as GraphicsLayer; graphicsLayer.Graphics.Clear(); if (featureSet != null && featureSet.Features.Count > 0) { var symbol = LayoutRoot.Resources["DefaultFillSymbol"] as Esri.ArcGISRuntime.Symbology.Symbol; var g = featureSet.Features[0]; graphicsLayer.Graphics.Add(g as Graphic); var selectedFeatureExtent = g.Geometry.Extent; Envelope displayExtent = selectedFeatureExtent.Expand(1.3); MyMapView.SetView(displayExtent); ResultsGrid.ItemsSource = g.Attributes; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { progress.IsActive = false; } }
async void MyMapView_ExtentChanged(object sender, EventArgs e) { Envelope init_extent = new Envelope(double.Parse(_view.eMap.XMin.ToString()), double.Parse(_view.eMap.YMin.ToString()), double.Parse(_view.eMap.XMax.ToString()), double.Parse(_view.eMap.YMax.ToString())); if (MyMapView.Extent.YMax > Convert.ToDouble(_view.eMap.YMax) + 100) { MyMapView.SetView(init_extent); return; } if (MyMapView.Extent.XMax > Convert.ToDouble(_view.eMap.XMax) + 50) { MyMapView.SetView(init_extent); return; } if (MyMapView.Extent.XMin < Convert.ToDouble(_view.eMap.XMin) - 50) { MyMapView.SetView(init_extent); return; } if (MyMapView.Extent.YMin < Convert.ToDouble(_view.eMap.YMin) - 100) { MyMapView.SetView(init_extent); return; } //标尺 rulerextent _initrulerx = new rulerextent() { XMax = MyMapView.Extent.XMax, XMin = MyMapView.Extent.XMin }; hruler.RulerExtent = _initrulerx; xjruler.RulerExtent = _initrulerx; mili_ruler.RulerExtent = _initrulerx; rulerextent _initrulery = new rulerextent() { XMax = MyMapView.Extent.YMax, XMin = MyMapView.Extent.YMin }; vruler.RulerExtent = _initrulery; }
void LoadTiledLayer1(EngineeringMap emap) { ArcGISLocalTiledLayer tileLayr1 = Map.Layers["TiledLayer1"] as ArcGISLocalTiledLayer; if (tileLayr1 != null) { Map.Layers.Remove(tileLayr1); } string file = ProjDef.LocalTilePath + "\\" + emap.LocalTileFileName1; if (File.Exists(file)) { ArcGISLocalTiledLayer newLayr = new ArcGISLocalTiledLayer(file); newLayr.ID = "TiledLayer1"; newLayr.DisplayName = "TileLayer1"; Map.Layers.Add(newLayr); MyMapView.SetView(newLayr.FullExtent); } }
private void ZoomToExtent() { Envelope extent = null; foreach (Graphic g in _addressOverlay.Graphics) { Envelope tempEnv = GetDisplayExtent(g.Geometry as MapPoint, MyMapView.ActualHeight, MyMapView.ActualWidth); if (extent == null) { extent = tempEnv; } else { extent = extent.Union(GetDisplayExtent(g.Geometry as MapPoint, MyMapView.ActualHeight, MyMapView.ActualWidth)); } } if (extent != null) { MyMapView.SetView(extent); } }
private void LocationButton_Checked(object sender, RoutedEventArgs e) { _myLocationOverlay.Graphics.Clear(); var point = MyMapView.LocationDisplay.CurrentLocation.Location; var buffer = GeometryEngine.GeodesicBuffer(point, 300, LinearUnits.Meters); MyMapView.SetView(buffer.Extent); var symbol = new PictureMarkerSymbol() { Width = 48, Height = 48, YOffset = 24 }; symbol.SetSourceAsync(new Uri("ms-appx:///Assets/CollPin.png")); var graphic = new Graphic() { Geometry = point, Symbol = symbol }; _myLocationOverlay.Graphics.Add(graphic); }
private void btnResetMap_Click(object sender, RoutedEventArgs e) { try { var localTiledLayer = MyMapView.Map.Layers.FirstOrDefault(lyr => lyr.ID == LOCAL_LAYER_ID); if (localTiledLayer != null) { MyMapView.Map.Layers.Remove(localTiledLayer); } var extentWGS84 = new Envelope(-123.77, 36.80, -119.77, 38.42, SpatialReferences.Wgs84); MyMapView.SetView(extentWGS84); } catch (Exception ex) { var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync(); } finally { _aoiOverlay.IsVisible = false; _onlineTiledLayer.IsVisible = true; } }
/// <summary>Reset the MapView by removing any map rotation and centering on the existing Location. </summary> private void resetDisplay_Click(object sender, RoutedEventArgs e) { // If the LocationDisplay is enabled and a Location currently exists, reset the map // to zero rotation and center on the Location. Otherwise, set the MapView to center on 0,0. if (MyMapView.LocationDisplay != null && MyMapView.LocationDisplay.IsEnabled && MyMapView.LocationDisplay.CurrentLocation.Location.Extent != null) { // Get the current AutoPanMode setting as it is automatically disabled when calling MyMapView.SetView(). var PanMode = MyMapView.LocationDisplay.AutoPanMode; MyMapView.SetRotation(0); MyMapView.SetView(MyMapView.LocationDisplay.CurrentLocation.Location); // Reset the AutoPanMode MyMapView.LocationDisplay.AutoPanMode = PanMode; } else { var centerPoint = new MapPoint(0, 0); MyMapView.SetView(centerPoint); } }
private void MyMapView_OnLayerLoaded(object sender, LayerLoadedEventArgs e) { // Zoom to water network var layer = e.Layer as ArcGISDynamicMapServiceLayer; if (layer != null) { var extent = layer.ServiceInfo.InitialExtent ?? layer.ServiceInfo.InitialExtent; if (extent != null) { // If extent is not in the same spatial reference than map, reproject it if (!SpatialReference.Equals(extent.SpatialReference, MyMapView.SpatialReference)) { extent = GeometryEngine.Project(extent, MyMapView.SpatialReference) as Envelope; } if (extent != null) { extent = extent.Expand(0.5); MyMapView.SetView(extent); } } } }
private async void GeocodeButton_Click(object sender, RoutedEventArgs e) { GeocodeButton.IsEnabled = false; geocodeText.IsEnabled = false; try { GeoCodeProgress.Visibility = Visibility.Visible; if (_stopsOverlay.Graphics.Count() > 0) { panelResults.Visibility = Visibility.Collapsed; _stopsOverlay.Graphics.Clear(); _routesOverlay.Graphics.Clear(); MyMapView.Overlays.Items.Clear(); _directionsOverlay.GraphicsSource = null; } if (_locatorServiceInfo == null) { _locatorServiceInfo = await _locatorTask.GetInfoAsync(); } var candidateResults = await _locatorTask.GeocodeAsync( GetInputAddressFromUI(), new List <string> { "Addr_type", "Score", "X", "Y" }, MyMapView.SpatialReference, CancellationToken.None); if (candidateResults == null || candidateResults.Count == 0) { throw new Exception("No se encontró la dirección."); } var found = false; foreach (var candidate in candidateResults) { if (candidate.Score >= 90) { AddGraphicFromLocatorCandidate(candidate); found = true; MyMapView.SetView(candidate.Extent.Expand(1)); await MyMapView.ZoomToScaleAsync(5000); break; } } GeocodeFlyout.Hide(); if (!found) { throw new Exception("No se encontró la dirección."); } } catch (AggregateException ex) { var innermostExceptions = ex.Flatten().InnerExceptions; if (innermostExceptions != null && innermostExceptions.Count > 0) { var _x = new MessageDialog(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray()), "Error").ShowAsync(); } else { var _x = new MessageDialog(ex.Message, "Error").ShowAsync(); } } catch (System.Exception ex) { var _x = new MessageDialog(ex.Message, "Error").ShowAsync(); } finally { GeoCodeProgress.Visibility = Visibility.Collapsed; GeocodeButton.IsEnabled = true; geocodeText.IsEnabled = true; } }