0
我有2個(或更多)多邊形,它可以正常工作。但我想爲每個多邊形添加一個mouseenter事件,並顯示相應的infowindow。在多邊形的mouseenter上添加InfoWindow(),每個多邊形都有一個內容
我在這方面沒有IDEIA(addGeojson)怎麼辦呢
代碼:
var mapOptions = {
zoom: 4,
scrollwheel: false,
center: {lat: 30.162129, lng: -117.341888},
};
geos = [{'type': 'Feature', 'geometry': {'type': 'Polygon', 'osm_type': 'relation', 'coordinates': [[[-482.2998046875,39.07890809706475],[-478.388671875,39.198205348894795],[-480.234375,36.10237644873644],[-483.72802734375,36.932330061503144],[-482.2998046875,39.07890809706475]]]}}, {'type': 'Feature', 'geometry': {'type': 'Polygon', 'osm_type': 'relation', 'coordinates': [[[-478.98193359375006,35.60371874069731],[-480.38818359375,33.687781758439364],[-477.31201171875,32.02670629333614],[-476.89453125,34.361576287484176],[-478.98193359375006,35.60371874069731]]]}}];
var map = new google.maps.Map(document.getElementById('map'), mapOptions);
for(var i = 0; i < geos.length; i++) {
\t map.data.addGeoJson(geos[i]);
}
map.data.setStyle({
\t fillColor: 'orange',
\t strokeWeight: 1
});
<div id="map" style="width: 400px; height: 400px;">
</div>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
的jsfiddle here
謝謝,我該如何讓他們失去mouseleave? Theres東西配合幫助:https://jsfiddle.net/jnL6z36p/2/ –
在attachPolygonInfoWindow方法中添加此代碼, 'google.maps.event.addListener(polygon,'mouseout',function(){ infoWindow.close (); });' –