O'Reilly logo

OpenLayers Cookbook by Antonio Santiago Perez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a custom control

OpenLayers has plenty of controls that address a broad range of needs. Unfortunately, the requirements we could have for building a new web application can imply the creation of a new one, or the extension of a previous one:

Creating a custom control

In this recipe, we are going to create a new control named Cross. The control will show a crosshair symbol, as shown in the previous screenshot, similar to the target selectors in the ancient war planes, which will show the location it is pointing to. In addition, the control will allow registering the click events that will return the current location too.

How to do it...

  1. Create an HTML file and add ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required