-2

所以我设法让标记和信息窗口使用 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 都制作了它们,如果这有意义的话。

4

1 回答 1

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>
于 2013-05-09T20:05:17.580 回答