0

我有一个特定的要求,我必须使用 dojo 1.9 制作简单的地理地图。我从 openlayer 站点下载了 openlayer.js,但是当我运行该页面时,仍然没有显示任何内容。如果有人能帮助我解决我所缺少的东西,我将不胜感激。请找到以下代码。

<html>
<head>
<link rel="stylesheet" type="text/css" href="../../dijit/themes/dijit.css">
<link rel="stylesheet" type="text/css" href="../../dijit/themes/tundra/tundra.css">
<link rel="stylesheet" type="text/css" href="demo.css">
<title>Map</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="../../dijit/themes/tundra/OpenLayers.js"></script>
<script type="text/javascript" src="../../dojo/dojo.js" data-dojo-config="async: true"></script>
<script type="text/javascript" src="src.js"></script>
</head>
</html>
4

1 回答 1

1

Dojo 容器内的 OpenLayers 地图:

<!DOCTYPE html>
<html>
    <head>
        <link href='//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css' rel='stylesheet' type='text/css' />
        <script src='//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js'></script>
        <script src='//cdnjs.cloudflare.com/ajax/libs/openlayers/2.12/OpenLayers.js'></script>
        <style type='text/css'>
        html,body,#border,#map { margin:0; width:100%; height:100%; }
        </style>
    </head>
    <body class='claro'>
        <div id='border' data-dojo-type='dijit/layout/BorderContainer'>
            <div data-dojo-type='dijit/layout/ContentPane' data-dojo-props='region:"center"'>
                <div id='map'></div>
            </div>
            <div data-dojo-type='dijit/layout/ContentPane' data-dojo-props='region:"trailing"'>
                Just an example
            </div>
        </div>
        <script type='text/javascript'>
        require(['dojo/ready', 'dojo/parser'], function (ready, Parser) {
            ready(function () {
                Parser.parse().then(function () {
                    var map = new OpenLayers.Map({
                        div:'map',
                        displayProjection:new OpenLayers.Projection('EPSG:4326'),
                        projection:new OpenLayers.Projection('EPSG:900913')
                    });
                    map.addLayer(
                        new OpenLayers.Layer.OSM()
                    );
                    map.setCenter(
                        new OpenLayers.LonLat(0, 0),
                        2
                    );
                });
            });
        });
        </script>
    </body>
</html>

100% 的宽度和高度会扩展所有内容以填充视口。虽然您不需要扩展到 100%,但您确实需要在这些元素上设置尺寸。

于 2013-10-25T10:58:09.810 回答