Parameters
- bookmark
- Bookmark
Exception | Description |
---|---|
ArcGIS.Core.CalledOnWrongThreadException | This method or property must be called within the lambda passed to QueuedTask.Run. |
//Set the extent of a map frame to a bookmark. //Perform on the worker thread await QueuedTask.Run(() => { //Reference MapFrame MapFrame mf_bk = layout.FindElement("Map Frame") as MapFrame; //Reference a bookmark that belongs to a map associated with the map frame Map m = mf_bk.Map; Bookmark bk = m.GetBookmarks().FirstOrDefault(item => item.Name.Equals("Lakes")); //Set the map frame extent using the bookmark mf_bk.SetCamera(bk); });
//Create a map frame and set its camera by zooming to the extent of an existing bookmark. //Construct on the worker thread await QueuedTask.Run(() => { //Build 2D envelope geometry Coordinate2D mf_ll = new Coordinate2D(6.0, 8.5); Coordinate2D mf_ur = new Coordinate2D(8.0, 10.5); //At 2.x - Envelope mf_env = EnvelopeBuilder.CreateEnvelope(mf_ll, mf_ur); Envelope mf_env = EnvelopeBuilderEx.CreateEnvelope(mf_ll, mf_ur); //Reference map, create MF and add to layout MapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>() .FirstOrDefault(item => item.Name.Equals("Map")); Map mfMap = mapPrjItem.GetMap(); Bookmark bookmark = mfMap.GetBookmarks().FirstOrDefault( b => b.Name == "Great Lakes"); //At 2.x - MapFrame mfElm = // LayoutElementFactory.Instance.CreateMapFrame( // layout, mf_env, mfMap); // mfElm.SetName("New Map Frame"); // MapFrame mfElm = ElementFactory.Instance.CreateMapFrameElement( layout, mf_env, mfMap, "New Map Frame"); //Zoom to bookmark mfElm.SetCamera(bookmark); });
//Change map frame extent to single feature with 10 percent buffer //Process on the worker thread await QueuedTask.Run(() => { //Reference the mapframe and its associated map MapFrame mf = layout.FindElement("Map Frame") as MapFrame; Map m = mf.Map; //Reference a feature layer and build a query (to return a single feature) FeatureLayer fl = m.FindLayers("GreatLakes").First() as FeatureLayer; QueryFilter qf = new QueryFilter(); string whereClause = "NAME = 'Lake Erie'"; qf.WhereClause = whereClause; //Zoom to the feature using (ArcGIS.Core.Data.RowCursor rowCursor = fl.Search(qf)) { while (rowCursor.MoveNext()) { //Get the shape from the row and set extent using (var feature = rowCursor.Current as ArcGIS.Core.Data.Feature) { Polygon polygon = feature.GetShape() as Polygon; Envelope env = polygon.Extent as Envelope; mf.SetCamera(env); //Zoom out 15 percent Camera cam = mf.Camera; cam.Scale = cam.Scale * 1.15; mf.SetCamera(cam); } } } });
Target Platforms: Windows 11, Windows 10