【问题标题】:Alternative to arcgis featureLayer?替代arcgis featureLayer?
【发布时间】:2014-12-15 20:34:48
【问题描述】:

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

1) 显示图层中的所有特征

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

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

所有上述搜索选项都可以通过在图层上执行查询(使用 queryFeatures())来减少其显示的特征,以仅显示具有类别 X 和/或行业 Y 的特征。

除了在打开或关闭要素图层时给服务器带来的点击之外,这一切都像一个魅力。

有没有办法在不依赖特征层的情况下完成所有这些工作?

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

【问题讨论】:

    标签: javascript angularjs layer arcgis esri


    【解决方案1】:

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

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

    【讨论】:

    • 我了解如何使用识别和查询任务,但是我将如何根据它们是否匹配标准 X/Y 来仅显示每个图层的符号?我可以拉取实际数据,我只需要过滤可见符号。
    • 我已经编辑了答案以向您展示一个工作示例
    • 我会试试这个。非常感谢!
    • 我只是想告诉你它确实有效。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 2015-07-05
    • 2013-07-07
    • 2022-08-17
    • 2016-05-12
    相关资源
    最近更新 更多