首页 文章

arcgis featureLayer的替代方案?

提问于
浏览
0

我有一个使用arcgis javascript API构建的应用程序 . 它使用要素图层来提取信息并允许在 Map 上进行不同的搜索,但是15个要素图层确实让我的客户端服务器陷入困境,所以我们正在寻找替代方案 . 我试图找到其他可以使用的东西,但不会破坏我的应用程序的功能,但我还没有找到解决方案 . 该应用程序目前具有以下搜索功能:

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

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

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

所有上述搜索选项都可以通过在图层上执行查询(使用queryFeatures())来显示其显示的功能,以仅显示具有categoryX和/或industryY的功能 .

除了打开或关闭要素图层时,它给它们的服务器提供了一个魅力 .

有没有办法在不依赖于要素图层的情况下完成所有这些?

编辑:这里's an example of what I'我在做:http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=query_buffer

1 回答

  • 1

    使用featurelayers可以直接在客户端上使用几何图形 . 在某些情况下,在客户端上具有几何图形是必需的(例如,如果您需要编辑功能),但在许多其他情况下,它不是更好的选择 .

    为了实现您的目标,您可以使用许多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;
        }
      });
    

相关问题