//public async Task<QueryResult> // QueryEntitiesByID(QueryEntitiesArgs args, string layerName) //{ // QueryResult queryResult = null; // // Objs field must be filled // if (_localFeatureService == null || args.Objs == null) // return queryResult; // EngineeringLayer eLayer = _eMap.GetELayerByName(layerName); // if (eLayer == null) // return queryResult; // string url = _localFeatureService.UrlFeatureService // + "/" + eLayer.LocalLayerID; // QueryTask queryTask = new QueryTask(new Uri(url)); // Query query = new Query("1=1"); // query.OutFields.Add("*"); // query.ReturnGeometry = true; // query.OutSpatialReference = _srEMap; // query.Where = QueryCondition(args.Objs); // try // { // IsBusy = true; // queryResult = await queryTask.ExecuteAsync(query); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } // IsBusy = false; // return queryResult; //} //public async Task<QueryResult> // QueryEntitiesByGeom(QueryEntitiesArgs args, EngineeringLayer layer) //{ // QueryResult queryResult = null; // if (_localFeatureService == null || layer == null) // return queryResult; // string url = _localFeatureService.UrlFeatureService // + "/" + layer.LocalLayerID; // QueryTask queryTask = new QueryTask(new Uri(url)); // Query query = new Query("1=1"); // query.OutFields.Add("*"); // query.ReturnGeometry = true; // query.OutSpatialReference = _srEMap; // query.Geometry = args.Geometry; // query.Where = args.Condition; // try // { // IsBusy = true; // queryResult = await queryTask.ExecuteAsync(query); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } // IsBusy = false; // return queryResult; //} #endregion #region map pan functions public void panToObjects(IEnumerable <DGObject> objs) { if (objs == null) { return; } IGraphicCollection allGraphics = new IS3GraphicCollection(); foreach (DGObject obj in objs) { if (obj == null || obj.parent == null) { continue; } string layerID = obj.parent.definition.GISLayerName; IGraphicsLayer layer = _map.Layers[layerID] as IGraphicsLayer; if (layer == null) { continue; } IGraphicCollection gc = layer.getGraphics(obj); if (gc == null) { continue; } allGraphics.Add(gc); } panToGraphics(allGraphics); }
public void panToSelected() { IGraphicCollection allGraphics = new IS3GraphicCollection(); foreach (Layer layer in _map.Layers) { IGraphicsLayer gLayer = layer as IGraphicsLayer; if (gLayer == null) { continue; } allGraphics.Add(gLayer.selectedGraphics); } panToGraphics(allGraphics); }
// 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 void panToSelected() { IGraphicCollection allGraphics = new IS3GraphicCollection(); foreach (Layer layer in _map.Layers) { IGraphicsLayer gLayer = layer as IGraphicsLayer; if (gLayer == null) continue; allGraphics.Add(gLayer.selectedGraphics); } panToGraphics(allGraphics); }
//public async Task<QueryResult> // QueryEntitiesByID(QueryEntitiesArgs args, string layerName) //{ // QueryResult queryResult = null; // // Objs field must be filled // if (_localFeatureService == null || args.Objs == null) // return queryResult; // EngineeringLayer eLayer = _eMap.GetELayerByName(layerName); // if (eLayer == null) // return queryResult; // string url = _localFeatureService.UrlFeatureService // + "/" + eLayer.LocalLayerID; // QueryTask queryTask = new QueryTask(new Uri(url)); // Query query = new Query("1=1"); // query.OutFields.Add("*"); // query.ReturnGeometry = true; // query.OutSpatialReference = _srEMap; // query.Where = QueryCondition(args.Objs); // try // { // IsBusy = true; // queryResult = await queryTask.ExecuteAsync(query); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } // IsBusy = false; // return queryResult; //} //public async Task<QueryResult> // QueryEntitiesByGeom(QueryEntitiesArgs args, EngineeringLayer layer) //{ // QueryResult queryResult = null; // if (_localFeatureService == null || layer == null) // return queryResult; // string url = _localFeatureService.UrlFeatureService // + "/" + layer.LocalLayerID; // QueryTask queryTask = new QueryTask(new Uri(url)); // Query query = new Query("1=1"); // query.OutFields.Add("*"); // query.ReturnGeometry = true; // query.OutSpatialReference = _srEMap; // query.Geometry = args.Geometry; // query.Where = args.Condition; // try // { // IsBusy = true; // queryResult = await queryTask.ExecuteAsync(query); // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // } // IsBusy = false; // return queryResult; //} #endregion #region map pan functions public void panToObjects(IEnumerable<DGObject> objs) { if (objs == null) return; IGraphicCollection allGraphics = new IS3GraphicCollection(); foreach (DGObject obj in objs) { if (obj == null || obj.parent == null) continue; string layerID = obj.parent.definition.GISLayerName; IGraphicsLayer layer = _map.Layers[layerID] as IGraphicsLayer; if (layer == null) continue; IGraphicCollection gc = layer.getGraphics(obj); if (gc == null) continue; allGraphics.Add(gc); } panToGraphics(allGraphics); }
// 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 = (IS3.Core.Geometry.GeometryType)(int)table.GeometryType; return gLayer; }
public int syncObjects(IEnumerable<DGObject> objs) { if (objs == null) return 0; // Build (graphic name)-(graphics) index. // Graphics may share a same name if they belong to a object. // Dictionary<string, IGraphicCollection> graphicIndex = new Dictionary<string, IGraphicCollection>(); foreach (IGraphic g in graphics) { if (g.Attributes.ContainsKey("Name")) { string name = g.Attributes["Name"] as string; if (name == null) continue; IGraphicCollection gc = null; if (graphicIndex.ContainsKey(name)) gc = graphicIndex[name]; else { gc = new IS3GraphicCollection(); graphicIndex[name] = gc; } gc.Add(g); } } // Sync objects with graphics // _obj2Graphics = new Dictionary<DGObject, IGraphicCollection>(); _graphicName2Objs = new Dictionary<string, DGObject>(); int count = 0; foreach (DGObject obj in objs) { string name = obj.name; if (graphicIndex.ContainsKey(name)) { IGraphicCollection gc = graphicIndex[name]; _obj2Graphics[obj] = gc; _graphicName2Objs[name] = obj; count++; } } _graphic2Objs = new Dictionary<IGraphic, DGObject>(); foreach (IGraphic g in graphics) { if (g.Attributes.ContainsKey("Name")) { string name = g.Attributes["Name"] as string; if (name == null) continue; if (_graphicName2Objs.ContainsKey(name)) { _graphic2Objs[g] = _graphicName2Objs[name]; } } } return count; }