function init_map() {
var map, layer;
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(43.5, 40), 10);
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);
var markers = new OpenLayers.Layer.Markers("Objects");
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addLayer(markers);
$.ajax({
type: "GET",
url: "/rest/displaymap/getMarkers/",
dataType: "json",
error: function() {
console.log('failed to retrieve data');
},
success: function(d) {
console.log(d);
var i;
for(i=0; i<d.length; i++) {
var mrk = new OpenLayers.Marker(new OpenLayers.LonLat(d[i]['objectLon'],d[i]['objectLat']), icon);
markers.addMarker(mrk);
}
}
});
}
^ 我的 Init() 函数。我有一个带有标记和瓷砖层的简单层。返回的 json 是正确的。但只显示一个标记而不是全部。不知道问题出在哪里。请帮忙!