Ir para conteúdo

scsrat

Members
  • Total de itens

    1
  • Registro em

  • Última visita

Reputação

0 Comum

Sobre scsrat

  1. Preciso de ajuda com infowindow para polygonos multiplos está abrindo popup em todos com nome do ultimo lançamento somente, não estou dando conta em java, alguém se habilita? <?php include 'export_xml.php'; ?> <html> <head> <meta charset='utf-8' /> <title>Google Maps: Storing Polygons in database</title> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDao9cuBBnlx14GWyG8ZnfZ1WjHj9oa6DA&callback=initMap"></script> <script> function initialize() { var mapOptions = { zoom: 14, center: new google.maps.LatLng(-22.247791, -53.348142), mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); var arr = new Array(); var polygons = []; var bounds = new google.maps.LatLngBounds(); var xml = xmlParse(xmlString); var subdivision = xml.getElementsByTagName("subdivision"); for (var i = 0; i < subdivision.length; i++) { arr = []; html = []; var name = xml.documentElement.getElementsByTagName("subdivision").getAttribute("name"); var address = xml.documentElement.getElementsByTagName("subdivision").getAttribute("address"); var html = "<b>" + name + "</b> <br/>" + address + "<br><a href=# target=_blank>Clique aqui"; //Tentando pegar dados dos polygons individuais var coordinates = xml.documentElement.getElementsByTagName("subdivision").getElementsByTagName("coord"); for (var j = 0; j < coordinates.length; j++) { arr.push(new google.maps.LatLng( parseFloat(coordinates[j].getAttribute("lat")), parseFloat(coordinates[j].getAttribute("lng")) )); bounds.extend(arr[arr.length - 1]) } polygons.push(new google.maps.Polygon({ paths: arr, title: html, strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.35 })); polygons[polygons.length - 1].setMap(map); var infowindow = new google.maps.InfoWindow({ content: html // Tentando pegar dados dos polygons individuais }); google.maps.event.addListener(polygons[polygons.length - 1], 'click', function(event) { infowindow.open(map); infowindow.setPosition(event.latLng); }); } // }); map.fitBounds(bounds); } var xmlString = '<?php echo $textolinha; ?>'; /** * Parses the given XML string and returns the parsed document in a * DOM data structure. This function will return an empty DOM node if * XML parsing is not supported in this browser. * @param {string} str XML string. * @return {Element|Document} DOM. */ function xmlParse(str) { if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined') { var doc = new ActiveXObject('Microsoft.XMLDOM'); doc.loadXML(str); return doc; } if (typeof DOMParser != 'undefined') { return (new DOMParser()).parseFromString(str, 'text/xml'); } return createElement('div', null); } google.maps.event.addDomListener(window, 'load', initialize); </script> <style> #map-canvas, body, html { height: 100%; width: 100%; } </style> </head> <body> <div id="map-canvas"></div> </body> </html> O include export_xml.php: Saida do xml <subdivisions> <subdivision name="teste1" address="0" > <coord lat="-22.246906181604235" lng="-53.343656079469014" /> <coord lat="-22.246160343589366" lng="-53.34298025442864" /> <coord lat="-22.246612168987966" lng="-53.34231238438393" /> <coord lat="-22.24577306351632" lng="-53.34163110329415" /> <coord lat="-22.246309297178513" lng="-53.34088544918801" /> <coord lat="-22.24709286679633" lng="-53.34152917935158" /> <coord lat="-22.247917069182467" lng="-53.342210460441365" /> <coord lat="-22.24876923872473" lng="-53.34288149840766" /> <coord lat="-22.248292595053044" lng="-53.343581554960544" /> <coord lat="-22.247442990211773" lng="-53.34287048089961" /> </subdivision> <subdivision name="teste2" address="0" > <coord lat="-22.24744605203327" lng="-53.3428707695716" /> <coord lat="-22.24664667240292" lng="-53.34224581487113" /> <coord lat="-22.24714566457059" lng="-53.341564533781344" /> <coord lat="-22.247922698585814" lng="-53.342200217317874" /> </subdivision> </subdivisions>
×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.