Api Google - kml

Stato
Chiusa ad ulteriori risposte.

lugalzaggesi

Nuovo Utente
1 Apr 2014
11
0
3
Buongiorno a tutti e scusate il disturbo.
Il script funziona ma vorrei dare la possibilità all'utente di selezionare e deselezionare i due kml inclusi, come posso fare?
Grazie Mille

var map; var geocoder; var side_bar_html = ''; var gmarkers = []; function loadMap() { var Iraq = {lat: 32.69840, lng: 45.07899}; map = new google.maps.Map(document.getElementById('map'), { zoom: 9, center: Italy }); ctaLayer = new google.maps.KmlLayer({ url: 'https://www.pinco.it/kml/site.kml', suppressInfoWindows: true, map: map }); ctaLayer = new google.maps.KmlLayer({ url: 'https://www.pinco.it/kml/area.kml', suppressInfoWindows: true, map: map }); var cdata = JSON.parse(document.getElementById('data').innerHTML); geocoder = new google.maps.Geocoder(); codeAddress(cdata); var allData = JSON.parse(document.getElementById('allData').innerHTML); showAllColleges(allData); } function showAllColleges(allData) { var infoWind = new google.maps.InfoWindow; Array.prototype.forEach.call(allData, function(data){ var content = document.createElement('div'); var strong = document.createElement('strong'); strong.textContent = data.id; content.appendChild(strong); content.appendChild(document.createElement('br')); var strong1 = document.createElement('strong1'); strong1.textContent = data.name; content.appendChild(strong1); content.appendChild(document.createElement('br')); var a = document.createElement('a'); var linkText = document.createTextNode('record'); a.appendChild(linkText); a.title = 'record'; a.href = ('record.php?id=') + data.id; content.appendChild(a); content.appendChild(document.createElement('br')); if (data.siteno != '') { var img = document.createElement('img'); img.src = (host + 'upload/') + data.siteno + ('.jpg'); img.style.width = '100px'; content.appendChild(img); } var iconBase = host + 'costruzione/coldmarker.png'; var marker = new google.maps.Marker({ position: new google.maps.LatLng(data.lat, data.lng), map: map, icon: iconBase }); marker.addListener('mousedown', function(){ infoWind.setContent(content); infoWind.open(map, marker); }); gmarkers.push(marker); side_bar_html += '<a class="link" href="javascript:myclick(' + (gmarkers.length-1) + ')">' + data.id + '. ' + data.name + '<\/a><br>'; }); document.getElementById('side_bar').innerHTML = side_bar_html; } function codeAddress(cdata) { Array.prototype.forEach.call(cdata, function(data){ var address = data.year; geocoder.geocode( { 'name': address}, function(results, status) { if (status == 'OK') { map.setCenter(results[0].geometry.location); var points = {}; points.id = data.id; points.lat = map.getCenter().lat(); points.lng = map.getCenter().lng(); updateCollegeWithLatLng(points); } else { alert('Geocode was not successful for the following reason: ' + status); } }); }); } function myclick(i) { google.maps.event.trigger(gmarkers[i], 'mousedown'); } function updateCollegeWithLatLng(points) { $.ajax({ url: "action.php", method: "post", data: points, success: function(res) { console.log(res); } }); }
 
codice.JPG
 
Stato
Chiusa ad ulteriori risposte.

Discussioni simili