2013-02-20 88 views
0

我竭力要找到一種方法,這種樣式地圖上的信息窗口。我試圖通過設置suppressInfoWindows:true來壓制infowindow,但這似乎不起作用。任何想法都會被大量讚賞。我已閱讀了很多Google文檔以及其他許多帖子,但無法找到解決方案。KML圖層的信息窗口

 <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> 
+0

你是如何使用suppressInfoWindows的例子嗎?我在你的發佈代碼中沒有看到它。 – geocodezip 2013-02-20 18:24:30

+0

它[對我的作品(http://www.geocodezip.com/v3_simpleMap_SO_infowindow.html)。 – geocodezip 2013-02-20 18:30:45

+0

對不起geocodezip,我把它的這個代碼,我只是用{suppressInfoWindows:真}。該信息窗口工作的時候,我不壓制他們,但我想抑制他們爲了顯示一個信息窗口的風格,而不是如果這是有道理的?而不是Google API提供的infowindow風格 – 2013-02-21 09:59:22

回答

0

禁止自動生成信息窗口,並使用click事件手動處理數據。

下面是被去除的信息窗口的鏈接target="_blank"屬性的例子:http://people.missouristate.edu/chadkillingsworth/mapsexamples/removekmllinktargets.js

+0

乍得您好,感謝爲你所有的辛勤工作。我專注於HTML和PHP,而我的Jquery/Javascript知識還處於起步階段。我怎麼會去你的代碼集成到礦井,得到所需的切換效果,但顯示自定義的CSS信息窗口? - 親切的問候,羅布。 – 2013-02-21 10:01:59

+0

同樣的概念,你只需在'click'事件監聽器代碼(而不是我的CommonInfoWindow)中替換你的自定義信息窗口代碼即可。您可以嘗試Google地圖實用程序庫的InfoBubble類:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/ – 2013-02-22 16:10:36

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