我有一个使用arcgis javascript API构建的应用程序。它使用要素图层提取信息并允许在地图上进行不同的搜索,但是15个要素图层确实使我的客户的服务器陷入瘫痪,因此我们正在寻找替代方法。我试图找到其他与之兼容的方法并不会杀死我的应用程序的功能,但是我还没有找到解决方案。该应用程序当前具有以下搜索功能:

1)显示图层中的所有要素

2)在可设置的半径内显示图层中的所有要素

3)在用户当前位置的可设置半径范围内显示所有功能(如果允许访问)

通过在图层上执行查询(使用queryFeatures())以仅显示具有categoryX和/或industryY的要素,可以将上述所有搜索选项的显示要素缩小。

无论何时打开或关闭要素图层,所有功能都像是一种魅力,它不仅为服务器提供了帮助。

有没有一种方法可以不依赖要素图层来完成所有这些工作?

编辑:这是我正在做的一个例子:http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=query_buffer

最佳答案

使用要素图层可让您直接在客户端上具有几何。在某些情况下(例如,如果您需要编辑要素),必须在客户端上具有几何形状,但在其他情况下,这不是更好的选择。

为了实现您的目标,您可以只使用许多ArcGISDynamicMapServiceLayer并标识或查询任务以从服务器获取信息。

编辑:我已经修改了您发布的示例

      var map;
  require([
    "esri/map", "esri/layers/ArcGISDynamicMapServiceLayer",
    "esri/tasks/query", "esri/geometry/Circle",
    "esri/graphic", "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",
    "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", "esri/renderers/SimpleRenderer",
    "esri/config", "esri/Color", "dojo/dom","esri/tasks/QueryTask", "dojo/domReady!"
  ], function(
    Map, ArcGISDynamicMapServiceLayer,
    Query, Circle,
    Graphic, InfoTemplate, SimpleMarkerSymbol,
    SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer,
    esriConfig, Color, dom, QueryTask
  ) {

    esriConfig.defaults.io.proxyUrl = "/proxy/";

    map = new Map("mapDiv", {
      basemap: "streets",
      center: [-95.249, 38.954],
      zoom: 14,
      slider: false
    });


    var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer");


    var queryTask = new QueryTask("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/0");



    var circleSymb = new SimpleFillSymbol(
      SimpleFillSymbol.STYLE_NULL,
      new SimpleLineSymbol(
        SimpleLineSymbol.STYLE_SHORTDASHDOTDOT,
        new Color([105, 105, 105]),
        2
      ), new Color([255, 255, 0, 0.25])
    );
    var circle;

    var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CIRCLE,
            12,
            new SimpleLineSymbol(
             SimpleLineSymbol.STYLE_NULL,
             new Color([247, 34, 101, 0.9]),
                 1
                ),
                new Color([207, 34, 171, 0.5])
    );

    //when the map is clicked create a buffer around the click point of the specified distance.
    map.on("click", function(evt){
      circle = new Circle({
        center: evt.mapPoint,
        geodesic: true,
        radius: 1,
        radiusUnit: "esriMiles"
      });
      map.graphics.clear();
      map.infoWindow.hide();
      var graphic = new Graphic(circle, circleSymb);
      map.graphics.add(graphic);

      var query = new Query();
      query.geometry = circle.getExtent();
      //use a fast bounding box query. will only go to the server if bounding box is outside of the visible map

      require([
        "esri/tasks/query"
      ], function (Query) {

          var query = new Query();
          query.spatialRelationship = Query.SPATIAL_REL_CONTAINS;
          query.geometry = circle;
          query.returnGeometry = true;
          queryTask.execute(query, function (fset1) {
              dojo.forEach(fset1.features, function (feature, i) {

                  console.log("feature", feature);
                  feature.setSymbol(symbol);

                  map.graphics.add(feature);

              });
          });
      });
    });

    function selectInBuffer(response){
      var feature;
      var features = response.features;
      var inBuffer = [];
      //filter out features that are not actually in buffer, since we got all points in the buffer's bounding box
      for (var i = 0; i < features.length; i++) {
        feature = features[i];
        if(circle.contains(feature.geometry)){
          inBuffer.push(feature.attributes[featureLayer.objectIdField]);
        }
      }
      var query = new Query();
      query.objectIds = inBuffer;
      //use a fast objectIds selection query (should not need to go to the server)
      featureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(results){
        var totalPopulation = sumPopulation(results);
        var r = "";
        r = "<b>The total Census Block population within the buffer is <i>" + totalPopulation + "</i>.</b>";
        dom.byId("messages").innerHTML = r;
      });
    }

    function sumPopulation(features) {
      var popTotal = 0;
      for (var x = 0; x < features.length; x++) {
        popTotal = popTotal + features[x].attributes["POP2000"];
      }
      return popTotal;
    }
  });

关于javascript - 替代arcgis featureLayer?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27492635/

10-12 00:54