How to create an inset map inside of a Dockpane?

624
5
11-05-2020 10:10 AM
Amadeus111
Occasional Contributor II

I created a frame inside of a dockpane and created the map but I could not figure out how to place the map inside the frame I created. 

XAML:
 <Frame x:Name="InsetMapFrame" HorizontalAlignment="Left" Margin="5,5,0,0" 
      VerticalAlignment="Top" Height="100" Width="278"/>

C#:
public void AddMap2()
 {
    QueuedTask.Run(() =>
    {
       var newProject = Project.Current;

       if (newProject != null)
       {
          var map = MapFactory.Instance.CreateMap("Kentucky", MapType.Map, 
                                       MapViewingMode.Map, Basemap.Hybrid);
          System.Uri uri = new System.Uri(map.URI);

          InsetMapFrame.Source = uri;
       }
    });
 }

0 Kudos
5 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I am not sure if you need a map control on your dockpane, if so then there is a sample that shows a map control in a dockpane:  OverviewMapControl

0 Kudos
Amadeus111
Occasional Contributor II

This is not what I am looking for but good to know this exists and might be able to use for another application. I need a simple inset map displays inside a dock pane. Thank you for your answer.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Looking at your code snippet above I could only deduct that you tried to display a map on your dockpane.  A Frame in WPF can be used to host WPF or HTML content.  Using the WPF content option for the Frame you can use a MapControl which would allow you to display a map created by MapFactory in your dockpane.  To implement this you can use my sample link above.  In your code snippet in your original question you try to display HTML content, but you pass in a unique identifier which happens to be in URI format (https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic11907.html).  ArcGIS Pro doesn't serve up web maps that can be displayed as HTML content.

Amadeus111
Occasional Contributor II

Sorry for the insufficient information on my question. I was just trying to show what I have tried which caused to a confusion. Also, I thought your mapcontrol is a module itself rather than something I can place inside a dockpane.

I am creating a dockpane which helps users to filter/find the data easily as we have too many different spatial data. I would like to display an inset map along with the full zoomed selected layer. So, users are able to see the data visually without moving the layer to TOC. I started working on the creating the map as initial step. 

 

I have modified your code but still map is not showing up. Do you have any idea what I am doing wrong? 


XAML:
xmlns:controls1="clr-namespace:ArcGIS.Desktop.Mapping.Controls;assembly=ArcGIS.Desktop.Mapping"
.
.
.
 <TextBlock Text="{Binding ActiveMap}" Margin="0,10"></TextBlock>
 <!--The MapControl -->
 <controls1:MapControl Name="MapControl" HorizontalAlignment="Right" Height="150" Margin="0,0,7,0" Width="273" >
 </controls1:MapControl>


C#:
private readonly MapControl _mapControl = null;

 public Dockpane1View()
 {
    InitializeComponent();
    _mapControl = this.MapControl; //Link _mapControl variable to this map control
    CreateInsetMap();
 }

 public void CreateInsetMap()
 {
    QueuedTask.Run(() =>
    {
       var newProject = Project.Current;

       if (newProject != null)
       {
          var map = MapFactory.Instance.CreateMap("Kentucky", MapType.Map, MapViewingMode.Map, Basemap.Hybrid);

          map = MapView.Active.Map;

          if (MapView.Active == null)
             return;
          if (MapView.Active.Extent == null)
             return;
          var spatialRef = SpatialReferenceBuilder.CreateSpatialReference(4269);
          var env = EnvelopeBuilder.CreateEnvelope(3798937, 3348809, 6018368, 4307216, spatialRef);
          map.SetCustomFullExtent(env);
          //Define 2D Extent that should be displayed inside the mapcontrol.
          _mapControl.ViewContent = MapControlContentFactory.Create(map, env, map.DefaultViewingMode)
          return;
       }
    });
}
0 Kudos
Amadeus111
Occasional Contributor II

I was over complicating but @Wolf  helped me find the right solution with map control. 

 

 

public void CreateInsetMap()
{
    QueuedTask.Run(() =>
    {
        var newProject = Project.Current;

        if (newProject != null)
        {
            kymap = MapFactory.Instance.CreateMap("Kentucky", MapType.Map, MapViewingMode.Map, Basemap.Hybrid);

            //map = MapView.Active.Map
            var spatialRef = SpatialReferenceBuilder.CreateSpatialReference(4269);
            var env = EnvelopeBuilder.CreateEnvelope(3798937, 3348809, 6018368, 4307216, spatialRef);
            kymap.SetCustomFullExtent(env);
            //Define 2D Extent that should be displayed inside the mapcontrol.
            this.Dispatcher.Invoke(() =>
            {
                LayersMapControl.ViewContent = MapControlContentFactory.Create(kymap, env, kymap.DefaultViewingMode);

            });

            return;
        }
    });
}

 

 

 

This is not a proper MVVM way but I will fix it later. 

 

Result:

 

KSDE.gif

0 Kudos