ArcGIS API for JavaScript,NS_ERROR_DOM_BAD_URI:访问受限制的URI被拒绝

问题描述 投票:0回答:1

我正在按照本指南操作:

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地图,请在调用createMap()方法之前引用arcgisUrl属性并设置门户URL的路径:arcgisUtils.arcgisUrl =“http://pathto/portal/sharing/content/items”;

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

javascript gis arcgis arcgis-js-api
1个回答
1
投票

我们将一步一步地解决上述问题:

首先,您应该知道您使用公共或私人的webmap ID 1a40fa5cc1ab4569b79f45444d728067。我的意思是每个人或创建它的创建者都可以访问它。

正如您所看到的,我可以全局访问此Id,因此它意味着它不是私有的,因此您不需要添加门户网站URL

(以下是您可以访问网页地图的两种方式,只需替换以下网址末尾的网络地图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时才需要Portal URL。


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


现在去this online sample并在那里替换你的webmap 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>
© www.soinside.com 2019 - 2024. All rights reserved.