Documentation

Override the mapClick Event

Overriding the map click is a fundamental skill in developing with Micello maps. The map click event sends information about the user's click to a callback function, including the click location and details about what was clicked. By overriding this callback the developer can get access to this information and use it to make their application more interactive.

First, a look at how to override the mapClicked callback during initialization of a map:

micello.maps.init (apikey, mapInit);
function  mapInit() {
    var mapControl =  new micello.maps.MapControl('mapElement');
    var mapDataObject = mapControl.getMapData();
    mapControl.onMapClick = onMapClick; // specify an override
    mapDataObject.loadCommunity(15);
}

Then, an example of what a custom callback function might look like:

function onMapClick (mx, my, clicked) {
    alert(mx+", "+my); // mx and my are always available
    if (clicked) { // check that a clicked object is present
        alert(clicked.id);
    }
}

Three values are passed as function argument:

mx - (int) the x coordinate of the click
my - (int) the y coordinate of the click
clicked - (object) the clicked geometry or overlay object
The 'mx' and 'my' values are often useful in development, especially for drawing custom geometries or placing marker overlays on the map.

If a geometry or overlay has been clicked, the 'clicked' object will contain several interesting properties. The properties included are:

id - the geometry id
nm - the name assosciated with the geometry
t - the type of geometry
Overriding the map click will prevent the 'default select action' ( the standard result a user expects ) from happening. It can be preserved by adding defaultSelectAction() to the override:

function onMapClick (mx, my, clicked) {
    if (clicked) {
        // do something with what was clicked
        // then, do the default select action too
        mapControl.defaultSelectAction(clicked);
    }
}