geocodezip / geoxml3

Automatically exported from code.google.com/p/geoxml3
102 stars 87 forks source link

Uncaught TypeError: geoXml.docs[0].gpolygons[i].Contains is not a function #118

Closed boonzik closed 7 years ago

boonzik commented 7 years ago

Unfortunately we have this error:

Uncaught TypeError: geoXml.docs[0].gpolygons[i].Contains is not a function

How can we solve it?

Best regards.

<script>
jQuery(document).ready(function(){
    jQuery(".map_search").ajaxlivesearch({
        loaded_at: <?php echo time() ; ?>,
        token: <?php echo "'" . $handler->getToken() . "'"; ?>,
        max_input: <?php echo Config::getConfig('maxInputLength'); ?>,
        onResultClick: function(e, data) {
            // get the index 0 (first column) value
            var selectedOne = jQuery(data.selected).find('td').eq('0').text();

            // set the input value
            jQuery('#ls_query').val(selectedOne);

            // hide the result
            jQuery("#ls_query").trigger('ajaxlivesearch:hide_result');
        },
        onResultEnter: function(e, data) {
            // do whatever you want
            // jQuery("#ls_query").trigger('ajaxlivesearch:search', {query: 'test'});
        },
        onAjaxComplete: function(e, data) {

        }
    });
})
</script> 

<!-- Countdown Script --> 
<script>
(function() {
  var start = new Date;
  start.setHours(17, 0, 0); // 11pm

  function pad(num) {
    return ("0" + parseInt(num)).substr(-2);
  }

  function tick() {
    var now = new Date;
    if (now > start) { // too late, go to tomorrow
      start.setDate(start.getDate() + 1);
    }
    var remain = ((start - now) / 1000);
    var hh = pad((remain / 60 / 60) % 60);
    var mm = pad((remain / 60) % 60);
    var ss = pad(remain % 60);
    document.getElementById('fasty-countdown').innerHTML =
      "<div class=\"element-container\"><div class=\"element\">" + hh + "<div class=\"label\">ore</div></div></div><div class=\"element-container\"><div class=\"element\">" + mm + "<br><div class=\"label\">minuti</div></div></div><div class=\"element-container\"><div class=\"element\">" + ss + "<br><div class=\"label\">secondi</div></div></div>";
    setTimeout(tick, 1000);
  }

  document.addEventListener('DOMContentLoaded', tick);
})();
</script> 

<!-- Google Maps API KEY --> 
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCvlsmeQTG0QwUecCa0WX0swDRROEIO98U"></script> 
<script src="/ajax-live-search-master/geoxml3.js" type="text/javascript" ></script> 
<script type="text/javascript">
    var geoXml = null;
    var map = null;
    var geocoder = null;
    var toggleState = 1;
    var infowindow = null;
    var marker = null;
    var geoXmlDoc = null;
    var directionsDisplay = null;
    var directionsService = null;
    window.onload = initialize;

  function initialize() {
    directionsService = new google.maps.DirectionsService();
        directionsDisplay = new google.maps.DirectionsRenderer({suppressInfoWindows :true}); 
    geocoder = new google.maps.Geocoder();
    infowindow = new google.maps.InfoWindow({size: new google.maps.Size(250,50) }); 
    var latlng = new google.maps.LatLng(42.3927939, 14.2137044);

    var myOptions = {
        zoom: 12,
        center: latlng,
    mapTypeControl: true,
        mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
        navigationControl: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
        google.maps.event.addListener(map,"click", function() {infowindow.close();});
    directionsDisplay.setMap(map);
        directionsDisplay.setPanel(document.getElementById("directionsPanel")); 
    geoXml = new geoXML3.parser({
                    map: map,
                    infoWindow: infowindow,
                    singleInfoWindow: true,
            pmParseFn: parsePlacemark,
                    afterParse: useTheData
                });
    geoXml.parse('/ajax-live-search-master/kml/italia/fasty.kml');
  }

function showAddress(address) {
    var contentString = "Outside Area";
    var pollingPlace = null;
    geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
      var point = results[0].geometry.location;
          map.setCenter(point);
          if (marker && marker.setMap) marker.setMap(null);
          marker = new google.maps.Marker({
              map: map, 
              position: point
          });
        for (var i=0; i<geoXml.docs[0].gpolygons.length; i++) {
          if (geoXml.docs[0].gpolygons[i].Contains(point)) {
            contentString = address+"<br>is in District "+geoXml.docs[0].placemarks[i].name;
            contentString += "<br>Polling Place is at:"+geoXml.docs[0].placemarks[i].address;
            if(geoXml.docs[0].placemarks[i].address) {
                  pollingPlace = geoXml.docs[0].placemarks[i].address;
                  //calcRoute(address, pollingPlace);
              // alert(pollingPlace);
            }
            break;
          }
        }
    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(contentString); 
        infowindow.open(map,marker);
        });
    google.maps.event.trigger(marker,"click");
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
}
function kmlClick(poly) {
//   map.fitBounds(geoXmlDoc.gpolygons[poly].bounds);
   google.maps.event.trigger(geoXmlDoc.gpolygons[poly],"click");
}
function kmlShowPoly(poly) {
   map.fitBounds(geoXmlDoc.gpolygons[poly].bounds);
   for (var i=0;i<geoXmlDoc.gpolygons.length;i++) {
     if (i == poly) {
       geoXmlDoc.gpolygons[i].setMap(map);
     } else {
       geoXmlDoc.gpolygons[i].setMap(null);
     }
   }
}
function showAll() {
   map.fitBounds(geoXmlDoc.bounds);
   for (var i=0;i<geoXmlDoc.gpolygons.length;i++) {
     geoXmlDoc.gpolygons[i].setMap(map);
   }
}

function useTheData(doc){
  // Geodata handling goes here, using JSON properties of the doc object
  var sidebarHtml = '<table><tr><td><a href="javascript:showAll();">Show All</a></td></tr>';
  geoXmlDoc = doc[0];
  for (var i = 0; i < doc[0].gpolygons.length; i++) {
    // console.log(doc[0].markers[i].title);
    sidebarHtml += '<tr><td><a href="javascript:kmlClick('+i+');"><strong>'+doc[0].placemarks[i].name+'</strong></a> - <a href="javascript:kmlShowPoly('+i+');">show</a>';
    if (doc[0].placemarks[i].address) sidebarHtml += '<br>'+doc[0].placemarks[i].address;
    sidebarHtml += '</td></tr>'
  }
  sidebarHtml += "</table>";
  document.getElementById("sidebar").innerHTML = sidebarHtml;
};

function calcRoute(start,end) {
// alert(start+":"+end);
  var request = {
    origin:start, 
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
  };
  directionsService.route(request, function(response, status) {
  // alert(status);
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    } else alert(status);
  });
}            

   function hide_markers_kml(){

            geoXml.hideDocument();  

   }

   function unhide_markers_kml(){

            geoXml.showDocument();  

   }

// Custom placemark parse function
function parsePlacemark (node, placemark) {
      var addressNodes = node.getElementsByTagName('address');
      var address = null;
      if (addressNodes && addressNodes.length && (addressNodes.length > 0)) {
        placemark.address = geoXML3.nodeValue(addressNodes[0]);
      }
}

</script> 
geocodezip commented 7 years ago

Not an issue with geoxml3