【问题标题】:ArcGIS API for JavaScript, NS_ERROR_DOM_BAD_URI: Access to restricted URI deniedArcGIS API for JavaScript,NS_ERROR_DOM_BAD_URI:访问受限 URI 被拒绝
【发布时间】:2016-03-24 11:14:54
【问题描述】:

我正在遵循本指南:

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:访问受限 URI 被拒绝

在教程中他们说:

要从 ArcGIS Online 之外的门户访问 web 地图,请参考 arcgisUrl 属性并在之前设置门户 URL 的路径 调用 createMap() 方法: arcgisUtils.arcgisUrl = "http://pathto/portal/sharing/content/items";

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

【问题讨论】:

  • 删除 "arcgisUtils.arcgisUrl" 它将开始工作

标签: javascript gis arcgis arcgis-js-api


【解决方案1】:

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

首先您应该知道您使用的是公共还是私有的网络地图 ID 1a40fa5cc1ab4569b79f45444d728067。我的意思是每个人或创建它的人都可以访问它。

如您所见,我可以全局访问此 ID,因此这意味着它不是私有的,因此您无需添加门户网址

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

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

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

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


Portal URL: 之后,无论您何时注册 arcgis.com,它都会为每个网站创建一个唯一的门户 URL(安装 Portal for ArcGIS 的服务器名称)用户。只有当 webmap/item 没有共享给所有人时,我们才需要配置这个唯一的 url。在这种情况下,它会自动采用 “arcgis 在线默认门户网址”。


现在转到 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>

【讨论】:

  • 我在沙盒中一切正常,但是当我在本地或从另一台服务器运行 html 文件时,地图是空白的。屏幕底部有一条消息“正在等待 js.arcgis.com...”,但没有加载任何内容。我花了几个小时与 arcgisUtils.arcgisUrl 门户参数作斗争,但到目前为止还没有运气。
  • @user2995274 是的...这可能是因为您将此 html 文件作为网页运行。在 IIS 或 IDE (如 Visual Studio)上部署此 URL,希望它能够开始工作..
  • @user2995274 如果您仍然面临这个问题,请打开一个新问题以及确切的代码...或者如果您想直接与我联系。
猜你喜欢
  • 2013-12-21
  • 2013-06-24
  • 1970-01-01
  • 1970-01-01
  • 2010-09-08
  • 2012-03-17
  • 1970-01-01
  • 1970-01-01
  • 2015-01-20
相关资源
最近更新 更多