Javascript error of init() not defined . How to remove this error? - Stack Overflow

<!DOCTYPE html><html><head><link rel="stylesheet" href="style.css&

<!DOCTYPE html>
<html>
  <head>

    <link rel="stylesheet" href="style.css" type="text/css">
<script src=".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",
                    "",
                    {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>

That is my html code with the javascript . My firebug throws up the error init() not defined . What can be the error ?

<!DOCTYPE html>
<html>
  <head>

    <link rel="stylesheet" href="style.css" type="text/css">
<script src="http://openlayers/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/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>

That is my html code with the javascript . My firebug throws up the error init() not defined . What can be the error ?

Share Improve this question asked Jun 18, 2011 at 10:45 IamH1kcIamH1kc 6,8024 gold badges20 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Your <script> element loads its content from an external resource (http://openlayers/api/2.10/OpenLayers.js) since you specified that URL in its src attribute.

Therefore, the browser will ignore the actual content of the element, so init() won't be defined.

Try using two <script> elements instead:

<script src="http://openlayers/api/2.10/OpenLayers.js" type="text/javascript">
</script>

<script 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/wms/vmap0",
                {layers: 'basic'} );
        map.addLayer(layer);
        map.zoomToMaxExtent();
    }
</script>

This might help:

http://openlayers/dev/examples/lite.html

It is the basic and simplest example of Openlayers.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744181293a4561994.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信