javascript require内容对dojo.dom的影响导致的问题

阔活洵信 2015-05-21 03:48:29
下面这段代码是木有问题的,功能是点击按钮,然后再地图上画一个框

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Shapes and Symbols</title>

<link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css">

<style>
#info {
top: 20px;
color: #444;
height: auto;
font-family: arial;
right: 20px;
margin: 5px;
padding: 10px;
position: absolute;
width: 115px;
z-index: 40;
border: solid 2px #666;
border-radius: 4px;
background-color: #fff;
}
html, body, #mapDiv {
padding:0;
margin:0;
height:100%;
}
button {
display: block;
}
</style>

<script src="http://js.arcgis.com/3.13/"></script>
<script>
var map, tb;

require([
"esri/map",
"esri/toolbars/draw", "esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol", "esri/graphic",
"esri/Color","dojo/dom", "dojo/on", "dojo/domReady!"
], function(
Map, Draw,SimpleLineSymbol,
SimpleFillSymbol,
Graphic,
Color, dom, on
) {
map = new Map("mapDiv", {
basemap: "streets",
center: [-25.312, 34.307],
zoom: 3
});
map.on("load", initToolbar);

// fill symbol used for extent, polygon and freehand polygon, use a picture fill symbol
// the images folder contains additional fill images, other options: sand.png, swamp.png or stiple.png
var fillSymbol = new SimpleFillSymbol(
SimpleFillSymbol.STYLE_SOLID,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.25])
);

function initToolbar() {
tb = new Draw(map);
tb.on("draw-end", addGraphic);

// event delegation so a click handler is not
// needed for each individual button
var drawbutton = dom.byId("Extent");
on(drawbutton, "click", function(evt) {
var tool = "extent";
map.disableMapNavigation();
tb.activate(tool);
});
}

function addGraphic(evt) {
//deactivate the toolbar and clear existing graphics
tb.deactivate();
map.enableMapNavigation();

// figure out which symbol to use
var symbol = fillSymbol;

map.graphics.add(new Graphic(evt.geometry, symbol));
}
});
</script>
</head>

<body>

<div id="info">
<div>Select a shape then draw on map to add graphic</div>
<button id="Extent">Rectangle</button>
</div>

<div id="mapDiv"></div>

</body>
</html>


但是,我在require里面随便再加一个,无论什么内容,就没法执行了,地图就出不来了,
目前只能确定是这句开始出问题,var drawbutton = dom.byId("Extent");至于什么原因,原理是什么,现在还不知道。求教各位大神
...全文
93 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧