2017-04-03 11 views
0

ArcGIS Online 공개 계정이 있고 웹 사이트에 WebMap을 추가했습니다. LINKArcGIS Online WebMap 인증 시간 초과

그리고 나는이 ESRI의 참조 페이지와 같은 내 웹 사이트에 내 WebMap를 추가하려고 :

내는 ArcGIS 온라인 WebMap이 ESRI의 샘플처럼 보인다. 페이지 중앙에지도가 표시됩니다. LINK

내 웹 맵이 내 웹 페이지에 잘 표시됩니다. 내 웹 페이지에 액세스하면 WebMap에서 내 ID와 암호를 묻습니다. 내가 그것을 입력하면, 그것은 내지도를 보여줍니다.

하지만 다른 페이지로 이동 한 다음 다시지도 페이지로 이동하면 다시 묻습니다. 시간 제한을 설정하여 페이지에 액세스 할 때마다 로그인 할 필요가 없습니까?

답변

1

내가이 질문을 한 이유는 내 코드를 단순화하고 프런트 엔드에서 코드 작업을 수행 할 수있는 방법이 있는지 알아 보는 것입니다.

ESRI에서 제공 한 OAuth를 조사한 결과 esri/IdentityManager이 사용되었습니다. esri/IdentityManager 패키지를 사용할 참조가있었습니다.

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/LayerList", 
      "esri/graphic", 
      "esri/symbols/PictureMarkerSymbol", 
      "esri/symbols/TextSymbol", 
      "esri/geometry/Point", 
      "esri/dijit/Scalebar", 
      "dojo/_base/unload", 
      "dojo/cookie", 
      "dojo/json", 
      "esri/config", 
      "esri/IdentityManager", 
      "esri/layers/FeatureLayer", 
      "dojo/domReady!" 
     ], function (
      parser, 
      ready, 
      BorderContainer, 
      ContentPane, 
      dom, 
      Map, 
      urlUtils, 
      arcgisUtils, 
      Legend, 
      LayerList, 
      Graphic, 
      PictureMarkerSymbol, 
      TextSymbol, 
      Point, 
      Scalebar, 
      baseUnload, 
      cookie, 
      JSON, 
      esriConfig, 
      esriId, 
      FeatureLayer 
     ) { 

      var mapOptions = { 
      basemap: "topo", 
        autoResize: true, // see http://forums.arcgis.com/threads/90825-Mobile-Sample-Fail 
        center: [currentPosition.lng, currentPosition.lat], 
        zoom: 15, 
        logo: false 
     }; 

      // cookie/local storage name 
      var cred = "esri_jsapi_id_manager_data"; 

      // store credentials/serverInfos before the page unloads 
      baseUnload.addOnUnload(storeCredentials); 

      // look for credentials in local storage 
      loadCredentials(); 

      parser.parse(); 

      esriConfig.defaults.io.proxyUrl = "/proxy/"; 

      //Create a map based on an ArcGIS Online web map id 
      arcgisUtils.createMap('PUT-YOUR-ESRI-KEY', "esriMapCanvas", { mapOptions: mapOptions }).then(function (response) { 

       var map = response.map; 

       // add a blue marker 
        var picSymbol = new PictureMarkerSymbol(
          'http://static.arcgis.com/images/Symbols/Shapes/RedPin1LargeB.png', 50, 50); 
        var geometryPoint = new Point('SET YOUR LAT', 'SET YOUR LONG'); 
        map.graphics.add(new Graphic(geometryPoint, picSymbol)); 

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

       //add the map layers 
       var mapLayers = new LayerList({ 
        map: map, 
        layers: arcgisUtils.getLayerList(response) 
       }, "esriLayerList"); 
       mapLayers.startup(); 

       //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 
       }, "esriLegend"); 
       legendDijit.startup(); 
      }); 

      function storeCredentials() { 
       // make sure there are some credentials to persist 
       if (esriId.credentials.length === 0) { 
        return; 
       } 

       // serialize the ID manager state to a string 
       var idString = JSON.stringify(esriId.toJson()); 
       // store it client side 
       if (supports_local_storage()) { 
        // use local storage 
        window.localStorage.setItem(cred, idString); 
        // console.log("wrote to local storage"); 
       } 
       else { 
        // use a cookie 
        cookie(cred, idString, { expires: 1 }); 
        // console.log("wrote a cookie :-/"); 
       } 
      } 

      function supports_local_storage() { 
       try { 
        return "localStorage" in window && window["localStorage"] !== null; 
       } catch (e) { 
        return false; 
       } 
      } 

      function loadCredentials() { 
       var idJson, idObject; 

       if (supports_local_storage()) { 
        // read from local storage 
        idJson = window.localStorage.getItem(cred); 
       } 
       else { 
        // read from a cookie 
        idJson = cookie(cred); 
       } 

       if (idJson && idJson != "null" && idJson.length > 4) { 
        idObject = JSON.parse(idJson); 
        esriId.initialize(idObject); 
       } 
       else { 
        // console.log("didn't find anything to load :("); 
       } 
      } 
     }); 
:하지만 그래서 여기 arcgisUtils.createMap

을 사용하는 개인 WebMap 함께 사용에 아무런 샘플 코드를 없었다 내가 일 샘플 코드