如何从信息窗口中删除信息(在KmlLayer上) [英] How to remove information from info window (on a KmlLayer)

查看:108
本文介绍了如何从信息窗口中删除信息(在KmlLayer上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Map API,并且已将kml图层导入代码中.我的问题是我不知道如何从信息窗口中删除未知点要素"信息.有什么建议?这是我在说什么的屏幕截图:

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 window. Any suggestions? here is a screenshot of what I am talking about:

这是我导入kml文件的代码:

This is my code for importing the kml file:

var AI_url = 'https://drive.google.com/uc?export=download&id=0B2KR4Lz3foYEeEtfR0laWWM0LVk'            
var AI_options = {
    preserveViewport: true,
    map: map
};
var AI_layer = new google.maps.KmlLayer(AI_url, AI_options);

推荐答案

一个选项是设置KmlLayer的preventInfoWindows选项,然后添加仅显示名称"的单击侦听器:

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);
});

概念验证代码段:

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

function initialize() {
  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);

function codeAddress(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
}

<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas" style="border: 2px solid #3872ac;"></div>

这篇关于如何从信息窗口中删除信息(在KmlLayer上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆