Skip to content Skip to sidebar Skip to footer

How To Remove Information From Info Window (on A Kmllayer)

I am working with a Google Map API and I have imported a kml layer into my code.My problem is that I don't know how to remove the 'Unknown Point Feature' information from the info

Solution 1:

The info window content is coming from the KML file so you would have to remove it from there, provided you have access to the file from the location it's being served of course.

Solution 2:

From the API: https://developers.google.com/maps/tutorials/kml/

var kmlOptions = {
  **suppressInfoWindows: true,**
  preserveViewport: false,
  map: map
};

Solution 3:

One option would be to set the suppressInfoWindows option of the KmlLayer, then add your own click listener that just displays the "name":

var AI_url = 'https://drive.google.com/uc?export=download&id=0B2KR4Lz3foYEeEtfR0laWWM0LVk'var AI_options = {
    preserveViewport: true,
    suppressInfoWindows: true,
    map: map
};
var AI_layer = new google.maps.KmlLayer(AI_url, AI_options);
google.maps.event.addListener(AI_layer,'click',function(e) {
    infoWindow.setOptions({
      content:"<b>"+e.featureData.name+"</b>",
      pixelOffset:e.pixelOffset, 
      position:e.latLng
    });
    infoWindow.open(map);
});

proof of concept code snippet:

var geocoder;
var map;
var infoWindow = new google.maps.InfoWindow();

functioninitialize() {
  geocoder = new google.maps.Geocoder();
  map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

  var AI_url = 'https://drive.google.com/uc?export=download&id=0B2KR4Lz3foYEeEtfR0laWWM0LVk'var AI_options = {
    preserveViewport: true,
    suppressInfoWindows: true,
    map: map
  };
  var AI_layer = new google.maps.KmlLayer(AI_url, AI_options);
  google.maps.event.addListener(AI_layer, 'click', function(e) {
    infoWindow.setOptions({
      content: "<b>" + e.featureData.name + "</b>",
      pixelOffset: e.pixelOffset,
      position: e.latLng
    });
    infoWindow.open(map);
  });

  codeAddress("Calgary, Canada");

}
google.maps.event.addDomListener(window, "load", initialize);

functioncodeAddress(address) {
  geocoder.geocode({
    'address': address
  }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.fitBounds(results[0].geometry.viewport);
    } else {
      alert("Geocode was not successful for the following reason: " + status);
    }
  });
}
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<scriptsrc="https://maps.googleapis.com/maps/api/js"></script><divid="map_canvas"style="border: 2px solid #3872ac;"></div>

Post a Comment for "How To Remove Information From Info Window (on A Kmllayer)"