2

我想为我想要的标记创建一个带有 jquery 的弹出窗口。所以我有一个标记的代码,但是如何为另一个标记创建另一个弹出窗口?例如在标记巴黎。我也想知道如何防止弹出窗口移动?

<script type='text/javascript'> $(function(){function initialize() {
    var mapOptions = {
      zoom: 4,
      disableDefaultUI: true,
      center: new google.maps.LatLng(45.35, 4.98),
      mapTypeId: google.maps.MapTypeId.TERRAIN
    }
    var map = new google.maps.Map(document.getElementById('map_canvas'),
                                  mapOptions);


// Paris 
var Paris = new google.maps.LatLng(48.856291,2.352705);
    var image = 'rss.png';
    var marker = new google.maps.Marker({
        position: Paris,
        map: map,
        icon: image,
    });


// Le Mans
var Lemans = new google.maps.LatLng(48.006922,0.20874);
    var image = 'rss.png';
    var marker = new google.maps.Marker({
        position: Lemans,
        map: map,
        icon: image,
    });

    var styles = [
   {
      featureType: "all",
      stylers: [
        { saturation: -15 },
        { lightness: -10 },
      ]
    },

            ];
map.setOptions({styles: styles});


var popup=$('<div/>', {
    'id':'infoWindow',
    'text':'Hello World'
}).dialog({
    'autoOpen':false,
    'width': 200,
    'height':200,
    'resizable':false,
    'modal':true,
    'title':'Map info'
});
google.maps.event.addListener(marker, 'click', function(e) {
    console.log(e);
    popup.dialog('open');
});    }initialize();}); </script>
4

2 回答 2

2

您可以在一个额外的函数中提取标记和窗口创建,并为每个城市调用它。顺便说一句,我用谷歌地图窗口替换了弹出窗口。但这也应该适用于自定义弹出窗口。

function addMarkerWithWindow(name, coordinate, map) {
    var infowindow = new google.maps.InfoWindow({
        content: name
    });

    var marker = new google.maps.Marker({
        map: map,
        position: coordinate
    });

    google.maps.event.addListener(marker, 'click', function (e) {
        infowindow.open(map, marker);
    });
}

function initialize() {
    var mapDiv = document.getElementById('map-canvas');
    var map = new google.maps.Map(mapDiv, {
        center: new google.maps.LatLng(48.006922, 2.20874),
        zoom: 4,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    addMarkerWithWindow("This is Lemans", new google.maps.LatLng(48.006922, 0.20874), map);
    addMarkerWithWindow("This is Paris", new google.maps.LatLng(48.856291, 2.352705), map);
}

如果你把它放在这里,你可以测试代码:http ://code.google.com/apis/ajax/playground/#info_windows_complex_v3

于 2013-02-01T16:43:46.480 回答
-1

要创建一个弹出窗口,您可以这样做:

您可以在此处查看一些示例:演示

<p><a href="http://www.yahoo.com" title="yahoo.com" class="example1demo">open popup</a></p> 
<script type="text/javascript"> 
$('.example1demo').popupWindow({ 
height:500, 
width:800, 
top:50, 
left:50 
}); 
</script>
于 2013-02-01T16:06:50.003 回答