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

时间:2016-03-24 11:14:54

标签: javascript gis arcgis arcgis-js-api

我正在遵循本指南:

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是什么?

1 个答案:

答案 0 :(得分:1)

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

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

正如您所看到的,我可以全局访问此ID,这意味着它不是私密的,因此您不需要添加门户网址

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

上述网站地图ID的详细信息: click here to see the details of webmap id.

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

仅当未向所有人共享webmap id时才需要Portal网址。

Portal URL :在您注册arcgis.com之后,它会创建一个唯一的门户网址网址(安装Portal for ArcGIS的服务器名称)为每个用户。这个唯一网址只有在不向所有人共享webmap / 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>
&#13;
&#13;
&#13;