var map; var hide_map = false; var centerPoint = new GLatLng(2.811371, 22.500000); var closedBox = true; var country_id = true; var dont_load_country = false; var dont_load_country_city = false; var country_name = ""; function doLoad() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); map.setCenter(centerPoint , 3, map.getMapTypes()[0]); map.enableDoubleClickZoom(); map.enableContinuousZoom(); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); GeoMapHome(); } } window.onload = function(){ doLoad(); }; function LoadCountry(id){ $("mapMessage").innerHTML = '

Loading Content...
'; var myRequest = new Request({ method: 'post', url: '/ajaxCountry/' + id + '/', onComplete: loadContent }).send(); } function LoadCountryCity(id){ $("mapMessage").innerHTML = '

Loading Content...
'; var myRequest = new Request({ method: 'post', url: '/ajaxCity/' + id + '/', onComplete: loadContent }).send(); } function loadContent(request){ if(closedBox == true){ $("mapMessage").style.display = "block"; var fadeFx = new Fx.Style("mapMessage", 'opacity', {wait: false, duration: 1000, onComplete:function(){ closedBox = false; }}).set(0); fadeFx.start(1); } $("mapMessage").innerHTML = request; $("mapMessageClose").removeEvents("click"); $("mapMessageClose").addEvent("click", closeMapMessage); } function closeMapMessage(){ var fadeFx = new Fx.Style("mapMessage", 'opacity', {wait: false, duration: 1000, onComplete:function(){ $("mapMessage").style.display = "none"; closedBox = true; }}).set(1); fadeFx.start(0); } function loadCity(request){ $("cityContainer").innerHTML= request; $('formCity').removeEvents("submit"); $('formCity').addEvent('submit', function(e) { e.stop(); this.set('send', {onComplete: function(response) { mapGoTo(country_id); }}); this.send(); }); } function GeoMapHome(){ dont_load_country = false; var sitMap = function(JSONModel){ map.clearOverlays() myModel = JSONModel; $("breadcountry").style.display = "none"; $("breadsep").style.display = "none"; JSONModel.each(function(row) { var countryPoint = new GLatLng(Number(row.fields.geo_x), Number(row.fields.geo_y)); var flag_icon = new GIcon(G_DEFAULT_ICON); flag_icon.image = '/static/img/pushpin.png'; flag_icon.iconSize = new GSize(32, 32); flag_icon.shadow = ''; flag_icon.iconAnchor = new GPoint(16,30); var marker = new GMarker(countryPoint,{icon: flag_icon,title:row.fields.title,draggable:false}); GEvent.addListener(marker,'dblclick',function(){ mapGoTo(row.pk); dont_load_country = true; closeMapMessage(); }); GEvent.addListener(marker,"click",function() { setTimeout(function(){ if(dont_load_country == false){ country_id = row.pk; LoadCountry(row.pk); } }, 500); }); map.addOverlay(marker); }); } var request = new Request.JSON({ url: '/admin/map/load/', onComplete: function(jsonObj) { sitMap(jsonObj); } }).send(); } function loadCityKML(city_id, country_name, city_name){ $("map").style.display = "none"; $("mapKML").style.display = "block"; $("mapMessage").style.display = "none"; $("mapKML").src = "/maps/" + city_id + "/"; $("breadcountry").innerHTML = '' + country_name + ' - ' + city_name + ' Settlements '; } function mapGoTo(country){ $("map").style.display = "block"; $("mapKML").style.display = "none"; $("mapMessage").style.display = "none"; closedBox = true; lock = false; country_id = country; dont_load_country_city = false; var sitMap = function(JSONModel){ map.clearOverlays() myModel = JSONModel; JSONModel.each(function(row) { var countryPoint = new GLatLng(Number(row.fields.geo_x), Number(row.fields.geo_y)); var flag_icon = new GIcon(G_DEFAULT_ICON); flag_icon.image = '/static/img/flag.png'; flag_icon.iconSize = new GSize(32, 32); flag_icon.shadow = ''; flag_icon.iconAnchor = new GPoint(3,30); var marker = new GMarker(countryPoint,{icon: flag_icon,title:row.fields.name,draggable:false}); GEvent.addListener(marker,'click',function(){ setTimeout(function(){ if(dont_load_country_city == false){ LoadCountryCity(row.pk); } }, 500); }); GEvent.addListener(marker,'dblclick',function(){ loadCityKML(row.pk, country_name, row.fields.name); dont_load_country_city = true; }); map.addOverlay(marker); }); } if(country == "nocountry"){ GeoMapHome(); map.setZoom(3); map.panTo(centerPoint); $("breadhome").style.fontWeight = "normal"; }else{ map.clearOverlays(); $("breadhome").style.fontWeight = "bold"; $("breadcountry").style.display = "block"; $("breadsep").style.display = "block"; var myRequest = new Request({ method: 'post', url: "/admin/ajaxCities/", onComplete: loadCity, }).send('id=' + country); var request = new Request.JSON({ method: 'post', url: "/admin/load/countryphoto/", onComplete: function(request){ var c=0; request.each(function(row) { if(c == 0){ if( row.fields.country_x != "" && row.fields.country_y != "" && row.fields.country_zoom != ""){ var photoPoint = new GLatLng(Number(row.fields.country_x), Number(row.fields.country_y)); map.setZoom(Number(row.fields.country_zoom)); map.panTo(photoPoint); $("breadcountry").removeEvents("click"); $("breadcountry").removeEvents("mouseover"); $("breadcountry").removeEvents("mouseleave"); $("breadcountry").addEvent("click", function(){ mapGoTo(row.pk); }); $("breadcountry").addEvent("mouseover", function(){ $("breadcountry").style.textDecoration = "underline"; }); $("breadcountry").addEvent("mouseleave", function(){ $("breadcountry").style.textDecoration = "none"; }); } } c = c + 1; }); }, }).send('id=' + country); var request = new Request.JSON({ url: '/admin/map/city/load/', onComplete: function(jsonObj) { sitMap(jsonObj); } }).send('id=' + country); var request = new Request.JSON({ url: '/admin/map/city/getcountry/', onComplete: function(request){ request.each(function(row) { country_name = row.fields.title; $("breadcountry").innerHTML = country_name; }); }, }).send('id=' + country); } }