我刚从示例中尝试了一些简单的代码:
$(document).ready(function() {
var map = OpenLayers.Map('map-content', {});
var wms_serever_map = OpenLayers.Layer.WMS('Base l', 'http://vmap0.tiles.osgeo.org/wms/vmap0', {layer:basic},
{});
map.addLayer(wms_serever_map);
if(!map.getCenter()){
map.zoomToMaxExtent();
}
});
但chrome和firefox没有向我显示地图并抛出错误:uncaught type error: Cannot call method 'apply' of undefined Openlayers.js:127
它相当有趣,因为前段时间此代码有效
答案 0 :(得分:3)
尝试在OpenLayers.Map和OpenLayers.Layer.WMS的前面添加'new'关键字,看看它是否解决了问题。