未定义init()的Javascript错误。如何删除此错误? var映射,层; 函数init(){ map=newOpenLayers.map('map',{控件:[ 新建OpenLayers.Control.Navigation({documentDrag:true}), 新建OpenLayers.Control.PanZoom(), 新建OpenLayers.Control.ArgParser(), 新建OpenLayers.Control.attribute() ]} ); 层=新的OpenLayers.layer.WMS(“OpenLayers WMS”, "http://vmap0.tiles.osgeo.org/wms/vmap0", {层:'基本'}); map.addLayer(层); zoomToMaxExtent(); } OpenLayers文档拖动示例 拖曳 即使鼠标光标移动到地图之外,也要继续拖动

未定义init()的Javascript错误。如何删除此错误? var映射,层; 函数init(){ map=newOpenLayers.map('map',{控件:[ 新建OpenLayers.Control.Navigation({documentDrag:true}), 新建OpenLayers.Control.PanZoom(), 新建OpenLayers.Control.ArgParser(), 新建OpenLayers.Control.attribute() ]} ); 层=新的OpenLayers.layer.WMS(“OpenLayers WMS”, "http://vmap0.tiles.osgeo.org/wms/vmap0", {层:'基本'}); map.addLayer(层); zoomToMaxExtent(); } OpenLayers文档拖动示例 拖曳 即使鼠标光标移动到地图之外,也要继续拖动,javascript,Javascript,此示例演示如何使地图可在地图本身之外拖动 这是我用javascript编写的html代码。我的firebug抛出了未定义的init()错误。什么是错误?您的元素从外部资源加载其内容(http://openlayers.org/api/2.10/OpenLayers.js),因为您在其src属性中指定了该URL 因此,浏览器将忽略元素的实际内容,因此不会定义init() 尝试改用两个元素: <!DOCTYPE html> <html> <head>

此示例演示如何使地图可在地图本身之外拖动

这是我用javascript编写的html代码。我的firebug抛出了未定义的init()错误。什么是错误?

您的
元素从外部资源加载其内容(
http://openlayers.org/api/2.10/OpenLayers.js
),因为您在其
src
属性中指定了该URL

因此,浏览器将忽略元素的实际内容,因此不会定义
init()

尝试改用两个
元素:

<!DOCTYPE html>
<html>
  <head>

    <link rel="stylesheet" href="style.css" type="text/css">
<script src="http://openlayers.org/api/2.10/OpenLayers.js" type="text/javascript">
        var map, layer;
        function init(){
            map = new OpenLayers.Map( 'map', {controls: [
                new OpenLayers.Control.Navigation({documentDrag: true}),
                new OpenLayers.Control.PanZoom(),
                new OpenLayers.Control.ArgParser(),
                new OpenLayers.Control.Attribution()
            ]} );
            layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} );
            map.addLayer(layer);
            map.zoomToMaxExtent();
        }
    </script>
  </head>
  <body onload="init()">
    <h1 id="title">OpenLayers Document Drag Example</h1>

    <div id="tags">
        drag
    </div>

    <div id="shortdesc">Keep on dragging even when the mouse cursor moves outside of the map</div>

    <div id="map" class="smallmap"></div>

    <div id="docs">
        <p>This example shows how to make a map draggable outside of the map itself.</p>
    </div>
  </body>

</html>

var映射,层;
函数init(){
map=newOpenLayers.map('map',{控件:[
新建OpenLayers.Control.Navigation({documentDrag:true}),
新建OpenLayers.Control.PanZoom(),
新建OpenLayers.Control.ArgParser(),
新建OpenLayers.Control.attribute()
]} );
层=新的OpenLayers.layer.WMS(“OpenLayers WMS”,
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{层:'基本'});
map.addLayer(层);
zoomToMaxExtent();
}
您的
元素从外部资源加载其内容(
http://openlayers.org/api/2.10/OpenLayers.js
),因为您在其
src
属性中指定了该URL

因此,浏览器将忽略元素的实际内容,因此不会定义
init()

尝试改用两个
元素:

<!DOCTYPE html>
<html>
  <head>

    <link rel="stylesheet" href="style.css" type="text/css">
<script src="http://openlayers.org/api/2.10/OpenLayers.js" type="text/javascript">
        var map, layer;
        function init(){
            map = new OpenLayers.Map( 'map', {controls: [
                new OpenLayers.Control.Navigation({documentDrag: true}),
                new OpenLayers.Control.PanZoom(),
                new OpenLayers.Control.ArgParser(),
                new OpenLayers.Control.Attribution()
            ]} );
            layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} );
            map.addLayer(layer);
            map.zoomToMaxExtent();
        }
    </script>
  </head>
  <body onload="init()">
    <h1 id="title">OpenLayers Document Drag Example</h1>

    <div id="tags">
        drag
    </div>

    <div id="shortdesc">Keep on dragging even when the mouse cursor moves outside of the map</div>

    <div id="map" class="smallmap"></div>

    <div id="docs">
        <p>This example shows how to make a map draggable outside of the map itself.</p>
    </div>
  </body>

</html>

var映射,层;
函数init(){
map=newOpenLayers.map('map',{控件:[
新建OpenLayers.Control.Navigation({documentDrag:true}),
新建OpenLayers.Control.PanZoom(),
新建OpenLayers.Control.ArgParser(),
新建OpenLayers.Control.attribute()
]} );
层=新的OpenLayers.layer.WMS(“OpenLayers WMS”,
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{层:'基本'});
map.addLayer(层);
zoomToMaxExtent();
}
这可能会有帮助:

这是Openlayers最基本、最简单的示例。

这可能有助于:


这是Openlayers最基本、最简单的示例。

谢谢。虽然错误消失了,但仍然没有显示OpenLayers映射的迹象。我不熟悉OpenLayers,但是
'map'
参数不应该是传递给
映射()的对象的一部分吗?类似于
Map({div:“Map”,控件:…})?谢谢。虽然错误消失了,但仍然没有显示OpenLayers映射的迹象。我不熟悉OpenLayers,但是
'map'
参数不应该是传递给
映射()的对象的一部分吗?类似于
Map({div:“Map”,控件:…})