描述
该示例展示了在应用中如何包含一个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())); });
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <meta http-equiv="X-UA-Compatible" content="IE=7" /> 6 <title>增加一个调试控制台</title> 7 <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.5/js/dojo/dijit/themes/tundra/tundra.css"> 8 <!-- Declare djConfig before including reference to ArcGIS JavaScript API --> 9 <script type="text/javascript">djConfig = { isDebug:true };</script> 10 <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.5"></script> 11 <script type="text/javascript"> 12 dojo.require("esri.map"); 13 14 function init() { 15 var map = new esri.Map("map"); 16 dojo.connect(map,"onLoad",function(){ 17 console.log("Map loaded"); 18 dojo.connect(map,"onExtentChange",function(extent){ 19 console.log("Extent changed: " + dojo.toJson(extent.toJson())); 20 }); 21 22 }); 23 24 dojo.connect(map,"onLayerAdd",function(){ 25 console.log("Layer added"); 26 }); 27 map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/arcgis/rest/services/ESRI_StreetMap_World_2D/MapServer")); 28 } 29 30 dojo.addOnLoad(init); 31 </script> 32 </head> 33 <body class="tundra"> 34 Add dojo console window 35 <div id="map" style="512px; height:512px; border:1px solid #000;"></div> 36 </body> 37 </html>