if(!Twi.isObject("carte")){ Twi.addObject("carte"); Twi.carte = new function() { /********************************************************/ /* Core */ /********************************************************/ var name = "carte"; this.imagecentre = Twi.options.sourceScript + Twi.options.client +"-"+ Twi.options.key +"/carte/images/marker/marker_centre.png"; this.map = {}; this.streetview = {}; this.setIconeCentre = function (url){ this.imagecentre = url; } this.scriptgoogle = function (fct,key){ if(!Twi.apigoogle){ Twi.apigoogle = true; var cssFile = "https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"; var jsFile = "https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"; document.head.innerHTML = document.head.innerHTML + ''; var script = document.createElement("script"); if (script.readyState){ script.onreadystatechange = function(){ if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; setTimeout(fct+"()", 500); var scriptFS = document.createElement("script"); scriptFS.src = 'https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js'; document.getElementsByTagName("head")[0].appendChild(scriptFS); } }; }else{ script.onload = function(){ setTimeout(fct+"()", 500); var scriptFS = document.createElement("script"); scriptFS.src = 'https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js'; document.getElementsByTagName("head")[0].appendChild(scriptFS); }; } script.src = jsFile; document.getElementsByTagName("head")[0].appendChild(script); var linkFS = document.createElement("link") linkFS.rel = 'stylesheet'; linkFS.href = 'https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/leaflet.fullscreen.css'; document.getElementsByTagName("head")[0].appendChild(linkFS); var link = document.createElement("link") link.rel = 'stylesheet'; link.href = cssFile; document.getElementsByTagName("head")[0].appendChild(link); }else{ if (!window['google']) { window['google'] = {}; } if (window['google']['maps']) { setTimeout(fct+"()", 500); }else{ setTimeout('Twi.carte.scriptgoogle("'+fct+'")', 500); } } } this.init = function (key) { if(key === undefined) key = ''; Twi.setWindowsOnload(function(){ Twi.carte.scriptgoogle("Twi.carte.initMap", key); }); } this.zoneTagCacher = function (id_carte,tagcacheid){ if(!this.map[id_carte].option.tagcacheid){ this.map[id_carte].option["tagcacheid"] = tagcacheid; } } this.resizeCarte = function(id){ //google.maps.event.trigger(document.getElementById('tw_carte_'+id), 'resize'); } this.div2parties = function(div){ var divmap = document.createElement('div'); divmap.id = "tw_carte_"+div.id; divmap.className = "tw_carte"; div.appendChild(divmap); attribut = Twi.getAttributes(div); if(attribut["supprimerLegendeTwimmo"]){ if(attribut["supprimerLegendeTwimmo"].value=="Oui"){ return { markers : {} , map : {}, carte : divmap, option : {} }; } } var divlegende = document.createElement('div'); divlegende.id = "tw_legende_"+div.id; divlegende.className = "tw_legende"; div.appendChild(divlegende); return { markers : {} , map : {}, carte : divmap, legende : divlegende, option : {}, bien : {} }; } this.insereDiv = function (id) { if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++){ this.map[arguments[i]] = this.div2parties(this.chercherElement(arguments[i])); } return true; } if(this.isString(id)){ this.map[id] = this.div2parties(this.chercherElement(id)); return true; } return false; } this.initMap = function (){ try { for (var property in this.map){ var myLatlng = [46.22,2.21]; var myOptions = { zoom: 5, center: myLatlng, mapTypeId: 'ROADMAP' } attribut = this.getAttributes(property); if(attribut["lng"]){ lng = attribut["lng"].value;}else{ lng = "";} if(attribut["lat"]){ lat = attribut["lat"].value;}else{ lat = "";} if(attribut["minimumZoom"]){ this.map[property].option["minZoom"]=parseInt(attribut["minimumZoom"].value,10); } if(attribut["maximumZoom"]){ this.map[property].option["maxZoom"]=parseInt(attribut["maximumZoom"].value,10); } if(attribut["echelle"]){ if(attribut["echelle"].value=="Oui"){ myOptions["scaleControl"]= true; } } if(attribut["streetview"]){ if(attribut["streetview"].value=="Oui"){ myOptions["streetViewControl"]= true; }else{ myOptions["streetViewControl"]= false; } }else{ myOptions["streetViewControl"] = true; } if(attribut["zoom"]){ myOptions["zoom"] = parseInt(attribut["zoom"].value,10); }else{ myOptions["zoom"] = 5; } if(attribut["mapTypeId"]){ myOptions["mapTypeId"] = eval(attribut["mapTypeId"].value); } if(attribut["lng"] && attribut["lat"]){ var latlng = [attribut["lat"], attribut["lng"]]; myOptions["center"] = latlng; } if(attribut["supprimerGuiDefaut"]){ if(attribut["supprimerGuiDefaut"].value=="Oui"){ myOptions["disableDefaultUI"]= true; } } if( attribut["adresse"] || attribut["cp"] || attribut["ville"] || attribut["pays"] ){ if(attribut["adresse"]){ adresse=attribut["adresse"].value; adresse=adresse.replace("'", " "); }else{ adresse=""; } if(attribut["cp"]){ cp=attribut["cp"].value; cp=cp.replace("'", " "); }else{ cp=""; } if(attribut["ville"]){ ville=attribut["ville"].value; ville=ville.replace("'", " "); }else{ ville=""; } if(attribut["pays"]){pays=attribut["pays"].value;}else{pays="France";} this.adresseToGPS(property,myOptions,adresse,cp,ville,pays,myOptions["zoom"]); }else{ this.insercarte(property,myOptions); } } }catch(err){ setTimeout("Twi.carte.initMap()", 500); } } this.insercarte = function (id_carte,myOptions){ var cartevisite = true; var cartestyle; if(this.map[id_carte].option["tagcacheid"]){ cartestyle = document.getElementById(this.map[id_carte].option["tagcacheid"]); if(cartestyle.style.display == "none"){ cartestyle.style.display="block"; cartevisite = false; } } //Map Twi.carte.map[id_carte].map = L.map(Twi.carte.map[id_carte].carte,{fullscreenControl: {pseudoFullscreen: false}}).setView([myOptions.center[0],myOptions.center[1]], 10); //new google.maps.Map(Twi.carte.map[id_carte].carte, myOptions); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: ' OpenStreetMap | Twimmo Pro' }).addTo(Twi.carte.map[id_carte].map); /*var logo = document.createElement('img'); logo.src="https://api.twimmo.com/images/logoPf.png"; logo.style.width="63px"; logo.style.margin="0px"; var lien = document.createElement('a'); lien.href = "https://www.twimmo.com"; lien.title = 'En partenariat avec Twimmo'; lien.appendChild(logo); lien.target = '_blank'; var homeControlDiv = document.createElement('DIV'); homeControlDiv.appendChild(lien); homeControlDiv.index = 1; Twi.carte.map[id_carte].map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(homeControlDiv);*} //Gestion de Event {*google.maps.event.addListener(Twi.carte.map[id_carte].map, 'zoom_changed', function(){ zoomChangeBoundsListener = google.maps.event.addListener(Twi.carte.map[id_carte].map, 'bounds_changed', function(event) { //if (Twi.carte.map[id_carte].map.getZoom() > 16){ // Twi.carte.map[id_carte].map.setZoom(16); //} google.maps.event.removeListener(zoomChangeBoundsListener); }); if(Twi.isNumber(Twi.carte.map[id_carte].option["minZoom"])){ if (Twi.carte.map[id_carte].map.getZoom() < Twi.carte.map[id_carte].option["minZoom"]) { Twi.carte.map[id_carte].map.setZoom(Twi.carte.map[id_carte].option["minZoom"]); } } if(Twi.isNumber(Twi.carte.map[id_carte].option["maxZoom"])){ if (Twi.carte.map[id_carte].map.getZoom() > Twi.carte.map[id_carte].option["maxZoom"]) { Twi.carte.map[id_carte].map.setZoom(Twi.carte.map[id_carte].option["maxZoom"]); } } Twi.carte.mouvementCarte(id_carte); }); Twi.carte.map[id_carte].map google.maps.event.addListener(Twi.carte.map[id_carte].map, 'drag', function() { Twi.carte.mouvementCarte(id_carte); });*/ //google.maps.event.trigger(Twi.carte.map[id_carte].map, 'resize'); Twi.carte.map[id_carte].map.on('zoomend', function() { Twi.carte.mouvementCarte(id_carte); }); Twi.carte.map[id_carte].map.on('moveend', function() { Twi.carte.mouvementCarte(id_carte); }) //Marker Twi.carte.map[id_carte].bien = Twi.carte.setMarkers(id_carte,myOptions["center"],"","",Twi.carte.imagecentre,this.options.sourceScript + this.options.client +"-"+ this.options.key +"/carte/images/marker/marker_shadow.png"); if(!cartevisite){ window.setTimeout(function() { cartestyle.style.display = "none"; }, 500); } } /********************************************************/ /* Legende */ /********************************************************/ this.initcarteLegende = function (){ for (var property in this.map){ if(this.map[property].legende){ var data ={ id_div : this.map[property].legende.id, id_carte : property }; this.execute ("carte","core/legende",data); } } } this.clicLegende = function(valeur,etat){ var reg=new RegExp("[\|]+", "g"); var tableau=valeur.split(reg); if(etat){ var reg=new RegExp("[\|]+", "g"); var tableau=valeur.split(reg); var data ={ id_carte : tableau[0], type : tableau[1], lat : this.map[tableau[0]].map.getCenter().lat, lng : this.map[tableau[0]].map.getCenter().lng }; this.execute ("carte","flux/poi",data); }else{ this.supprimerMarker(tableau[0],tableau[1]); } } /********************************************************/ /* Marker */ /********************************************************/ this.mouvementCarte = function(id_carte){ var carte = this.map[id_carte]; for (var property in carte.markers){ var data ={ id_carte : id_carte, type : property, lat : carte.map.getCenter().lat, lng : carte.map.getCenter().lng }; this.execute ("carte","flux/poi",data); } } this.constuireMarker = function(id_carte,type,data){ var img = this.options.sourceScript + this.options.client +"-"+ this.options.key +"/carte/images/marker/marker_"+type+".png"; var imgombre = this.options.sourceScript + this.options.client +"-"+ this.options.key +"/carte/images/marker/marker_shadow.png"; for (var property in data){ var reg=new RegExp("[-]+", "g"); var tableau=property.split(reg); var type = tableau[0]; var id = tableau[1]; if(!this.map[id_carte].markers[type]){ this.map[id_carte].markers[type]= {}; } if(!this.map[id_carte].markers[type][id]){ var latlng = [data[property].lat,data[property].lng]; this.map[id_carte].markers[type][id] = this.setMarkers(id_carte,latlng,data[property].titre,data[property].html,img,imgombre); } } } this.setMarkers = function (id_carte,latlng,titre,html,img,imgombre) { var options = {}; if(img){ options.icon = L.icon({ iconUrl: img, iconSize: [25,45], iconAnchor: [12,45], shadowUrl: imgombre, shadowSize: [25,45], shadowAnchor: [7,45], }); } var marker = L.marker(latlng, options).addTo(this.map[id_carte].map); if(html){ marker.bindPopup("