<?
$_pageTitle="A Norma de Granada em Évora";
$_nav="Mapa da Cidade";
$theMarker=isset($_GET['nr'])?$_GET['nr']:"";
include("inc/_start.php");
?>
	<div id="main">		
		<div id="map"></div>
	</div>
	
	
	<script>	
		var map;
		var theMarker=null;
		var lastWindowOpen=null;
		function addCommas(nStr){
			nStr += '';
			x = nStr.split('.');
			x1 = x[0];
			x2 = x.length > 1 ? ',' + x[1] : '';
			var rgx = /(\d+)(\d{3})/;
			while (rgx.test(x1)) {
				x1 = x1.replace(rgx, '$1' + '.' + '$2');
			}
			return x1 + x2;
		}
		
		function placePin(lat,lon){
			var image = 'img/marker_arv.png';				
			var myLatLng = new google.maps.LatLng(lat, lon);
			var marker = new google.maps.Marker({
					position: myLatLng,
					map: map,
					icon: image
			});
			var contentString = '<div class="infoWindow">'+
					'<h2>Árvore em tal sítio</h2>'+
					'<p>Parágrafo de texto sobre a árvore em tal sítio com várias linhas e que serve para escrever um texto mais ou menos longo.</p>'+
					'<div class="footer"><a href="maisinfo.html">+ info</a></div>'+
					'</div>';

			var infowindow = new google.maps.InfoWindow({
					content: contentString
			});
			google.maps.event.addListener(marker, 'click', function() {
				infowindow.open(map,marker);
			});
		}
		
		function pinaArvore(obj){
			if (obj.latitude==null || obj.longitude==null){
				return;
			}
			
			var image = 'img/marker_arv.png';				
			var myLatLng = new google.maps.LatLng(obj.latitude, obj.longitude);
			var marker = new google.maps.Marker({
					position: myLatLng,
					map: map,
					icon: image
			});
			var ficheiro="";
			
for(idx=0;idx<fichasTecnicas.length;idx++){

				if (fichasTecnicas[idx].nome.substr(0,obj.especie.length).toLowerCase()==obj.especie.toLowerCase()){
					ficheiro=fichasTecnicas[idx].ficheiro;
					idx=fichasTecnicas.length;
				}

			}

			var contentString = '<div class="infoWindow">'+
					'<h2><a href="'+ficheiro+'" class="especieBtn">'+obj.especie+'</a><div class="infoNr">'+obj.nr+'</div></h2>'+
					'<h3><a href="'+ficheiro+'" class="especieBtn">'+obj.nomeComum+'</a></h3>'+
					'<p>'+
					'<table>'+
					'<tr><th>Localização</th><td>'+obj.local+'</td></tr>'+
					'<tr><th>PAP</th><td>'+obj.pap + '&nbsp;cm</td></tr>'+
					'<tr><th>Factor intrínseco (Els)</th><td>'+obj.els + '</td></tr>'+
					'<tr><th>Factor extrínseco (Ele)</th><td>'+obj.ele + '</td></tr>'+
					'<tr><th>Valor final (V<sub>f</sub>)</th><td>'+obj.valorFinal + '</td></tr>'+
					'</table></p>'+
					'<div class="footer"><a href="fichaarvore.php?nr='+obj.nr+'">+ info</a></div>'+
					'</div>';

			var infowindow = new google.maps.InfoWindow({
					content: contentString
			});
			
			google.maps.event.addListener(marker, 'click', function() {
				if (lastWindowOpen) lastWindowOpen.close();
				lastWindowOpen=infowindow;
				infowindow.open(map,marker);
			});
			if (obj.nr=="<?=$theMarker;?>"){
				theMarker=marker;
			}
		}
		
		function placeMarkersOnMap(){
			for (i=0;i<arArvores.length;i++){
				//console.debug(arArvores[i]);
				pinaArvore(arArvores[i]);
			}
			
		}
		
    function initialize() {
		
			
			var myOptions = {
				zoom: 15,
				center: new google.maps.LatLng(38.57, -7.907),
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				styles:
				[
					{
						featureType: "poi.business",
						elementType: "labels",
						stylers:
						[
								{
										visibility: "off"
								}
						]
					},
					{
						featureType: "poi.place_of_worship",
						elementType: "labels",
						stylers:
						[
								{
										visibility: "off"
								}
						]
					},
					{
						featureType: "administrative.locality",
						elementType: "labels",
						stylers:
						[
								{
										visibility: "off"
								}
						]
					},
					{
						featureType: "road",
						stylers: [
							{ visibility: "simplified" }							
						]
					},
					{
						featureType: "road.arterial",
						stylers: [
							{ hue: "#fff700" },
							{ saturation: -100 },
							{ lightness: 40 }
						]
					},{
						featureType: "road.highway",
						stylers: [
							{ hue: "#fff700" },
							{ saturation: -96 },
							{ lightness: 40 }
						]
					},{
						featureType: "road",
						elementType: "labels",
						stylers: [
							{ hue: "#0022ff" },
							{ visibility: "on" },
							{ gamma: 0.7 }
						]
					}
					/*
					// http://gmaps-samples-v3.googlecode.com/svn/trunk/styledmaps/wizard/index.html
					{
						featureType: "road",
						stylers: [
							{ visibility: "simplified" },
							{ hue: "#ff0000" },
							{ saturation: -100 }
						]
					},
					{
						featureType: "landscape.man_made",
						stylers: [
							{ visibility: "simplified" },
							{ hue: "#ff00aa" },
							{ lightness: 65 },
							{ saturation: 25 }
						]
					}
					*/
				]
			};
			map = new google.maps.Map(document.getElementById('map'),myOptions);
			
			placeMarkersOnMap();
			if (theMarker!=null){
				google.maps.event.trigger(theMarker, 'click', {
				  latLng: new google.maps.LatLng(0, 0)
				});
				map.setZoom(18);
				var p=theMarker.getPosition();
				console.debug(p.lat());
				p=new google.maps.LatLng(p.lat()+0.0005,p.lng());
				console.debug(p.lat());
				map.setCenter(p);
			}
		}
		
		
		google.maps.event.addDomListener(window, 'load', initialize);
		
		/*
		administrative	Apply the rule to administrative areas.
		administrative.country	Apply the rule to countries.
		administrative.land_parcel	Apply the rule to land parcels.
		administrative.locality	Apply the rule to localities.
		administrative.neighborhood	Apply the rule to neighborhoods.
		administrative.province	Apply the rule to provinces.
		all	Apply the rule to all selector types.
		landscape	Apply the rule to landscapes.
		landscape.man_made	Apply the rule to man made structures.
		landscape.natural	Apply the rule to natural features.
		poi	Apply the rule to points of interest.
		poi.attraction	Apply the rule to attractions for tourists.
		poi.business	Apply the rule to businesses.
		poi.government	Apply the rule to government buildings.
		poi.medical	Apply the rule to emergency services (hospitals, pharmacies, police, doctors, etc).
		poi.park	Apply the rule to parks.
		poi.place_of_worship	Apply the rule to places of worship, such as church, temple, or mosque.
		poi.school	Apply the rule to schools.
		poi.sports_complex	Apply the rule to sports complexes.
		road	Apply the rule to all roads.
		road.arterial	Apply the rule to arterial roads.
		road.highway	Apply the rule to highways.
		road.highway.controlled_access	Apply the rule to controlled-access highways.
		road.local	Apply the rule to local roads.
		transit	Apply the rule to all transit stations and lines.
		transit.line	Apply the rule to transit lines.
		transit.station	Apply the rule to all transit stations.
		transit.station.airport	Apply the rule to airports.
		transit.station.bus	Apply the rule to bus stops.
		transit.station.rail	Apply the rule to rail stations.
		water
		*/
		
	</script>
<?
include("inc/_end.php");
?>