﻿// 15 MALIGNE  //
   
   // Map & Pano delcarations
	google.load("maps", "2");
    var map;
    var myPano;   
    var panoClient;
    var currentLatLng = new GLatLng(45.828141,1.26138);
	var imoLatLng = new GLatLng(45.827841,1.26178);
    var currentYaw = 120;
	var imgSrc = "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/images/residence.png";
   
   // Field of view marker and icon declarations
    var fovMarker; 
    var fovIcon = new GIcon(G_DEFAULT_ICON);
    var iconSize = 150; 
    
    var imoMarker; //marker pour icone imobilier
    var imoIcon = new GIcon(G_DEFAULT_ICON);    	
	
   function initialized1(chosen) {
	panoClient = new GStreetviewClient(); 
	     
	map = new GMap2(document.getElementById("street1"));
	map.addControl(new GLargeMapControl3D);
	map.addControl (new GScaleControl);
	map.setCenter(currentLatLng, 17);
	myPano = new GStreetviewPanorama(document.getElementById("view1"));
	myPano.setLocationAndPOV(currentLatLng, {yaw:currentYaw, pitch:0});
			
	fovIcon.image = "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/demoicon.php?yaw=180";		
	fovIcon.iconSize = new GSize(iconSize, iconSize);
	fovIcon.iconAnchor = new GPoint(iconSize/2, iconSize/2); //anchor in the middle
	fovIcon.shadow = null;
	fovMarker = new GMarker(currentLatLng, {icon: fovIcon, clickable: false})		
	GEvent.addListener(myPano, "initialized", handleInitialized); 
	GEvent.addListener(myPano, "yawchanged", handleYawChange);
	
	/*icone immo*/
	imoIcon.image = imgSrc;
	imoIcon.shadow = null;
	imoIcon.iconSize = new google.maps.Size(20,20);
	imoMarker = new GMarker(imoLatLng, {icon: imoIcon, clickable: false})		
	return;
}
function handleInitialized(location) {
	currentLatLng = location.latlng;	
	placeFovMarker();
	return;	
}
function handleYawChange(yaw){
	currentYaw = Math.round(yaw);
	placeFovMarker();
	return;
} 
function placeFovMarker(){
	map.removeOverlay(fovMarker);
	/* The following line really only needs to be in handleYawChange(), but doing so creates a flicker of the marker 
	* when using Firefox.  It may have something to do with the lag between when the initialized event is triggered
	* and when the Street View image is actually finished loading. Although less than optimal, I've found that 
	* reloading the image for each placement avoids the problem.
	*/
fovIcon.image = "http://www.limoges-locations.fr/wp-content/themes/limoges-locations/demoicon.php?yaw="+currentYaw+"&rand="+Math.random();	
	fovMarker = new GMarker(currentLatLng, {icon: fovIcon, clickable: false});
	map.addOverlay(fovMarker);
	map.addOverlay(imoMarker);
	map.setCenter(currentLatLng);
	return;
}
google.setOnLoadCallback(initialized1);
