Event Handler example
- Map resize
map.Event.bind('ready', function() { map.Event.bind('beforeResize', function() { alert('Map is going to resize'); }); });
- bind: Attach a handler to target event
- ready: Map is ready to use
- beforeResize: Map is going to resize can prevent default behavior
- Map location changed or zoom
map.Event.bind('location', function() { var location = map.location(); document.getElementById('status').innerHTML = 'Move: ' + location.lon + ', ' + location.lat; }); map.Event.bind('zoom', function() { document.getElementById('status').innerHTML = 'Zoom: ' + map.zoom(); });
- location: Map location changed event
- zoom: Zoom level changed event
ExampleMove or zoom to show event
- User click overlay
map.Event.bind('overlayClick', function(overlay) { if (overlay == marker1) { alert(overlay.message); } }); var marker1 = new longdo.Marker({ lon: 100.5, lat: 13.7 }); marker1.message = 'Click me'; map.Overlays.add(marker1);
- overlayClick: User click overlay event
- Routing guide complete
map.Event.bind('guideComplete', function(overlay) { document.getElementById('distance').innerHTML = map.Route.distance(true); }); map.Route.add(marker1); map.Route.add({ lon: 101, lat: 14 }); map.Route.search();
- guideComplete: Routing guide complete
More information: Event Handler