Rectangle not getting displayed on map ?

177
13
07-31-2018 07:50 AM
VijitWadhwa
New Contributor III

Hi,

I tried to zoom the map by drawing a rectangle on the map (i.e zooming a specific area) , the map zooms to the extent on which rectangle gets drawed, but I am unable to see the rectangle on my screen , I am sharing the code, can anyone tell me , what is my mistake ?

Reply
0 Kudos
13 Replies
MortenNielsen
Esri Frequent Contributor

The editor only allows you to sketch a geometry, and is temporary while sketching. What you do with it afterwards is up to you. In this case you need to add it to the mapview afterwards. For instance by using a GraphicsOverlay.

Reply
0 Kudos
VijitWadhwa
New Contributor III

No , I don't want it to persist on mapView , but the problem is , I can't

even see the trail of rectangle been drawn.

Reply
0 Kudos
VijitWadhwa
New Contributor III

I don't want to add the rectangle on the map, I just want to see ,while it

gets drawn temporarily , but I am unable to see that. The map zooms to the

extent of the covered area while mouse is down , but I am unable to see the

trail of rectangle.

Reply
0 Kudos
VijitWadhwa
New Contributor III

This problem occurs if a measuring toolbar is present on the screen, If I remove the measuring toolbar then i can see the rectangle, Otherwise the rectangle is not visible. How to resolve this ?

Reply
0 Kudos
JenniferNery
Esri Regular Contributor

Hi Vijit,

I think I know what the problem is now that you mention MeasureToolbar. 

Can you check and set ` MyMapView.SketchEditor.IsVisible = true;`. The measure toolbar hides active editors when enabled, but this should only happen when a specific mode is selected.

VijitWadhwa
New Contributor III

Hi Jennifer,

Even if any specific mode was not selected, still the rectangle was not getting displayed. On setting the ` MyMapView.SketchEditor.IsVisible = true;` , I am able to see the rectangle, but the lines and polygons made by the measure toolbar get disappeared, How should i resolve it ?

Thanks

Reply
0 Kudos
JenniferNery
Esri Regular Contributor

Thanks for confirming. I just logged MeasureToolbar bug here. Not having any mode selected, should not have interfered with current SketchEditor.

However, the behavior where the measure draw feedback disappears once another SketchEditor becomes active is by design. MapView can only be assigned one SketchEditor at a given time.

If you don't want the other SketchEditor draw session to be canceled, you can disable it first and assign to MapView once your draw/edit session is over. You can do this by keeping reference to the current SketchEditor.

public MainWindow()
{
    InitializeComponent();
    _sketchEditor = MyMapView.SketchEditor;
    MyMapView.Map = new Map(Basemap.CreateTopographic());
}

private readonly SketchEditor _sketchEditor;

private async void OnDraw(object sender, RoutedEventArgs e)
{
    SketchEditor otherSketchEditor = null;
    if (MyMapView.SketchEditor != _sketchEditor)
    {
        otherSketchEditor = MyMapView.SketchEditor;
        otherSketchEditor.IsVisible = false;
        otherSketchEditor.IsEnabled = false;
        MyMapView.SketchEditor = _sketchEditor;
    }
    try
    {

        MyMapView.SketchEditor.IsVisible = true;
        var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);
        var _ = MyMapView.SetViewpointAsync(new Viewpoint(geometry));
    }
    catch (TaskCanceledException)
    {

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, ex.GetType().Name);
    }
    if(otherSketchEditor != null)
    {
        otherSketchEditor.IsVisible = true;
        otherSketchEditor.IsEnabled = true;
        MyMapView.SketchEditor = otherSketchEditor;
    }
}
VijitWadhwa
New Contributor III

Thankyou for your help

Reply
0 Kudos
JenniferNery
Esri Regular Contributor

Outside SketchEditor, there already is built-in feature that allows you to zoom-in/out by rectangle. It looks like this and can be used in combination with key press. Shift to zoom-in, Shift+Ctrl to zoom-out.

GeoView.ViewpointChanged event will be raised and you can GetCurrentViewpoint then to add target geometry to your map. 

If you wish to call SetViewpoint yourself like you are doing now and need the geometry result from rectangle sketch to remain on your map, you will need to add this to your GraphicsOverlay. You can use any symbol that matches the type of geometry. Rectangle will be a polygon so any fill symbol will do. 

public MainWindow()
{
    InitializeComponent();
    MyMapView.Map = new Map(Basemap.CreateTopographic());
    MyMapView.GraphicsOverlays.Add(new GraphicsOverlay());
}

private async void OnTest(object sender, RoutedEventArgs e)
{
    try
    {
        var geometry = await MyMapView.SketchEditor.StartAsync(SketchCreationMode.Rectangle, false);
        var overlay = MyMapView.GraphicsOverlays.FirstOrDefault();
        if (overlay == null)
            return;
        var symbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Transparent,
            new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Red, 2));
        overlay.Graphics.Add(new Graphic(geometry, symbol));

        var _ = MyMapView.SetViewpointAsync(new Viewpoint(geometry));
    }
    catch (TaskCanceledException)
    {

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, ex.GetType().Name);
    }
}
Reply
0 Kudos