arcgis server 9.3.1 rest开发学习(一)
Posted: April 13th, 2010 | Author: laomi | Filed under: 开发日志 | Tags: arcgis, rest | 1 Comment »以前自己做arcgis server的开发一般都是基于jsf框架做的,最近美国同事那边开始做基于rest的开发方式,自己以前在java的条件下做了几个demo,感觉还不错,开发起来比jsf感觉要爽很多,不需要一大堆jsf之类的东西。
开始自己想实现简单的功能就是在地图加载的时候自己直接添加上一些点,自己做一个test程序,程序的代码如下:
dojo.require(“esri.map”);
var map;
function init() {
var startExtent = new esri.geometry.Extent(-117.29, 34, -117.14, 34.10, new esri.SpatialReference({ wkid: 4326 }) );
map = new esri.Map(“map”,{ extent: startExtent });
var tiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer(“http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer”);
map.addLayer(tiledMapServiceLayer);addPointToMap();
}function addPointToMap(){
//alert(map.graphics)var markerSymbol = new esri.symbol.SimpleMarkerSymbol();
markerSymbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);
markerSymbol.setSize(12);
markerSymbol.setColor(new dojo.Color([255,0,0,0.5]));pointESRI = new esri.geometry.Point(-117.233,34.057, map.spatialReference);
// alert(“pointESRI “+pointESRI);pointGraphic = new esri.Graphic(pointESRI, markerSymbol);
// alert(“pointGraphic “+pointGraphic);
map.graphics.add(pointGraphic);
}
dojo.addOnLoad(init);
就这样的一段代码自己怎么弄就是现实map.graphics的对象始终为null,一开始就不明白,然后我就在想试试因为map.graphics这个对象在map的onload的时候还没有初始化完的呢?照着这个想法自己写了一个button,然后在onclick事件中直接添加了addPointToMap函数,结果work了,看来自己的想法八九不离十了,然后自己就回到rest 的javascript api中查了一下最后看到了一段原文的描述:
Since the Map.graphics object is only available to use after the Map.onLoad event is fired, you should wait to register event listeners until the the Map.onLoad event is fired.
看完之后我明白是怎么回事了,但是我不知道怎么样才能解决这个问题,之前自己也没有怎么写过javascript程序,然后自己又在api中查到了dojo.connect方法,这个方法就可以监听事件。然后在看了一下api中的sample,之后只是在上述的init中添加一句dojo.connect(map, “onLoad”, addPointToMap);然后就搞定了。
自己平常由于写东西都比较急,很多的东西只是知其然不知其所以然,所以还得花点时间看看javascrpt以及arcgis rest的javascript的开发接口。下次希望自己能够原理上写点东西,不然就算是将程序完成了碰到的其他的问题还是不会弄。









呵呵 类似与 Jquery里面的 bind() 方法