Customize OverviewMapControl Add-in

144
3
Jump to solution
10-31-2018 10:57 AM
Highlighted
New Contributor II

I have downloaded the community samples, installed SDK and run the solution successfully in Visual Studio to generate the default add-in. I am now interested in customizing the overviewmapcontrol to:

1) display specific layers (not all of the active/displayed layers)

2) open to a specified zoom extent and remain static unless the user clicks/pans/zooms the window pane

I have located some of the snippets on the git site (zoom to extent specifically) but do not know how to format the coordinates and am unclear as to what heading they go under. I cannot find related code and am unfamiliar with coding in C# (pretty well versed in python and AHK). Any help or resources would be GREATLY appreciated. 

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Regular Contributor

Hi Peter,

Something like this would display specific layers in the Map Control (I have used the overload to display a collection of specific layers in line 23.): 

 private async void InitializeMapControl()
        {
            ActiveMapViewChangedEvent.Subscribe(OnActiveMapViewChanged); //Update the content of the MapControl when the active map changes.
            MapViewCameraChangedEvent.Subscribe(OnMapViewCameraChanged);

           
            if (MapView.Active == null)
                return;
            if (MapView.Active.Extent == null)
                return;
            //Setting the collection of layers we want to display in the Map Control.
            var layerToDisplay = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First();
            List<Layer> layersToDisplay = new List<Layer> { layerToDisplay };

            //2D
            if (MapView.Active.ViewingMode == ArcGIS.Core.CIM.MapViewingMode.Map)
            {
                Envelope mapControlExtent = await QueuedTask.Run(() =>
                    (MapView.Active.Extent.Clone() as Envelope)?.Expand(4, 4, true));
                //Define 2D Extent that should be displayed inside the mapcontrol.
                //_mapControl.ViewContent = MapControlContentFactory.Create(MapView.Active.Map, mapControlExtent, MapView.Active.Map.DefaultViewingMode);
                //This overload use the collection of Layers we want to display the content.
                _mapControl.ViewContent = MapControlContentFactory.Create(layersToDisplay, mapControlExtent, MapView.Active.Map.DefaultViewingMode);
                //Event handler: When mapcontrol's extent changes, the active map view reflects the extent.
                _mapControl.ExtentChanged += OnMapControlExtentChanged;               
                return;
            }
            //3D
            //Define 3D View that should be displayed inside the mapcontrol.
            if (MapView.Active.Camera == null)
                return;
            Camera newCamera = new Camera(MapView.Active.Camera.X, MapView.Active.Camera.Y,
                MapView.Active.Camera.Z + 100, MapView.Active.Camera.Pitch, MapView.Active.Camera.Heading);
            _mapControl.ViewContent = MapControlContentFactory.Create(MapView.Active.Map, newCamera,
                MapView.Active.Map.DefaultViewingMode);            
          
            _mapControl.CameraChanged += OnMapControlCameraChanged;
        }

View solution in original post

Reply
0 Kudos
3 Replies
Highlighted
Esri Regular Contributor

Hi,

1. MapControl has a ViewContent property that can be set to any custom view content.  In the sample, I am using the MapControlContentFactory.Create method to set the view content (within the InitializeMapControl method in MapControlDockpane.xaml.cs).  This Create method has many overloads.  This particular overload might be exactly what you need: (Note the first parameter which takes a list of any layers you need)

Create Methodhttp://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic12607.html 

public static MapControlContent Create( IEnumerable<Layer> layers, Envelope initialExtent, MapViewingMode viewingMode )

2. MapControl's zoom extent is also defined when you create the content using the Create method (the envelope parameter).  In the sample, I am listening to the ActiveMapViewChangedEvent and MapViewCameraChangedEvent events and modifying the MapControl's extent to match that. You can remove that for your workflow and set the MapControl's content the way you want it to be.

Thanks

Uma

Reply
0 Kudos
Highlighted
New Contributor II

Hi Uma,

I can find the related code in MapControlDockpane.xaml.cs and understand the create method, but am stumped as to where I write the method with my parameters. Changing the MapControlContentFactory.Create method line to what you suggested results in errors that  'MapControlContent' does not contain a definition for 'create', so where do I put the definition block? Is that where the parameters are entered, or are they entered when I call the function?

Thank you for your help with this!

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Hi Peter,

Something like this would display specific layers in the Map Control (I have used the overload to display a collection of specific layers in line 23.): 

 private async void InitializeMapControl()
        {
            ActiveMapViewChangedEvent.Subscribe(OnActiveMapViewChanged); //Update the content of the MapControl when the active map changes.
            MapViewCameraChangedEvent.Subscribe(OnMapViewCameraChanged);

           
            if (MapView.Active == null)
                return;
            if (MapView.Active.Extent == null)
                return;
            //Setting the collection of layers we want to display in the Map Control.
            var layerToDisplay = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First();
            List<Layer> layersToDisplay = new List<Layer> { layerToDisplay };

            //2D
            if (MapView.Active.ViewingMode == ArcGIS.Core.CIM.MapViewingMode.Map)
            {
                Envelope mapControlExtent = await QueuedTask.Run(() =>
                    (MapView.Active.Extent.Clone() as Envelope)?.Expand(4, 4, true));
                //Define 2D Extent that should be displayed inside the mapcontrol.
                //_mapControl.ViewContent = MapControlContentFactory.Create(MapView.Active.Map, mapControlExtent, MapView.Active.Map.DefaultViewingMode);
                //This overload use the collection of Layers we want to display the content.
                _mapControl.ViewContent = MapControlContentFactory.Create(layersToDisplay, mapControlExtent, MapView.Active.Map.DefaultViewingMode);
                //Event handler: When mapcontrol's extent changes, the active map view reflects the extent.
                _mapControl.ExtentChanged += OnMapControlExtentChanged;               
                return;
            }
            //3D
            //Define 3D View that should be displayed inside the mapcontrol.
            if (MapView.Active.Camera == null)
                return;
            Camera newCamera = new Camera(MapView.Active.Camera.X, MapView.Active.Camera.Y,
                MapView.Active.Camera.Z + 100, MapView.Active.Camera.Pitch, MapView.Active.Camera.Heading);
            _mapControl.ViewContent = MapControlContentFactory.Create(MapView.Active.Map, newCamera,
                MapView.Active.Map.DefaultViewingMode);            
          
            _mapControl.CameraChanged += OnMapControlCameraChanged;
        }

View solution in original post

Reply
0 Kudos