Click or drag to resize

Rendering Concept

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release

Renderers are used to draw additional features on a map. Any object that you want to draw on a map should implement the IMapRenderer interface. Then, add the object to the Renderer property of an IMap, and the object will be drawn on the map. The object that implements the IMapRenderer interface is often a user object, although there are some objects provided with GeoBase that also implement this interface.

Tutorial

See Renderers Tutorial

Create a simple form with a map and add a user-defined class that implements the IMapRenderer interface to draw on that map.

Rendering

When a map is redrawn, the Render method of the IMapRenderer currently assigned to the map is invoked. The renderer then draws any appropriate graphics onto the map and returns.

The Render method is passed a System.Drawing.Graphics object to facilitate drawing on the map. A RenderContext object is also passed to the method, giving information about the current RenderMode, and allowing the renderer to reserve space on the map by calling Place. If desired, a renderer may use Test to determine whether it is about to draw over an already placed object. The target IMap can also be retrieved from the RenderContext to allow coordinate transformations and provide the renderer with additional information about the state of the map.

The Render method is called four times for each map - once for each of the RenderModes. For details on the four different RenderModes, see Render Modes in Detail.

Example

The example below describes a very simple implementation of IMapRenderer, that draws a circle in the middle of the map. Often it is desirable to make the IMapRenderer reserve space from the RenderContext, and to vary behavior depending on the current RenderMode.

C#
public class CenterRenderer : IMapRenderer {

  public RenderMode RequiredRendermodes {
    get { return RenderMode.PostLabelling; }
  }

  public void Render(Graphics graphics, RenderContext rc) {
    if (rc.Mode != RenderMode.PostLabelling) return;

    // Render a circle at the center of the map
    Pen pen = new Pen(Color.Red, 3);
    int center_x, center_y;
    int radius = 20;
    rc.Map.LatLontoXY(out center_x, out center_y, rc.Map.Center);
    graphics.DrawEllipse(pen, center_x - radius, center_y - radius, radius * 2, radius * 2);
  }
}

...

public class MyApplication {
  IMap map;
  ...
  public void InitApplication() {
    ...
    map.Renderer = new CenterRenderer();
    ...
  }
...
}
Beyond the basics

You can combine multiple renderers using RendererList objects. Using Multiple Renderers describes this process in more detail.

Objects that are rendered on a map can respond to mouse clicks by implementing the IMapMouseHandler interface. This provides for the ability to HitTest an object, that is, to check whether an object lies under the mouse co-ordinates generated by a mouse click. By hit-testing objects in a RendererList, a map can determine which object should handle a mouse click.

Related Classes
Next Topic