点击按钮获取要素图层

时间:2017-08-01 07:54:02

标签: arcgis-js-api

如何在按钮点击和显示上获取要素图层。

Project.update({},{$set:{parameter:reqparameter}, { multi: true }, callback)
S_layer = new FeatureLayer("http://localhost:6080/arcgis/rest/services/...../MapServer/0",{
         mode: FeatureLayer.MODE_SELECTION,
        outFields: ["*"]
		
         }); 

map.addLayer(S_layer);

function soil()
{
queryTask = new esri.tasks.QueryTask("http://localhost:6080/arcgis/rest/services/...../MapServer/0"); 
			var query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["soil"];
		var name = document.getElementById("combo1").value.toString();
        query.where = "NAME = '" + name;
		<!-- queryTask.execute(query); -->
		
		S_layer.selectFeatures(query, queryTask.SELECTION_NEW, function (features) { 
			if(features[0]){
              thePoly = features[0].geometry;
              theExtent = thePoly.getExtent().expand(1.8); //Zoom out slightly from the polygon's extent
              map.setExtent(theExtent);
			}

    });
}

但是这个查询没有运行它会给出错误“init.js:89错误:无法完成操作。     在Object.g.load“。

1 个答案:

答案 0 :(得分:0)

好吧,因为我不知道你想在点击按钮上添加一个图层。

以下是此代码 -

&#13;
&#13;
<!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>Hydrography - Selection mode</title>

    <link rel="stylesheet" href="https://js.arcgis.com/3.21/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.21/esri/css/esri.css">
    <style>
      html, body {
        height: 100%; 
        width: 100%; 
        margin: 0; 
        padding: 0;
      }
      body {
       background-color: white; 
       overflow: hidden; 
       font-family: sans-serif;
      }
    

    </style>

    

  </head>
  <body class="claro">
    

   <br>
      Add layers- 
<button type="button" id="addWaterBodies" class = "button" >water Bodies</button>
		 
		 <button type="button" id="addRivers" class = "button"  >River</button>   <br> <br>
            <div id="map"  >
      </div>
<script src="https://js.arcgis.com/3.21/"></script>
    <script>
      var map;

      require([
        "esri/map", 
        "esri/dijit/editing/Editor", "esri/dijit/editing/TemplatePicker",
        "esri/tasks/GeometryService",
        "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer",
        "dojo/i18n!esri/nls/jsapi", "esri/config",
        "dojo/_base/array", "dojo/keys", "dojo/parser",
        "dijit/layout/BorderContainer", "dijit/layout/ContentPane",
        "dojo/domReady!"
      ], function(
        Map, 
        Editor, TemplatePicker,
        GeometryService,
        ArcGISDynamicMapServiceLayer, FeatureLayer,
        esriBundle, esriConfig,
        arrayUtils, keys, parser
      ) {
        parser.parse();

        
        map = new Map("map", {
          basemap: "hybrid",
          center: [-96.325, 37.855],
          zoom: 13
        });

        map.infoWindow.resize(400,300);

    function addWaterBodies(){
      var waterBodiesLayer=   map.getLayer("waterLayerId");
   if(!waterBodiesLayer){
             waterBodiesLayer = new FeatureLayer("https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/0", {
  id : "waterLayerId",
            outFields: ["*"],
          });
       map.addLayer(waterBodiesLayer);
   } else {
     alert("water bodies layer already added");
   }
    }
 
   function addRivers(){
   var riversLayer=   map.getLayer("riverLayerId");
   if(!riversLayer){
          riversLayer = new FeatureLayer("https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/1", {
          id:"riverLayerId",
          outFields: ["*"]
        });
        map.addLayer( riversLayer);
   } else {
     alert("River layer already added");
   }
   }
   
   document.getElementById("addWaterBodies").onclick = addWaterBodies;
   document.getElementById("addRivers").onclick = addRivers;
      });
    </script>
  </body>
</html>
&#13;
&#13;
&#13;

如果您需要任何详细信息,请与我们联系。

希望这会对您有所帮助:)