描述
该示例展示了在应用中如何包含一个Dojo调试控制台。可以写信息到控制台来记录发生的事件和应用运行时设置的属性。当调试Internet Explorer浏览器的错误时这是极为有帮助的。(对Firefox,Firebug提供了比Dojo调试控制台更强的调试能力。)
可以通过设置djConfig里面的isDebug属性为true来加入Dojo调试。必须在引用ArcGIS JavaScript API之前设置这个选项:
<script type="text/javascript">djConfig = { isDebug:true };</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.1"></script>
本例在地图加载,地图图层被增加和地图范围修改时写了一个信息。当图层被增加时,一个事件监听器用console.log方法往控制台写了一个信息:
dojo.connect(map, "onLayerAdd", function() { console.log("Layer added"); })
注意也可以通过toJson方法发送一组属性给控制台。这行代码便利地在控制台上写了所有范围的属性:
dojo.connect(map, "onExtentChange", function(extent) { console.log("Extent changed : " + dojo.toJson(extent.toJson())); });
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>增加一个调试控制台</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.5/js/dojo/dijit/themes/tundra/tundra.css">
<!-- Declare djConfig before including reference to ArcGIS JavaScript API -->
<script type="text/javascript">djConfig = { isDebug:true };</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.5"></script>
<script type="text/javascript">
dojo.require("esri.map"); function init() {
var map = new esri.Map("map");
dojo.connect(map,"onLoad",function(){
console.log("Map loaded");
dojo.connect(map,"onExtentChange",function(extent){
console.log("Extent changed: " + dojo.toJson(extent.toJson()));
}); }); dojo.connect(map,"onLayerAdd",function(){
console.log("Layer added");
});
map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/arcgis/rest/services/ESRI_StreetMap_World_2D/MapServer"));
} dojo.addOnLoad(init);
</script>
</head>
<body class="tundra">
Add dojo console window
<div id="map" style="width:512px; height:512px; border:1px solid #000;"></div>
</body>
</html>