首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >替代arcgis featureLayer?

替代arcgis featureLayer?
EN

Stack Overflow用户
提问于 2014-12-15 20:34:48
回答 1查看 1.4K关注 0票数 0

我已经使用arcgis javascript构建了一个应用程序。它使用功能层来获取信息,并允许在地图上进行不同的搜索,但是15个功能层确实陷入了我客户服务器的困境,所以我们正在研究替代方案。我试图找到其他可以处理的东西,这并不会扼杀我的应用程序的功能,但我还没有找到解决方案。应用程序目前具有以下搜索功能:

1)在一层中显示所有特征

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

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

上述所有搜索选项都可以通过在层上执行查询(使用queryFeatures())来显示具有categoryX和/或industryY的特性,从而减少其显示的功能。

当功能层打开或关闭时,除了它给服务器带来的冲击之外,所有这些功能都像一种魅力。

有没有一种不依赖于特性层来完成所有这一切的方法?

编辑:下面是我正在做的一个例子:buffer

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-17 13:52:35

使用功能继电器可以让你直接在你的客户上拥有几何图形。在某些情况下(例如,如果需要编辑特性),在客户端上设置几何图形是强制性的,但在许多其他情况下,这并不是更好的选择。

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

编辑:我修改了你贴出的样本

代码语言:javascript
复制
      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;
    }
  });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27492635

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档