var logged = null; // logged user
var cdmappa; // id mappa su db
var deflat = 45;
var deflong = 9;
var defzoom = 3;
var map; // oggetto mappa
var geocoder = new google.maps.Geocoder(); // geocoder per indirizzi
var lastmarkerId = 0; // contatore marker aggiunti con i bottoni
var dimensionexpoint = 0; // per memorizzare dimensione panel editor punti
var dimensionexmap = 0; // per memorizzare dimensione panel laterale mappa
var templat = null; //per memorizzare le coordinate di partenza del punto che edito
var templng = null;
var tempico = null;
var temptestomappa = null;
var temptestopunto = null;
var iconDir = "http://www.maledettaprimavera.it/map/icons/";
var collapsedPanelWidth = 20; //pixel
var shadow = new google.maps.MarkerImage(iconDir + 'shadow.png',
// The shadow image is larger in the horizontal dimension
// while the position and offset are the same as for the main image.
new google.maps.Size(38, 34),
new google.maps.Point(0,0),
new google.maps.Point(12, 32));
/* per accedere ai markers */
google.maps.Map.prototype.markers = new Array();
google.maps.Map.prototype.getMarkers = function() {
return this.markers
};
google.maps.Map.prototype.clearMarkers = function() {
for(var i=0; i < this.markers.length; i++){
this.markers[i].setMap(null);
}
this.markers = new Array();
};
google.maps.Marker.prototype._setMap = google.maps.Marker.prototype.setMap;
google.maps.Marker.prototype.setMap = function(map) {
if (map) {
map.markers[map.markers.length] = this;
}
this._setMap(map);
}
/* fine prototipazione metodi per accedere ai markers */
/* geocoding chiamato durante il dragging */
function geocodePosition(pos) {
geocoder.geocode({
latLng: pos
}, function(responses) {
if (responses && responses.length > 0) {
updateMarkerAddress(responses[0].formatted_address);
} else {
updateMarkerAddress("Geocode cant' determine the address.");
}
});
}
/* funzioni per aggiornare il box di info */
function updateMarkerStatus(str) {
$('#markerStatus').html (str);
}
function updateMarkerPosition(latLng) {
$('#info').html ( [
convertDecDeg ( latLng.lat(),'N' ),
convertDecDeg ( latLng.lng(),'E' )
].join(' ') );
}
function updateMarkerAddress(str) {
$('#address').html (str);
}
/* fine funzioni per aggiornare il box di info */
/* inizializzazione mappa, chiamata al load della pagina */
function initialize() {
var myOptions = {
zoom: defzoom,
center: new google.maps.LatLng(deflat, deflong) ,
mapTypeId: google.maps.MapTypeId.TERRAIN,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
/* caricamento dei punti da xml esterno */
/* ai punti viene assegnato solo lat, lgn e id e viene aggiunto evento click */
function loadmappa(id) {
map.clearMarkers();
$('#infomappa').show();
$('#infomappa').html("
Loading...");
var strInfoMappa = "";
var doneMappa = false;
var donePunti = false;
jQuery.get("ajax.loaddatimappa.php?id="+id+"&rand=" + Math.random(), {}, function(data) {
//alert(data);
//todo: caricare dati nell'html e abilitare il pulsante
//modifica se è l'autore corrente
var obj = $.evalJSON(data);
map.setCenter(new google.maps.LatLng(parseFloat(obj.lat), parseFloat(obj.lng)));
//alert(obj.zoom);
var t = google.maps.MapTypeId.ROADMAP;
if (obj.typ == 0) t = google.maps.MapTypeId.SATELLITE;
if (obj.typ == 1) t = google.maps.MapTypeId.ROADMAP;
if (obj.typ == 2) t = google.maps.MapTypeId.HYBRID;
if (obj.typ == 3) t = google.maps.MapTypeId.TERRAIN;
map.setMapTypeId( t );
var modstr = "";
if (logged == obj.auth)
{
modstr = "edit";
}
strInfoMappa = "
Loading...");
jQuery.get("ajax.loaddatimappa.php?id="+ii+"&rand=" + Math.random(), {}, function(data) {
//if ( $('#addplaceaddressdiv').is(':visible') ) toggleeditorpoint();
var obj = $.evalJSON(data);
$('#titolo').val(obj.nome);
$('#tipomap').val(obj.typmap);
$('#descrizmap').val(obj.testo0);
$('#formmappa').show();
$('#komappa').show();
$('#infomappa').hide();
$('#titolo').focus();
});
}
/* memorizza dimensione iniziale pannello di edit/ricerca dei punti */
function seteditorpointwidth() {
dimensionexpoint = $('#editorpoint').width();
$('#editorpoint').css("width",dimensionexpoint + "px");
$('#listapunti').css("height", $('#map_canvas').height() + "px");
$('#toolsdiv').css("height", $('#map_canvas').height() + "px");
$('#addmapdiv').css("height", $('#map_canvas').height() + "px");
$('#helpdiv').css("height", $('#map_canvas').height() + "px");
//$('#listamappe').css("height", $('#map_canvas').height()-20 + "px");
$('#formpunto').hide("fast");
$('#searchContainer').show("slow");
}
/* memorizza dimensione iniziale pannello di gestione mappa */
function seteditormapwidth() {
dimensionexmap = $('#editormap').width();
$('#editormap').css("width",dimensionexmap + "px");
}
/* apro-chiudo pannello laterale editor dei punti */
function toggleeditorpoint(start) {
if (!start)
{
if ( $('#formpunto').is(':visible') ) { alert("You're editing a point, please save it or cancel.") ; return ; }
if ( !cdmappa ) { alert("caricare o creare una mappa prima di aprire il pannello.") ; return ; }
}
if ($('#editorpoint').width() == dimensionexpoint ) {
//chiudo
$('#ponoff').attr("class","poff");
var nuovo = $('#map_canvas').width() + dimensionexpoint - collapsedPanelWidth;
$('#editorpoint').css("width",collapsedPanelWidth + "px");
$('#map_canvas').css("width", nuovo + "px");
$('#addplaceaddressdiv').hide();
} else {
//apro
$('#ponoff').attr("class","pon");
var nuovo = $('#map_canvas').width() - dimensionexpoint + collapsedPanelWidth;
$('#editorpoint').css("width",dimensionexpoint + "px");
$('#map_canvas').css("width", nuovo + "px");
$('#addplaceaddressdiv').show();
}
google.maps.event.trigger(map, 'resize') ;
}
/* apro-chiudo pannello laterale editor della mappa*/
function toggleeditormap() {
if ($('#editormap').width() == dimensionexmap ) {
//chiudo
$('#monoff').attr("class","poff"); //linguetta
var nuovo = $('#map_canvas').width() + dimensionexmap - collapsedPanelWidth;
$('#editormap').css("width",collapsedPanelWidth + "px");
$('#map_canvas').css("width", nuovo + "px");
$('#toolsdiv').hide();
$('#addmapdiv').hide();
$('#helpdiv').hide();
$("a[class=lang]").hide();
$("a[class=lang first]").hide();
$("a[class=tabon]").hide();
$("a[class=taboff]").hide();
} else {
//apro
$('#monoff').attr("class","pon");
var nuovo = $('#map_canvas').width() - dimensionexmap + collapsedPanelWidth;
$('#editormap').css("width",dimensionexmap + "px");
$('#map_canvas').css("width", nuovo + "px");
if ( $('#toolstab').attr('class')=="tabon") $('#toolsdiv').show();
if ( $('#addmaptab').attr('class')=="tabon") $('#addmapdiv').show();
if ( $('#helptab').attr('class')=="tabon") $('#helpdiv').show();
$("a[class=lang]").show();
$("a[class=lang first]").show();
$("a[class=tabon]").show();
$("a[class=taboff]").show();
}
google.maps.event.trigger(map, 'resize') ;
}
function cercaico(n,tmp) {
var s
if (n) s = n; else s = $('#findico').val();
if (s.length>0)
{
$('#iconz').html("
Loading...");
if (tmp) {
url = "ajax.findicon.php?tmp=&q=" + escape(s);
} else {
url = "ajax.findicon.php?q=" + escape(s);
}
jQuery.get(url, {}, function(data) {
$('#iconz').html(data);
}
);
}
}
function newmap() {
if (!logged) { alert("non sei loggato"); return; }
cdmappa = null;
lastmarkerId = 0;
map.clearMarkers();
map.setCenter ( new google.maps.LatLng(deflat, deflong) );
map.setZoom ( defzoom );
vai_info_mappa();
$('#infopunto').html("");
$('#listapunti').html("");
if ( $('#addplaceaddressdiv').is(':visible') ) toggleeditorpoint();
$('#modnewmaplabel').html("New");
$('#formmappa').show();
$('#infomappa').hide();
$('#titolo').val("");
$('#descrizmap').val("");
$('#tipomap').val(0);
$('#titolo').focus();
}
function switchtabs(n) {
$('#toolstab').attr("class","taboff");
$('#addmaptab').attr("class","taboff");
$('#helptab').attr("class","taboff");
$('#'+n+'tab').attr("class","tabon");
$('#toolsdiv').hide();
$('#addmapdiv').hide();
$('#helpdiv').hide();
$('#'+n+'div').show();
void(0);
}
function logout(){
$.post('ajax.logout.php', {user: logged}, function(res){
if (res=="OK")
{
logged = null;
document.location.href=document.location.href;
} else alert(res);
});
}
function vai_info_mappa() {
$('#mappa_corrente_fs').show();$('#listamappe_fs').hide();
}
function vai_elenco_mappa() {
$('#mappa_corrente_fs').hide();$('#listamappe_fs').show();$('#embed_fs').hide();
if (cdmappa) {
if (logged) $('#vaiinfobutt').val("Info & edit"); else $('#vaiinfobutt').val("Info");
} else {
$('#vaiinfobutt').val("Info");
}
}
function uploadico() {
$('#nomefile').html("
Loading...");
$('#uploadicoform').submit();
}
function showicouploaded(s) {
cercaico(s,"tmp");
$('#nomefile').html(s);
}
var poly = null;
function drawPoly() {
if (poly) {poly.setMap(null); poly = null; return }
var a = new Array();
var b = new Array();
a = map.getMarkers();
for(var i=0; i