【问题标题】:Arcgis API for Javascript 4 Calcite map add feature layerArcgis API for Javascript 4 Calcite 地图添加要素图层
【发布时间】:2016-11-23 21:06:40
【问题描述】:

我是 ArcGIS API for Javscript 4.0 API 的新手。使用 API 网站上的方解石样本。在哪里可以将要素图层添加到地图视图和场景视图?本质上,我正在尝试合并要素图层示例 这里:https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer/index.html

/********************
     * Add feature layer
     ********************/

    // Carbon storage of trees in Warren Wilson College.
    var featureLayer = new FeatureLayer({
      url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
    });

    map.add(featureLayer);

这里有方解石地图示例: https://developers.arcgis.com/javascript/latest/sample-code/frameworks-bootstrap/index.html

但不确定要将图层添加到哪个部分。我已经尝试了几次。见下文。谢谢

      /******************************************************************
   *
   * Create the map and scene view and ui components
   * 
   ******************************************************************/

  // Map
  var map = new Map({
    basemap: app.basemap
  });
  app.mapView = new MapView({
    container: "mapViewDiv",
    map: map,
    center: app.center,
    scale: app.scale,
    padding: app.viewPadding,
    popup: new Popup({
      dockOptions: app.dockOptions
    }),
    ui: {
      components: app.uiComponents
    }
  });

  // Scene
  var mapScene = new Map({
    basemap: app.basemap,
    ground: "world-elevation"
  });
  app.sceneView = new SceneView({
    container: "sceneViewDiv",
    map: mapScene,
    center: app.center,
    scale: app.scale,
    padding: app.viewPadding,
    popup: new Popup({
      dockOptions: app.dockOptions
    }),
    ui: {
      components: app.uiComponents
    }
  });

  // Set the active view to scene
  app.activeView = app.mapView;

  // Create the search widget and add it to the navbar instead of view
  app.searchWidget = new Search({
    view: app.activeView
  }, "searchWidgetDiv");
  app.searchWidget.startup();

  // IS THIS WHERE I CAN ADD LAYERS??????????????????
  var featureLayer = new FeatureLayer({
      url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0"
    });

  app.mapView.map.add(featureLayer);
  app.sceneView.map.add(featureLayer);

【问题讨论】:

    标签: esri arcgis-js-api


    【解决方案1】:

    您可以在 4.0 中直接将它们添加到地图对象中。请查看此处的 API 文档以获取一个小示例:https://developers.arcgis.com/javascript/latest/api-reference/esri-Map.html#layers

    基本上它看起来像这样:

    var featureLayer = new FeatureLayer(url);
    var map = new Map({
      basemap: app.basemap,
      layers: [featureLayer]
    });
    

    您需要确保将其应用于您希望它们在其上渲染的任何地图。

    【讨论】:

    • 如果这篇文章有什么不正确的地方,请告知它是什么或提供正确的答案,以便为了社区的利益而更新它
    【解决方案2】:

    您可能需要以下代码:

      var countyLayer = new FeatureLayer({
          url: "http://127.0.0.1:6080/arcgis/rest/services/newyourk/MapServer/1"
      });
      app.map.add(countyLayer);
    

    【讨论】:

      猜你喜欢
      • 2020-08-08
      • 2021-12-16
      • 1970-01-01
      • 2015-10-27
      • 2016-03-28
      • 2018-07-12
      • 2015-05-08
      • 1970-01-01
      • 2020-10-21
      相关资源
      最近更新 更多