首先,在地图中添加1个graphiclayer:
gLayer = new Graphicslayer(); map.addLayer(gLayer);
接着,在gLayer中添加几个对象:
map.on("load",function(){ var items = geometry.item; gLayer.add(new Graphic(Wkttopoint(items[0].wkt,{"wkID":4326}),sms)); gLayer.add(new Graphic(WktTopolyline(items[1].wkt,sls)); gLayer.add(new Graphic(WktTopolygon(items[2].wkt,sfs)); });接下来,定义drawtoolbar和绘制完成后的事件:
var drawToolbar = new esri.toolbars.Draw(map,{tooltip: "place text"}); drawToolbar.on("draw-end",showDrawResults); function showDrawResults(evt){ drawToolbar.deactivate(); map.setMapCursor("default"); var geometry = evt.geometry; map.graphics.add(new Graphic(geometry,sls)); };接下来,定义1个button,并添加button的click事件:<button ID="draw" style="z-index: 99;">绘制图形</button> on(dom.byID("draw"),"click",function(){ drawToolbar.activate(esri.toolbars.Draw.polyliNE); });接下来定义map的捕捉设置: var snapManager = map.enableSnapPing({ snapKey:has("mac") ? keys.Meta : keys.CTRL }); var layerInfos = [{layer: gLayer}]; snapManager.setLayerInfos(layerInfos);备注:此处,需要调用的dojo包包括:
require([ "esri/map","esri/layers/Graphicslayer","esri/graphic","esri/SnapPingManager","esri/sniff","dojo/_base/event","dojo/on","dojo/dom","dojo/keys","dojo/domready!"],function(Map,Graphicslayer,Graphic,Point,SnapPingManager,has,event,on,dom,keys) {如有疑问请联系:
QQ:1004740957
Email:niujp08@qq.com
请关注微信公众账号lzugis15,随时了解更多GIS动态信息。
总结
以上是内存溢出为你收集整理的Arcgis for JS之对象捕捉全部内容,希望文章能够帮你解决Arcgis for JS之对象捕捉所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)