Element layer Range Query attributes arcgis api for js, arcgisapi

Source: Internet
Author: User

Element layer Range Query attributes arcgis api for js, arcgisapi

This blog is reprinted. Thanks to the blogger. Original article: Workshop.

Element layer Range Query attributes

This article mainly uses Query and FeatureLayer. setDefinitionExpression to Query the range attribute of the element layer. The query result is displayed by FeatureTable and the shape can be displayed on the map..

Sometimes, we often need to query attributes of a certain range of element layers. You can assign a value to FeatureLayer. setDefinitionExpression through an SQL query statement. Then, FeatureTable is used to display the query results. At the same time, only the query element diagram is displayed on the map.
The elements on the map are associated with the elements of the table. If you select either of them, the other displays the selected elements:

 

1. First, define the map, element layer, and element table.

// The basemap defines var map = new Map ("map", {basemap: "topo", center: [102.96, 31.65], zoom: 10 }); // element layer definition var myFeatureLayer = new esri. layers. featureLayer ("http: // localhost: 6080/arcgis/rest/services/Test/ft/MapServer/0", {mode: esri. layers. featureLayer. MODE_ONDEMAND, // load feature outFields: ["*"], opacity: 0.5, visible: true, id: "fLayer"}) on demand "}); // element table definition var myFeatureTable = new FeatureTable ({featureLayer: myFeatureLayer, map: map, editable: true, syncSelection: true, showRelatedRecords: true, showAttachments: true, // outfields: ["Subbasin", "mydb. DBO. subs2.Area "," Len1 "," Elev "," ElevMin "," ElevMax "],}, 'mytablenode ');

2. Then, add the query conditions and the query button.

<Div data-dojo-type = "dijit/layout/ContentPane" data-dojo-props = "region: 'top'"> myFeatureTable. startup (); // The element table is run first. It cannot be placed in the click function. You only need to refresh () in the click function. On (dom. byId ("sqlque"), "click", function (e) {map. removeLayer (myFeatureLayer); // remove the previous element layer query result // Range Query var submin = dom. byId ("submin "). value; // the minimum value of the subwatershed serial number var submax = dom. byId ("submax "). value; // maximum value // determines whether the input is zero. if it is zero, the range of if (submin = "") {submin = 0;} is automatically set ;} // minimum value if (submax = "") {submax = 100;} // maximum value var SQL _sub = "Subbasin >=" + submin +" and Subbasin <= "+ submax; // subwatershed No. SQL query string var areamin = dom. byId ("areamin "). value ;/ /The minimum area var areamax = dom. byId ("areamax "). value; // maximum value // determines whether the input is zero. if it is zero, the if (areamin = "") {areamin = 0;} if (areamax = "") {areamax = 100000;} var SQL _area = "Area> =" + areamin + "and Area <=" + areamax; // area SQL query string var SQL _r = SQL _sub + "and" + SQL _area; // subwatershed and area query string connection note and there is a space behind it! MyFeatureLayer. setDefinitionExpression (SQL _r); // use setDefinitionExpression for query // set the selected flag parameter var selectionSymbol = new SimpleFillSymbol (SimpleFillSymbol. STYLE_SOLID, new SimpleLineSymbol (SimpleLineSymbol. STYLE_SOLID, new Color ("blue"), 1), new Color ("blue"); myFeatureLayer. setSelectionSymbol (selectionSymbol); // sets the element layer to be selected. // listen to featurelayer click event to handle selection // from layer to the table. // when user clicks on a feature on the map, the corresponding // record will be selected in the table. // listen to the element layer Click Event and send the corresponding parameters to the element table // when the element in the local graph is selected, the property record related to this will also be selected in the element table myFeatureLayer. on ("click", function (evt) {var idProperty = myFeatureLayer. objectIdField; var feature, featureId, query1; if (evt. graphic & evt. graphic. attributes & evt. graphic. attributes [idProperty]) {feature = evt. graphic; // obtain the element shape featureId = feature. attributes [idProperty]; // obtain the element ID // instantiate the Query parameter query1 = new Query (); query1.returnGeometry = false; query1.objectIds = [featureId]; query1.where = "1 = 1 "; // retrieve all data in the query myFeatureLayer. selectFeatures (query1, FeatureLayer. SELECTION_NEW) ;}}); map. addLayer (myFeatureLayer); // Add the element query result layer myFeatureTable. refresh (); // update the element table // listen to show-attachments event myFeatureTable. on ("show-attachments", function (evt) {console. log ("show-attachments event-", evt) ;}); // listen to show-related-records event myFeatureTable. on ("show-related-records", function (evt) {console. log ("show-related-records event-", evt );});})

  All code:

<! DOCTYPE html> 

Thanks again to the author who posted this article. This case is for your reference only !!!

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.