Select to view content in your preferred language

Custom layers WPF

1493
9
10-29-2010 07:51 AM
NiklasWennberg
Deactivated User
Hi,

Is there anyone out there who has managed to implement a custom layer (GraphicLayer) using the ESRI.ArcGIS.Mobile.WPF namespace. I would be very happy if someone could give me some guidance on this issue.

Thanks in advance!
0 Kudos
9 Replies
AkhilParujanwala
Regular Contributor
Yes, but I used a Sample that ESRI provides, but this should help you in doing your task.

C:\Program Files (x86)\ArcGIS\Mobile10.0\DeveloperKit\Samples\ApplicationFramework\Windows\ShowXYLocationExtension

This is where the sample is located. Uses a Graphic layer to display the X,Y coordinates of where your mouse is on the map.
0 Kudos
NiklasWennberg
Deactivated User
Thanks Akhil for your reply, but I don't understand how that example would help me. There is an example called: CustomLayer_Win using windows forms to achive what I want to do in WPF but I really don't now how to translate it to WPF. For example there is no Draw method to override in GraphicLayer-WPF.

Any further help would be appreciated.
0 Kudos
AkhilParujanwala
Regular Contributor
The ShowXYExtension sample I linked to you, shows that you can create a graphic layer in which you can place text into it, however I believe this is not what you wanted.

I am not sure what you want to do with your graphic layer.

You want to draw? As in have users draw on screen like MS Paint? or collect features using a drawing method (you stated does not appear to be there).

If you don't mind clarifying the context of how you will use the graphics layer maybe other can also put some input too.

Thanks,

Akhil P.
0 Kudos
NiklasWennberg
Deactivated User
Hi,

I want to display geometries from a custom graphic layer as in the sample I mentioned. The only difference is that I am developing using the WPF library and there are som differences from using ordinary WinForms.

Below is the code I want to "migrate" to WPF. And as I mentioned in my previous post there is no Draw method to override in the GraphicLayer class in wpf name space. OnRender is the closest thing I've found so far...

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using ESRI.ArcGIS.Mobile;
using ESRI.ArcGIS.Mobile.Geometries;

namespace CustomLayer_Win
{
  public class CustomGraphicLayer: MapGraphicLayer
  {
    /// Defines a symbol class instance for displaying point
    private Symbol m_pointSymbol;
    /// Defines a CoordinateCollection instance to store custom features
    private CoordinateCollection m_coordinateCollection = new CoordinateCollection();
    /// Get or set coordinate collection stored in custom graphic layer
    public CoordinateCollection Coordinates
    {
      get      {
        return m_coordinateCollection;
      }
      set      {
        m_coordinateCollection = value;
      }
    }
    /// Initializes a new instance of custom graphic layer
    public CustomGraphicLayer(): base("CustomGraphicLayer")
    {
        m_pointSymbol = new Symbol(
        new PointPaintOperation(
        Color.LightGreen, 2, 0,  Color.LightGreen,   50, 25,  PointPaintStyle.Circle));
    }
    /// Draw method being called after adding to map
    protected override void Draw(Display display)
    {
      //return if display is null
      if (display == null)
        return;
      //return if drawing is cancelled
      if (display.DrawingCanceled)
        return;
      //draw coordinate collection using DrawMultipoint method
      m_pointSymbol.DrawMultipoint(display, m_coordinateCollection);
    }
    protected override void Dispose(bool disposing)
    {
      //Dispose symbol implementing IDisposible
      try
      {
        if (disposing)
        {
          if (m_pointSymbol != null)
            m_pointSymbol.Dispose();
          m_pointSymbol = null;

          m_coordinateCollection = null;
        }
      }
      finally
      {
        base.Dispose(disposing);
      }
    }

  }
}
0 Kudos
MelindaFrost
Frequent Contributor
To draw (display) the graphic you need to add your graphiclayer to the map using mapcontrol.MapGraphicLayer.Add(yourgraphiclayer)
To add geometry (points, lines, polygons) to the graphic layer- you need to add them to the graphic layer geometrybag.
0 Kudos
ChrisCarter
Deactivated User
I had the same problem, the samples are for Windows applications, the WPF model is a little different.  I got the attached sample from the Mobile team, it should help you implement a custom graphic layer.

-Chris
0 Kudos
NiklasWennberg
Deactivated User
Thanks Chris for a good sample.
Looking forward to see more WPF samples from the Mobile team. There are too few of them...
0 Kudos
ChristianDiaz
New Contributor
For all thoses who is trying add custom GraphicLayers to WPF Map.. a short way  is:
MobileCache md = new MobileCache("MapCache");
            md.Open();            
            mapControl1.MapLayers.AddRange(md);            
            mapControl1.ExtentChanged += new EventHandler(mapControl1_ExtentChanged);
            GraphicLayer gl = new GraphicLayer();
            ESRI.ArcGIS.Mobile.Geometries.Point p = new ESRI.ArcGIS.Mobile.Geometries.Point(new ESRI.ArcGIS.Mobile.Geometries.Coordinate(mapControl1.GetExtent().XCenter, mapControl1.GetExtent().YCenter));            
            mapControl1.MapGraphicLayers.Add(gl);//Carefull with the order of this 2 lines
            gl.GeometryBag.Add(p);


This sample adds a point in the center of the current extend.
0 Kudos
EzequiasRodrigues_da_Rocha
Regular Contributor
For all thoses who is trying add custom GraphicLayers to WPF Map.. a short way  is:
MobileCache md = new MobileCache("MapCache");
            md.Open();            
            mapControl1.MapLayers.AddRange(md);            
            mapControl1.ExtentChanged += new EventHandler(mapControl1_ExtentChanged);
            GraphicLayer gl = new GraphicLayer();
            ESRI.ArcGIS.Mobile.Geometries.Point p = new ESRI.ArcGIS.Mobile.Geometries.Point(new ESRI.ArcGIS.Mobile.Geometries.Coordinate(mapControl1.GetExtent().XCenter, mapControl1.GetExtent().YCenter));            
            mapControl1.MapGraphicLayers.Add(gl);//Carefull with the order of this 2 lines
            gl.GeometryBag.Add(p);


This sample adds a point in the center of the current extend.


How about adding a Text in the center of the map? I tryed with labels but it does not reflect on my MobileCache.

Regards
Ezequias
0 Kudos