// Summary: // Set the GraphicsLayer display options according to the definition // which is specified in the LocalELayer. // The display options include selection color, renderer, and labelling // void setGraphicLayerDisplayOptions(LayerDef layerDef, IS3GraphicsLayer gLayer) { if (layerDef == null || gLayer == null) { return; } gLayer.IsVisible = layerDef.IsVisible; gLayer.SelectionColor = layerDef.SelectionColor; ISymbol symbol = GraphicsUtil.GenerateLayerSymbol(layerDef, gLayer.geometryType); gLayer.renderer = Runtime.graphicEngine.newSimpleRenderer(symbol); //if (layerDef.RendererDef == null) //{ // //} //else //{ // gLayer.renderer = Runtime.graphicEngine.newRenderer(layerDef.RendererDef); //} if (layerDef.EnableLabel == true) { AttributeLabelClass labelClass = generateLayerAttributeLable(layerDef, gLayer.geometryType); gLayer.Labeling.LabelClasses.Add(labelClass); } }
// Summary: // Add a layer in a shape file // The name of the layer and display options are specified in the LocalELayer // public async Task <IGraphicsLayer> addShpLayer(LayerDef layerDef, string shpFile, int start = 0, int maxFeatures = 0) { if (layerDef == null || shpFile == null) { return(null); } string filePath = _prj.projDef.LocalFilePath + "\\" + shpFile; if (File.Exists(filePath)) { ShapefileTable table = await ShapefileTable.OpenAsync(filePath); if (table == null) { return(null); } IS3GraphicsLayer gLayer = await featureTable2GraphicsLayer( table, start, maxFeatures, true); if (gLayer == null) { return(null); } gLayer.ID = layerDef.Name; setGraphicLayerDisplayOptions(layerDef, gLayer); _map.Layers.Add(gLayer); return(gLayer); } return(null); }
public IGraphicsLayer removeLayer(string layerID) { IS3GraphicsLayer layer = _map.Layers[layerID] as IS3GraphicsLayer; _map.Layers.Remove(layer); return(layer); }
// Summary: // Add a layer in a geodatabase (aka. local layer) // The name of the layer and display options are specified in the LocalELayer // public async Task <IGraphicsLayer> addGeodatabaseLayer(LayerDef layerDef, Geodatabase gdb, int start = 0, int maxFeatures = 0) { if (layerDef == null || gdb == null) { return(null); } GeodatabaseFeatureTable table = gdb.FeatureTables.FirstOrDefault(t => t.Name == layerDef.Name); if (table == null) { return(null); } IS3GraphicsLayer gLayer = await featureTable2GraphicsLayer( table, start, maxFeatures, false); if (gLayer == null) { return(null); } gLayer.ID = layerDef.Name; gLayer.MinScale = table.ServiceInfo.MinScale; gLayer.MaxScale = table.ServiceInfo.MaxScale; setGraphicLayerDisplayOptions(layerDef, gLayer); _map.Layers.Add(gLayer); return(gLayer); }
public async Task <bool> selectByPoint(Point screenPoint) { bool success = false; DGObject obj = null; IS3GraphicsLayer gLayer = null; foreach (Layer layer in _map.Layers) { gLayer = layer as IS3GraphicsLayer; if (!isLayerSelectable(gLayer)) { continue; } obj = await gLayer.selectObjectByPoint(screenPoint, mapView); if (obj != null) { break; } } if (obj != null && objSelectionChangedTrigger != null) { ObjSelectionChangedEventArgs args = new ObjSelectionChangedEventArgs(); args.addedObjs = new Dictionary <string, IEnumerable <DGObject> >(); List <DGObject> objs = new List <DGObject>(); objs.Add(obj); args.addedObjs.Add(gLayer.ID, objs); objSelectionChangedTrigger(this, args); success = true; } return(success); }
// Summary: // Add a layer in a geodatabase (aka. local layer) // The name of the layer and display options are specified in the LocalELayer // public static async Task <IGraphicsLayer> addGeodatabaseLayer( Map map, LayerDef layerDef, GeodatabaseFeatureTable table, int start = 0, int maxFeatures = 0) { if (layerDef == null || table == null) { return(null); } IS3GraphicsLayer gLayer = await featureTable2GraphicsLayer( map, table, start, maxFeatures); if (gLayer == null) { return(null); } gLayer.ID = table.Name; gLayer.MinScale = table.ServiceInfo.MinScale; gLayer.MaxScale = table.ServiceInfo.MaxScale; setGraphicLayerDisplayOptions(layerDef, gLayer); map.Layers.Add(gLayer); return(gLayer); }
async Task showDefaultMapTip(System.Windows.Point screenPoint, MapPoint mapPoint) { if (_isHitTesting) { return; } try { _isHitTesting = true; DGObject obj = null; IS3GraphicsLayer gLayer = null; for (int i = _map.Layers.Count - 1; i >= 0; i--) { Layer layer = _map.Layers[i]; gLayer = layer as IS3GraphicsLayer; if (!isLayerSelectable(gLayer)) { continue; } obj = await gLayer.hitTestAsync(screenPoint, mapView); if (obj != null) { break; } } //foreach (Layer layer in _map.Layers) //{ // gLayer = layer as IS3GraphicsLayer; // if (!isLayerSelectable(gLayer)) // continue; // obj = await gLayer.hitTestAsync(screenPoint, mapView); // if (obj != null) // { // break; // } //} if (obj != null) { //_mapTip.className.Text = obj.GetType().Name; _mapTip.DataContext = obj; _mapTip.Visibility = System.Windows.Visibility.Visible; MapView.SetViewOverlayAnchor(_mapTip, mapPoint); } else { _mapTip.Visibility = System.Windows.Visibility.Collapsed; } } catch { _mapTip.Visibility = System.Windows.Visibility.Collapsed; } finally { _isHitTesting = false; } }
//public async void drawToolsClickEventListener(object sender, // UserControl.DrawToolClickEventArgs args) //{ // if (args.stopDraw) // { // if (_mapView.Editor.Cancel.CanExecute(null)) // _mapView.Editor.Cancel.Execute(null); // } // else // { // await drawGraphics(args.drawShapeType); // } //} public async Task drawGraphics(DrawShapeType drawShapeType) { if (Globals.isThreadUnsafe()) { await Globals.application.Dispatcher.Invoke(new Func <Task>(async() => { await drawGraphics(drawShapeType); })); return; } // Add a drawing graphics layer if (_drawingLayer == null) { _drawingLayer = new IS3GraphicsLayer(); _drawingLayer.ID = "0"; _drawingLayer.DisplayName = "0"; _map.Layers.Add(_drawingLayer); } if (_mapView.Editor.IsActive) { return; } try { Geometry geom = await _mapView.Editor.RequestShapeAsync((DrawShape)drawShapeType); if (_srEMap != null) { geom = GeometryEngine.Project(geom, _srEMap); } IGeometry iGeom = IS3GeometryEngine.fromGeometry(geom); IGraphic g = Runtime.graphicEngine.newGraphic(iGeom); GraphicsUtil.AssignDefaultDrawingSymbol(g); _drawingLayer.graphics.Add(g); // trigger a drawing graphics changed event if (drawingGraphicsChangedTrigger != null) { DrawingGraphicsChangedEventArgs args = new DrawingGraphicsChangedEventArgs(); List <IGraphic> addedItems = new List <IGraphic>(); addedItems.Add(g); args.addedItems = addedItems; drawingGraphicsChangedTrigger(this, args); } } catch (TaskCanceledException) { // Ignore TaskCanceledException - usually happens if the editor gets cancelled or restarted } }
public async Task <bool> selectByPoint(System.Windows.Point screenPoint) { bool success = false; DGObject obj = null; IS3GraphicsLayer gLayer = null; //foreach (Layer layer in _map.Layers) //{ // gLayer = layer as IS3GraphicsLayer; // if (!isLayerSelectable(gLayer)) // continue; // obj = await gLayer.selectObjectByPoint(screenPoint, mapView); // if (obj != null) // { // break; // } //} for (int i = _map.Layers.Count - 1; i >= 0; i--) { Layer layer = _map.Layers[i]; gLayer = layer as IS3GraphicsLayer; if (!isLayerSelectable(gLayer)) { continue; } obj = await gLayer.selectObjectByPoint(screenPoint, mapView); if (obj != null) { break; } } if (obj != null && ObjSelectionChangedHandler != null) { ObjSelectionChangedEvent args = new ObjSelectionChangedEvent(); args.addObjs = new Dictionary <string, List <DGObject> >(); List <DGObject> objs = new List <DGObject>(); objs.Add(obj); args.addObjs.Add(obj.parent.definition.Name, objs); ObjSelectionChangedHandler(this, args); success = true; } return(success); }
public void InitializeDoc() { _defaultDrawingELayer = _view.EMap.GetELayerByName(_drawingLayerName); if (_defaultDrawingELayer == null) { _defaultDrawingELayer = _view.EMap.NewDrawingELayer(_drawingLayerName, "DGGraphic"); _defaultDrawingELayer.LayerType = EngineeringLayerType.UserDrawing; } IS3GraphicsLayer gLayer = null; gLayer = _view.GetLayer(_drawingLayerName) as IS3GraphicsLayer; if (gLayer == null) { gLayer = _view.NewLayer(_drawingLayerName, _defaultDrawingELayer) as IS3GraphicsLayer; } if (File.Exists(_filePath)) { StreamReader reader = new StreamReader(_filePath); XElement root = XElement.Load(reader); if (root.Name != "Map" || root.Attribute("MapID").Value != _view.EMap.MapID) { string error = string.Format(_corruptedDataFile, _filePath); MessageBox.Show(error); return; } DefaultDrawingELayerFromXml(root); } }
// Summary: // Load features in a FeatureTable into a GraphicsLayer // async Task <IS3GraphicsLayer> featureTable2GraphicsLayer(FeatureTable table, int start = 0, int maxFeatures = 0, bool isShp = false) { if (table == null) { return(null); } if (_srEMap == null) { // The spatial reference in the first table is used as the project spatial reference. // All features on other layers will be projected to the spatial reference. _srEMap = table.SpatialReference; _map.SpatialReference = table.SpatialReference; } //// We cannot use the feature layer class because it typically //// has a different SpatialReferece object (coordinate system) //// other than the tiled layer (WKID = 3857 or 102100), //// and there is no easy way to reproject feature layer //// to another coordinate system. //// We can only use the feature layer when there is no tiled layer defined, //// which is not a usual case. //FeatureLayer fLayer = new FeatureLayer(table); //fLayer.ID = table.Name; //fLayer.DisplayName = table.Name; //_map.Layers.Add(fLayer); QueryFilter qf = new QueryFilter(); qf.WhereClause = "1=1"; IEnumerable <Feature> features = await table.QueryAsync(qf); IS3GraphicCollection graphics = new IS3GraphicCollection(); int index = 0, count = 0; foreach (Feature f in features) { // jump to start position if (index++ < start) { continue; } // Note: // In ArcGIS Runtime SDK: User-defined coordinate system // is not allowed when using ShapefileTable.OpenAsync(). // Workaround: // (1) Do not assign user-defined CS in shape file; // (2) Assign CS dynamically here to _srEMap. // Geometry geometry = f.Geometry; if (isShp == true) { geometry = ArcGISMappingUtility.ChangeSpatailReference(geometry, _srEMap); if (geometry == null) { continue; } } if (_srEMap != null && isShp == false && geometry.SpatialReference != _srEMap) { geometry = GeometryEngine.Project(geometry, _srEMap); } // import the attributes IS3Graphic g = new IS3Graphic(geometry); foreach (KeyValuePair <string, object> item in f.Attributes.AsEnumerable()) { g.Attributes.Add(item); } graphics.Add(g); // Load max featuers if (maxFeatures != 0 && count++ == maxFeatures) { break; } } IS3GraphicsLayer gLayer = new IS3GraphicsLayer(); gLayer.DisplayName = table.Name; gLayer.GraphicsSource = graphics; gLayer.geometryType = (Core.Model.GeometryType)(int) table.GeometryType; return(gLayer); }
public IGraphicsLayer getLayer(string layerID) { IS3GraphicsLayer layer = _map.Layers[layerID] as IS3GraphicsLayer; return(layer); }