Arcgis for Js implements space query for graphiclayer (continued)

Source: Internet
Author: User
Tags polyline

Arcgis for Js implements space query for graphiclayer (continued)

In this section, we will introduce the space query for graphiclayer in more detail. First, the spatial query method: provides multiple types of spatial queries, including dot perimeter, line perimeter, and in-area. Second, displays the status after drawing is complete, the result is displayed. The result is as follows:


Point perimeter-input buffer distance <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20141028/20141028091440197.png" alt = "\">

Point perimeter-query results



Line perimeter-input buffer distance


Line perimeter-query results



Inside-rectangle


Inside-circle


Inside-polygon

First, draw the image.

Var drawToolbar = new esri. toolbars. draw (map); drawToolbar. on ("draw-end", showDrawResults); on (dom. byId ("point"), "click", function () {restoreMap (); drawToolbar. activate (esri. toolbars. draw. POINT) ;}); on (dom. byId ("polyline"), "click", function () {restoreMap (); drawToolbar. activate (esri. toolbars. draw. POLYLINE) ;}); on (dom. byId ("extent"), "click", function () {restoreMap (); drawToolbar. activate (esri. toolbars. draw. EXTENT) ;}); on (dom. byId ("circle"), "click", function () {restoreMap (); drawToolbar. activate (esri. toolbars. draw. CIRCLE) ;}); on (dom. byId ("polygon"), "click", function () {restoreMap (); drawToolbar. activate (esri. toolbars. draw. POLYGON) ;});/*** display the drawing result */function showDrawResults (evt) {drawToolbar. deactivate (); map. setMapCursor ("default"); var geometry = evt. geometry; if (geometry. type = "point" | geometry. type = "polyline") {$ ('# map '). modalInfowindow ({width: 175, height: 75, title: "Enter the buffer distance", content :""}); $ (" # Distance "). focus (); $ ("# distance "). keydown (function (e) {// enter key event if (e. which = 13) {$ ("# close "). click () ;}}); on (dom. byId ("close"), "click", function () {distance = dom. byId ("distance "). value; $ ("# modal "). remove (); doBuffer (geometry) ;}} else {queryGraphicByPolygon (geometry );}};

When it is a vertex or line, you must first perform a buffer analysis to obtain the geometry of the buffer. The code for the buffer analysis is as follows:

/*** Run the buffer * @ param geometry */function doBuffer (geometry) {var symbol = null; switch (geometry. type) {case "point": symbol = new SimpleMarkerSymbol (SimpleMarkerSymbol. STYLE_CIRCLE, 7, new SimpleLineSymbol (SimpleLineSymbol. STYLE_SOLID, new Color ([255, 255]), 1), new Color ([,]); break; case "polyline": symbol = new SimpleLineSymbol (SimpleLineSymbol. STYLE_SOLID, new Color ([255,]), 2); break; case "polygon": symbol = new SimpleFillSymbol (SimpleFillSymbol. STYLE_NONE, new SimpleLineSymbol (SimpleLineSymbol. STYLE_SOLID, new Color ([255, 255]), 2), new Color ([0.25,]); break;} var graphic = new Graphic (geometry, symbol); map. graphics. add (graphic); // setup the buffer parameters var params = new BufferParameters (); params. distances = [distance]; params. bufferSpatialReference = map. spatialReference; params. outSpatialReference = map. spatialReference; params. unit = GeometryService ["UNIT_KILOMETER"]; if (geometry. type = "polygon") {// if geometry is a polygon then simplify polygon. this will make the user drawn polygon topologically correct. gsvc. simplify ([geometry], function (geometries) {params. geometries = geometries; gsvc. buffer (params, function (bfGeometry) {queryGraphicByPolygon (bfGeometry [0]) ;}) ;}else {params. geometries = [geometry]; gsvc. buffer (params, function (bfGeometry) {queryGraphicByPolygon (bfGeometry [0]) ;}}

Geometryservice is used to analyze the buffer zone. The Code is as follows:

var gsvc = new GeometryService("http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");

When the geometry is polygon after the buffer zone analysis is complete or the surface element is drawn, perform a space query:

/*** Query by Polygon * @ param geometry */function queryGraphicByPolygon (geometry) {var graphics = chartLayer. graphics; var sfs = new SimpleFillSymbol (SimpleFillSymbol. STYLE_SOLID, new SimpleLineSymbol (SimpleLineSymbol. STYLE_DASHDOT, new Color ([255,255, 0, 0]), 2), new Color ([0.25, 0,]); var graphic = new Graphic (geometry, sfs ); map. graphics. add (graphic); for (var I = 0, total = graphics. length; I
 
  
The spatial query logic is very simple, that is, to determine whether a custom region contains all points.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.