HOME BLOG

MAPAS API

Galeria de exemplos: Eventos do mapa

Este exemplo demonstra como se poderá utilizar alguns dos eventos disponíveis no controlador. Para ver este exemplo a funcionar, efectue as seguintes acções sobre o mapa:
- Clique
- Mover o mapa
- Zoom

				<html>
					<head>
						<title>Map Simple Event</title>
						<script type="text/javascript" src="http://js.sapo.pt/Bundles/SAPOMapsAPI.js"></script>
						<script type='text/javascript'>
							
							var map = false;
							function init() { 
								map = new SAPO.Maps.Map('mapDiv');
								
								map.events.register('click', this, clicked);
								map.events.register('zoomend', this, zoomend);
								map.events.register('movestart', this, movestart);
								map.events.register('moveend', this, moveend);
							}
							
							function clicked(evt){
								var lonlat = map.getLonLatFromContainerPixel(evt.xy);
								var msg = 'You clicked at pixel: x= ' + evt.xy.x + ' y = ' + evt.xy.y + ' and lon = ' + lonlat.lon + ' lat = ' + lonlat.lat;
								writeMsg(msg);
							}
							
							function movestart(evt){
								writeMsg('starting move');
							}
							
							function moveend(){
								writeMsg('move ended');
							}
							
							function zoomend(){
								writeMsg('zoomed end');
							}
							
							function writeMsg(msg){
								var panel = document.getElementById('msgs');
								panel.innerHTML += msg + '<br/>'
							}
							
						</script>
					</head>
					<body onload='init();'>
						<div id='mapDiv' style='width:980px; height:400px;'></div>
						<div id='msgs'></div>
					</body>
				</html>