仅显示最后一个标记信息窗口,即使有154个其他标记信息窗口

时间:2013-05-09 19:51:10

标签: asp.net-mvc-4 razor google-maps-api-3

所以我设法使用razor和google maps api来完成标记和信息窗口的工作:

@{
            IEnumerable<UFA.Location.Core.Location> Location = UFALocation___Front.Helpers.QueryHelper.QueryHelper.getAllLocations();

            foreach(var loc in Location){
                <text>
                    var contentString_@loc.id = "@loc.name";

                    mapMarker_@loc.id = new google.maps.Marker({
                        position: new google.maps.LatLng(@loc.latitude, @loc.longitude),
                        map: map,
                        title: "Hello World!"
                    });

                    var infoWindow = new google.maps.InfoWindow({
                        content: contentString_@loc.id
                    });

                    google.maps.event.addListener(mapMarker_@loc.id, 'click', function() {
                        infoWindow.open(map, mapMarker_@loc.id);
                    });

                </text>
            }
        }

更新

所以它显示为每个位置的信息框,正如我所想,但其中的内容只是最后一个位置的名称,无论位置如何。基本上信息框没有绑定到任何一个特定的位置,即使我已经为每个id创建了它们,如果这是有意义的。

1 个答案:

答案 0 :(得分:0)

<script defer="defer" type="text/javascript">
          var map = new OpenLayers.Map('map', {allOverlays: true, controls: []});
            var wms_layer_Test_5000_fKr = new OpenLayers.Layer.WMS(
            'Test_5000_fKr',
            'http://130.237.175.39:8080/geoserver/wms/test_test',
            {layers: 'Test_5000_fKr', transparent: "true", format: "image/png"},

            {maxExtent: new OpenLayers.Bounds(585000, 6600000, 740000, 6722500), maxResolution: 'auto', projection:"EPSG:3006", units: "m"},
            {isBaseLayer: false}, 
            {visibility: true},
            {transparent: true}
            );

      map.addLayers([wms_layer_Test_5000_fKr]);

      var scalebar = new OpenLayers.Control.ScaleLine();
            map.addControl(scalebar);

            map.addControl(
                new OpenLayers.Control.MousePosition({
                    prefix: '<a target="_blank" ' +
                        'href="http://spatialreference.org/ref/epsg/3006/">' +
                        'SWEREF99 TM:&nbsp</a>',
                    separator: ' , ',
                    numDigits: 0,
                    emptyString: 'Mouse is not over map.'
                })
            );            

      var panel = new OpenLayers.Control.NavToolbar();
            map.addControl(panel);

      var panzoom = new OpenLayers.Control.PanZoomBar();
            map.addControl(panzoom);                                              

      var layer = new OpenLayers.Control.LayerSwitcher({'ascending':false});
            map.addControl(layer);

        map.zoomToMaxExtent();
      </script>