Deep Map SDK Web
This tutorial will show you how you can handle taps on the map. The SDK will handle those clicks for you and return the corresponding geographic feature (geometry) at the tapped point via a callback. In addition, you can use the queryPoint if the SDK can not find a geographic feature at the tap point.
Step 1: Register a tap handler
After creating a web map, as outlined in "A Map Application", you can register a tap handler in the map init success callback:
This tap handler must to be previously defined, as shown here:
That's it! You are now able to click on the map, look in the Console, and see the backend logs.
To have a little bit more fun, read further!
Step 2: Give this tap handler more power
In order to do more with a given geometry, we can enhance the tap handler:
- We now use some helper methods:
- Clean up all former activity.
- Get the "current" feature.
- Check if we are in an "Overview" zoom level. If yes, check if the feature is an area. If yes, zoom to it.
- If we are on a "Detail" zoom level, append a message with the feature properties to the log and highlight the feature
- If nothing was found, append an error message to the log
In order to clean up all activity from previous taps, use the following method:
Here are the methods used to get the "current" feature:
The following methods show a feature dialog and extend the log:
Let us add some HTML and style to this example!
You have created a fully featured tap handler. If a user clicks on a building on your map, the map will zoom to this building. If the map is already zoomed to a zoom level lower than 2, a click on a room or booth will highlight this room/booth (see step 4 for details).