JavaScript、NS_ERROR_DOM_BAD_URI 的 ArcGIS API:拒绝访问受限 URI

ArcGIS API for JavaScript, NS_ERROR_DOM_BAD_URI: Access to restricted URI denied

我正在遵循此指南:

https://developers.arcgis.com/javascript/jshelp/intro_agstemplate_amd.html

我正在使用他们在教程中使用的 Web 地图 ID:1a40fa5cc1ab4569b79f45444d728067

但是,当我 运行 我的代码时:

var map;
require([
"esri/map",
"esri/arcgis/utils",
"dojo/domReady!"
], function(Map, arcgisUtils) {
    arcgisUtils.arcgisUrl = "file:///C:/Users/Bryan/Desktop/gis.html";
    arcgisUtils.createMap("1a40fa5cc1ab4569b79f45444d728067 ", "mapDiv").then(function(response) {
        map = response.map;
    });
});

我收到以下错误:

NS_ERROR_DOM_BAD_URI: Access to restricted URI denied

在教程中他们说了以下内容:

To access a web map from a portal outside of ArcGIS Online, reference the arcgisUrl property and set the path to your portal URL before calling the createMap() method: arcgisUtils.arcgisUrl = "http://pathto/portal/sharing/content/items";

但是什么是门户 URL?我的门户是什么 URL?

我们将逐步解决以上问题:

首先你应该知道你的网络地图 ID 1a40fa5cc1ab4569b79f45444d728067 你正在使用它的 public 或私人。我的意思是每个人或创建它的创建者都可以访问它。

如您所见,我可以在全球范围内访问此 ID,这意味着它不是私有的,因此您无需添加门户 url

(以下是访问您的网络地图的两种方式,只需替换下面 urls 末尾的网络地图 ID)。

以上Webmap ID的项目详情: click here to see the details of webmap id.

地图查看器中的 Webmap ID: click here to see webmap id in map viewer.

仅当 webmap id 未与所有人共享时才需要门户 url。


Portal URL: 每当您注册 arcgis.com 之后,它都会创建一个独特的门户 url (为每个用户安装 Portal for ArcGIS 的服务器名称 )。这个唯一的url只有在ifwebmap/item不共享给所有人的时候才需要配置。在这种情况下,它会自动 "arcgis online default portal url".


现在转到 this online sample 并在那里替换您的网络地图 ID。它会正常工作。


运行代码:

require([
        "dojo/parser",
        "dojo/ready",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane",
        "dojo/dom",
        "esri/map", 
        "esri/urlUtils",
        "esri/arcgis/utils",
        "esri/dijit/Legend",
        "esri/dijit/Scalebar",
        "dojo/domReady!"
      ], function(
        parser,
        ready,
        BorderContainer,
        ContentPane,
        dom,
        Map,
        urlUtils,
        arcgisUtils,
        Legend,
        Scalebar
      ) {
        ready(function(){

        parser.parse();

//if accessing webmap from a portal outside of ArcGIS Online, uncomment and replace path with portal URL
       //arcgisUtils.arcgisUrl = "https://pathto/portal/sharing/content/items";
        arcgisUtils.createMap("1a40fa5cc1ab4569b79f45444d728067 ","map").then(function(response){
          //update the app 
          dom.byId("title").innerHTML = response.itemInfo.item.title;
          dom.byId("subtitle").innerHTML = response.itemInfo.item.snippet;

          var map = response.map;



          //add the scalebar 
          var scalebar = new Scalebar({
            map: map,
            scalebarUnit: "english"
          });

          //add the legend. Note that we use the utility method getLegendLayers to get 
          //the layers to display in the legend from the createMap response.
          var legendLayers = arcgisUtils.getLegendLayers(response); 
          var legendDijit = new Legend({
            map: map,
            layerInfos: legendLayers
          },"legend");
          legendDijit.startup();


        });


        });

      });
<link rel="stylesheet" href="https://js.arcgis.com/3.16/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css">
    <link rel="stylesheet" href="http://developers.arcgis.com/javascript/sandbox/css/styles.css">

    <script src="https://js.arcgis.com/3.16/"></script>

<body class="claro">
    <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'" style="width:100%; height:100%;">
      <div id="header" class="shadow roundedCorners" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'">
        <div id="title"></div>
        <div id="subtitle"></div>
      </div>
      <div id="map" class="roundedCorners shadow" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'"></div>
      <div id="rightPane" class="roundedCorners shadow" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'" >
        <div id="legend"></div>
      </div>
    </div>
  </body>