【问题标题】:ArcGIS Web JS API "Invalid portal item type 'Map Service', expected 'Web Map'"ArcGIS Web JS API“无效的门户项目类型‘地图服务’,预期为‘网络地图’”
【发布时间】:2021-07-22 20:05:11
【问题描述】:

我想使用 ArcGIS Web API 显示位于https://cartes.nicecotedazur.org/portal/apps/webappviewer/index.html?id=237a9574a4b34ffaba8754a61235e828 的地图。

我首先尝试使用 ArcGIS Sandbox 显示它:https://developers.arcgis.com/javascript/latest/sample-code/sandbox/i

这是代码示例:

  require(["esri/views/MapView", "esri/WebMap", "esri/config"], function (
    MapView,
    WebMap,
    esriConfig
  ) {
    esriConfig.portalUrl = "https://cartes.nicecotedazur.org/portal/";
    var webmap = new WebMap({
      portalItem: {
        id: "b79f6b55f4a0427b8c32ba805fa6e71a"
      }
    });

    var view = new MapView({
      map: webmap,
      container: "viewDiv"
    });
  });

但是在加载时控制台中会弹出此错误消息:

"Invalid portal item type 'Map Service', expected 'Web Map'"

我没有找到任何引用此错误的文章

我尝试了两个不同的 id:

  • b79f6b55f4a0427b8c32ba805fa6e71a 是网络地图 ID
  • 237a9574a4b34ffaba8754a61235e828 这是在 url 中找到的 id

【问题讨论】:

    标签: javascript arcgis arcgis-js-api


    【解决方案1】:

    这是您的实际代码吗?我看到的第一个问题是:

    var view = new WebMap({
      map: webmap,
      container: "viewDiv"
    });
    

    应该是这样的

    var view = new MapView({
      map: webmap,
      container: "viewDiv"
    });
    

    这样,我收到了该资源的 CORS 错误。 Here's a codesandbox。我不确定那是不是因为我使用的是 CSB。我可以访问layer json directly,这意味着您的设置是正确的。但这让我怀疑,如果您遇到 CORS 错误,您可能需要set up a proxy。

    【讨论】:

    • 我的错,确实是个错误。我实际上使用var view = new MapView(...)。关于CORS错误,我会看看并更新你
    猜你喜欢
    • 2023-02-16
    • 2014-12-08
    • 2012-10-01
    • 1970-01-01
    • 2020-06-20
    • 2023-04-08
    • 2018-05-16
    • 2020-04-25
    • 1970-01-01
    相关资源
    最近更新 更多