首页 > 代码库 > Arcgis for Js之featurelayer实现空间查询和属性查询
Arcgis for Js之featurelayer实现空间查询和属性查询
空间查询和属性查询是常用的两种对数据的检索与查询方式,在本节,将讲述Arcgis for Js下如何实现featurelayer的这两种查询方式,先贴图给大家看看:
实现界面
属性查询
空间查询
看完了效果,下面说说我的实现思路。
首先,实现查询的关键是Query,属性查询时query.where来实现,空间查询时query.geometry来实现,具体代码如下:
1、属性查询
on(dom.byId("query"), "click", function(event){ map.graphics.clear(); var name = dom.byId("name").value; var query = new Query(); query.where = "name = '"+name+"'"; city.queryFeatures(query, function(results) { var features = results.features; console.log(features); map.centerAndZoom(features[0].geometry,8); var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_DIAMOND, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([0,0,0]), 1 ), new Color([255,0,0]) ); map.graphics.add(new Graphic(features[0].geometry,sms)); }); });2、空间查询
var draw = new esri.toolbars.Draw(map); draw.on("draw-end",addGraphicToMap); on(dom.byId("extent"), "click", function(event){ map.graphics.clear(); map.setMapCursor("pointer"); draw.activate(esri.toolbars.Draw.EXTENT); }); function addGraphicToMap(evt){ map.setMapCursor("default"); draw.deactivate(); var sfs = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT, new Color([255,0,0]), 2 ), new Color([255,255,0,0.25]) ); map.graphics.add(new Graphic(evt.geometry, sfs)); //根据空间进行查询 var query = new Query(); query.geometry = evt.geometry; city.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){ console.log(results); for(var i= 0,length=results.length;i<length;i++){ var sms = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255,0,0]), 1 ), new Color([0,255,255,0.25]) ); results[i].symbol = sms; city.redraw(); } }); map.setExtent(evt.geometry.getExtent().expand(2)); };
完整代码如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/> <title>Simple Map</title> <link rel="stylesheet" href=http://www.mamicode.com/"http://localhost/arcgis_js_api/library/3.9/3.9/js/esri/css/esri.css">>
欢迎关注LZUGIS CSDN之Arcgis for JS系列文章,有疑问请联系:QQ:1004740957
Mail:niujp08@qq.com
来信请注明您的来意,方便我为您解疑答惑。
Arcgis for Js之featurelayer实现空间查询和属性查询
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。