AnsweredAssumed Answered

Connecting to secure map service within javascript app

Question asked by djh78 on Mar 2, 2020
Latest reply on Mar 3, 2020 by djh78

Hi

 

I have read all kinds of help documentation on this subject but can't seem to find the best fit, or get any to work. I have written the javascript app below. The layer being used is secured as I would not want the contents being made available to everyone, except for people who are using the app. They will have already logged in to get this far so I just need the application to handle the logging in to get the map data back. (ie at the moment it asks for an ArcGIS server log in). I can find lots of information about accessing secure applications, but not specific layers within a javascript app...any help would be great.

 

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>DH Test Map</title>
    <style>
      html, body, #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
 
 <link rel="stylesheet" href="https://js.arcgis.com/4.14/esri/themes/light/main.css">
 <script src="https://js.arcgis.com/4.14/"></script>
 
 
  <script>
    require([
    "esri/WebMap",
    "esri/views/MapView",
 "esri/layers/FeatureLayer",
 "esri/core/urlUtils",
 "esri/tasks/support/Query",
    ], function(WebMap, MapView, FeatureLayer, urlUtils, Query) {
 
 
     var urlObject = urlUtils.urlToObject(document.location.href);
  runValidaty(urlObject);
  
    var impactedPropertiesLayer = new FeatureLayer({
   url: "https://MYENTERPRISESERVER/server/rest/services/TEST/AffectedPropertiesSecure/MapServer/0",
   definitionExpression:expression,
   popupTemplate: { title: "{UPRN}", content: "{ImpactLevel_ID}"},
  });
  
  impactedPropertiesLayer.when(function() {
   return impactedPropertiesLayer.queryExtent();
   }).then(function(response) {
   view.goTo(response.extent);
  });

  var webmap = new WebMap({
   portalItem: {
     id: "1a409e5d6939452cbb27fee5f05a2140"
   }
  });

  var view = new MapView({
   container: "viewDiv",
   map: webmap,
   zoom: 6
  });
  

     
 webmap.add(impactedPropertiesLayer)

 var expression;
 function runValidaty(UrlPropertiesObj){
 expression ="";
 Object.keys(UrlPropertiesObj.query).forEach(function(key,index) {
 
 var objectValue = UrlPropertiesObj.query[key];
 if(objectValue){
 //first time round
 
 if(parseInt(objectValue)){
 expression += key + "="+objectValue+"";
  
 }else{
 expression += key + "='"+objectValue+"'";
 }
  
  
 var nextObj = Object.keys(UrlPropertiesObj.query)[index+ 1];
  if(UrlPropertiesObj.query[nextObj]){
  //yes there is a property in the next loop
  expression += "AND "
  }
  }
 
 });
 }
 

   
    });
  </script>
</head>
<body>
  <div id="viewDiv"></div>
</body>
</html>

Outcomes