1

我正在努力寻找一种方法来设置此地图上的信息窗口的样式。我尝试通过设置 suppressInfoWindows: true 来抑制信息窗口,但这似乎不起作用。任何想法将不胜感激。我在这里阅读了很多谷歌文档和很多其他帖子,但找不到解决方案。

     <script>

var geocoder;
var map; 
var marker;
var layers = [];

function initialize() {
geocoder = new google.maps.Geocoder ();
var latlng = new google.maps.LatLng (51.505288, -0.191544);
var myOptions = {
  zoom: 15,
  disableDefaultUI: true,
  styles: [
        {
           stylers: [

  ]
},

{
  featureType: "poi.park",
  stylers: [
      { color: "#aecfae" },
    { saturation: 0 },
    { lightness: 0 },
    { visibility: "simplified" }



  ]
  },

  {
  featureType: "landscape",
  stylers: [
      { color: "#ffffff" },
    { saturation: 0 },
    { lightness: 0 },
    { visibility: "simplified" }
  ]
},

{
  featureType: "road.highway",
  elementType: "labels",
  stylers: [
    { color: "transparent" },
    { visibility: "off" },

  ]
},

{
  featureType: "water",
  elementType: "geometry.fill",
  stylers: [
    { color: "#a5bfdd" },
    { visibility: "on" },

  ]
},

{
  featureType: "road",
  elementType: "labels",
  stylers: [
    { color: "transparent" },
    { visibility: "off" },

  ]
},

  {
  featureType: "road",
  elementType: "geometry",
  stylers: [
      { color: "#e0e0e0" },
    { saturation: 0 },
    { lightness: 0 },
    { visibility: "simplified" }
  ]
}],
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
    }
  map = new google.maps.Map(document.getElementById("map_canvas"),
    myOptions);

  marker = new google.maps.Marker({map:map});

     layers[0] = new google.maps.KmlLayer('http://www.cid-dev.co.uk/vicarage-phase-2/kml/VicarageGate.kml', {preserveViewport: true});

    for (var i = 0; i < layers.length; i++) {
    layers[i].setMap(map);


  }

  layers[1] = new google.maps.KmlLayer('http://www.cid-dev.co.uk/vicarage-phase-2/kml/PrimarySchools-1.kml',
         {preserveViewport: true});
  layers[2] = new google.maps.KmlLayer('http://www.cid-dev.co.uk/vicarage-phase-2/kml/SecondarySchools-1.kml', {preserveViewport: true});
  layers[3] = new google.maps.KmlLayer('http://www.cid-dev.co.uk/vicarage-phase-2/kml/Culture-6.kml', {preserveViewport: true});
  layers[4] = new google.maps.KmlLayer('http://www.cid-dev.co.uk/vicarage-phase-2/kml/Hotels-2.kml', {preserveViewport: false});
   layers[5] = new google.maps.KmlLayer('http://www.cid-dev.co.uk/vicarage-phase-2/kml/Shopping.kml', {preserveViewport: false});
   layers[6] = new google.maps.KmlLayer('http://www.cid-dev.co.uk/vicarage-phase-2/kml/Restaurants.kml', {preserveViewport: false});
  for (var i = 1; i < layers.length; i++) {
    layers[i].setMap(null);


  }
    }
function codeAddress () {
    var address = document.getElementById ("address").value;
    geocoder.geocode ( { 'address': address}, function(results, status)  {
    if (status == google.maps.GeocoderStatus.OK)  {
        map.setCenter(results [0].geometry.location);
        marker.setPosition(results [0].geometry.location);
        map.setZoom(15);
        } 
    else {
        alert("Geocode was not successful for the following reason: " + status);
            }
}); 
}

function toggleLayer(i) {
  if(layers[i].getMap() === null) {
    layers[i].setMap(map);
  }
  else {
    layers[i].setMap(null);
  }






}


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






    </script>



    <div id="map_canvas" style="position:absolute; width:100%; height:100%; top:0px; left:0px; right:0px; bottom:0px; z-index:100; background-color:#000;"></div>
4

2 回答 2

0

禁止自动生成信息窗口,并使用点击事件手动处理数据。

target="_blank"这是从信息窗口链接中删除属性的示例:http: //people.missouristate.edu/chadkillingsworth/mapsexamples/removekmllinktargets.js

于 2013-02-20T19:04:57.913 回答
0

您可以尝试将这样的方法添加到所有标记中。

// generalized click handler
function addClickHandler(item, content, position) {
  google.maps.event.addListener(item, 'click', function () {
    infoWindow.close();
    infoWindow.setContent(content);
    infoWindow.setPosition(position);
    infoWindow.open(map);
  });
}

当我使用 KML 进行样式设置时,<[CDATA 标记中传递的任何内容都会被格式化。因此允许在 cdata 中添加。

还有一个来自 GOOGLE 的例子

http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/examples/example.html

于 2013-12-02T21:38:59.970 回答