Click or drag to resize

Linking the Two

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

The final step is to set up the user interface to use the renderer we have defined. First we need to tell the map to use our renderer, and then we need to add some way for the user to add points to our renderer.

Setting the Renderer for the Map

In the constructor of the form, below the call to InitializeComponent add this code to set the renderer for our map.

C#
mapCtrl1.Renderer = new PointRenderer();

Now whenever the map is redrawn, the Render method of our PointRenderer will be called. However, because the renderer currently has no points nothing will be drawn.

Adding User Interaction

Go back into the Form Designer and select the MapCtrl. In the properties window, click the Events tab (the lightning bolt). Double click MouseUp to add a MouseUp event handler to the MapCtrl. Add the following code to the event handler to get the current mouse position and add a point to the point renderer when the right mouse button is clicked.

C#
private void mapCtrl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
  if (e.Button == MouseButtons.Right) {
    Point mouse = mapCtrl1.PointToClient(new Point(e.X, e.Y));
    Telogis.GeoBase.LatLon mouse_ll = mapCtrl1.XYtoLatLon(e.X, e.Y);
    (mapCtrl1.Renderer as PointRenderer).AddPoint(mouse_ll);
    mapCtrl1.Invalidate();
  }
}
Note Note

The call to Invalidate ensures that the map gets redrawn.

Testing

That is all that is required to make this basic renderer run. Run your application now. Try right clicking on the map. A blue dot should appear where you click, as you pan around the map that dot will stay in the same geographical location. As you zoom out you will reach a point where the dots become invisible when the zoom goes over the threshold we set earlier.