Add overlay graphic on overview windows problem (SDK 3.0)

281
7
a month ago
RookieLee
New Contributor

I used overview in SDK sample code and wanna add graphic on it. The graphic does not show unless I added a messagebox and show it ( the red text below). Can anyone has solution of it? 

 

//sample code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using ArcGIS.Core.CIM;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Mapping.Controls;
 
namespace MapControl {
    internal class ShowOverview : Button {
        private static System.IDisposable _overlayObject = null;
        private bool _isOpen = false;
        private OverviewWindow _overview = null;
        private static readonly object _lock = new object();
 
 
        private IDisposable _graphic = null;
 
        private CIMLineSymbol _lineSymbol = null;
 
        public ShowOverview() {
            RegisterForActiveViewChanged();
        }
    protected override void OnClick()
    {
      if (_isOpen)
        return;
      _overview = new OverviewWindow();
      var cam = MapView.Active.Camera;
      //cam.Heading = 90;
      _overview.ViewContent = MapControlContentFactory.Create(
          MapView.Active.Map, cam, MapView.Active.ViewingMode);
 
           
                
              
            _overview.Closed += (s, e) =>
      {
       _isOpen = false;
        lock (_lock)
        {
          _overview = null;
        }
      };
      _overview.Show();
      _isOpen = true;

var extent = MapView.Active.Extent;

var height = extent.Height;
var width = extent.Width;
var centerPt = extent.Center;

ArcGIS.Core.CIM.CIMPointSymbol symbol = null;
_overlayObject =   QueuedTask.Run(() =>
{
    //add these to the overlay
   _overview.MyMapControl.AddOverlay(centerPt,
   SymbolFactory.Instance.ConstructPointSymbol(
    ColorFactory.Instance.RedRGB, 30.0, SimpleMarkerStyle.Star).MakeSymbolReference());
});
 
            
 
     //update the overlay with new point graphic symbol
 
     // MessageBox.Show("test");
 
     //QueuedTask.Run(() =>
     // {
 
      //     _overview.MyMapControl.AddOverlay(centerPt,
     //         SymbolFactory.Instance.ConstructPointSymbol(
     //                 ColorFactory.Instance.RedRGB, 30.0, SimpleMarkerStyle.Star).MakeSymbolReference());
     // });
 
    }
 
    private void RegisterForActiveViewChanged() {
            ArcGIS.Desktop.Mapping.Events.ActiveMapViewChangedEvent.Subscribe((args) => {
                if (args.IncomingView == null)
                    return;
                lock (_lock) {
                    if (_overview == null)
                        return;
                    _overview.ViewContent = MapControlContentFactory.Create(
                        MapView.Active.Map, MapView.Active.Extent, MapView.Active.ViewingMode);
                }
            });
        }
 
    }
}

 

0 Kudos
7 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Your _overview.MyMapControl.OverlayControl equal null. This is the reason why you can add overlay. Create new OverlayControl, set it to _overview.MyMapControl. Then try to add overlay.

How to deal with OverlayControl look at the community sample ScribbleControl_ArcGISPro

0 Kudos
RookieLee
New Contributor

I checked it is not null. It is a popup WPF windows, the added overlay symbol only can show after I added a MessageBox.show message and pop up first.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

I have debugged on ArcGIS Pro 3.1 and found, _overview.MyMapControl.OverlayControl before adding overlay is equal null.

Another one thing you need to make your OnClick() method async and add await before calling  QueuedTask.Run. Without await it returns Task type object

 

0 Kudos
RookieLee
New Contributor

is it possible to add a polygon symbol inside the overview WPF window without adding current active view?

0 Kudos
NarelleChedzey
Esri Contributor

Hello, 

 

You need to wait until the MapControl on the overview window has finished drawing before you can add anything to it's overlay.  Move your code into an event handler for the DrawComplete. 

Your OnClick method should look like the following

 

protected override void OnClick()
{
  if (_isOpen)
    return;
  _overview = new OverviewWindow();
  var cam = MapView.Active.Camera;
  //cam.Heading = 90;
  _overview.ViewContent = MapControlContentFactory.Create(MapView.Active.Map, cam, MapView.Active.ViewingMode);
  _overview.Closed += (s, e) =>
  {
    _isOpen = false;
    lock (_lock)
    {
      _overview = null;
    }
  };

  _overview.MyMapControl.DrawComplete += (s, e) =>
  {
    if (MapView.Active == null)
      return;

    var extent = MapView.Active.Extent;

    var height = extent.Height;
    var width = extent.Width;
    var centerPt = extent.Center;

    QueuedTask.Run(() =>
    {
      _overview.MyMapControl.AddOverlay(centerPt,
           SymbolFactory.Instance.ConstructPointSymbol(
                   ColorFactory.Instance.RedRGB, 30.0, SimpleMarkerStyle.Star).MakeSymbolReference());
    });
  };

  _overview.Show();
  _isOpen = true;
}

 

Narelle

0 Kudos
RookieLee
New Contributor

I have further question about overview map, is it possible to add WPF control onto the mapcontrol ? E.g. button, I added a button in xaml file but the button is covered by the mapcontrol. 

0 Kudos
NarelleChedzey
Esri Contributor

You cannot add controls to the mapControl itself.  but you can add other controls to the window that is hosting the mapControl. 

In your example (the MapControl sample); this means you can add a button to the OverviewWindow xaml file.  

If you are not familiar with WPF you may need to do some research about the various WPF controls that can help you control the layout.  

Here's an article that gives some introduction to the Grid control  - https://wpf-tutorial.com/panels/grid/.  and how you can use column, rows and alignments to position child elements .

Narelle

0 Kudos