Select to view content in your preferred language

URL Parameters - again!!! Kelly help (or anyone else!)

1120
6
09-27-2012 06:43 AM
AndyBurns
Regular Contributor
Hi

I need to accept some URL parameters from a hidden field from xml/json. It will be x,y,maxLevel,layers.

I have managed to sort out x,y,maxlevel but i am struggling to get to grips with the layers call, essentially we will write a array to say layers 0,3,4,5 etc = traffic but for now i just want to enable the layer id's to be passed to the rest service and 'turn on' these layers specified. My identify task will then only query these layers that are ''turned on''

Everything is sort of hard coded at the moment and there is no logic yet for parameters that have not been passed through etc...its only a few hours work so far as i want to get the concept right before we move deeper.

A working call internally at the moment is http://sw08agsd/DEV/urlparams_new.html?coords=351406,329248&zoomLevel=8 which i will then pass layers=0,1,2,3,4 etc to it (i understand the urlToObject but not sure on passing the objects to the service to turn on!)

I am also getting a 404 error on my initial zoom with a dynamic map service - NetworkError: 404 'bboxSR' parameter is invalid - http://sccw08ags/ArcGIS/rest/services/APILBSR/MapServer/export?dpi=96&transparent=true&format=png8&b..." with no dynamic service showing, however when i pan the map then updates...

thanks a million.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples 
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>Topographic Map</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css">
 <link rel="stylesheet" type="text/css" href="css/map_new.css">
    <style>
      html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
      .esriScalebar{
        padding: 20px 20px;
      }
      #map{
        padding:0;
      }
    </style>
    <script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.0"></script>
 <script type="text/javascript" src="http://sccw08ags/DEV/js/jquery-1.3.2.min.js"></script>
 <script type="text/javascript" src="js/identify.js"></script>
    <script type="text/javascript" src="http://sccw08ags/DEV/js/jquery.stylish-select.min.js"></script>
  <!-- jquery plugin -->
 <script type="text/javascript" src="http://sccw08ags/DEV/js/jquery/jquery.url.packed.js"></script>
    <script type="text/javascript">
      dojo.require("dijit.layout.BorderContainer");
      dojo.require("dijit.layout.ContentPane");
      dojo.require("esri.map");
   // Require for identify
   dojo.require("esri.tasks.identify");
      dojo.require("dijit.Toolbar");  
   dojo.require("dijit.layout.TabContainer"); //old tab "identify" box
      dojo.require("dijit._Widget"); //additional parameters for editing widgets
      dojo.require("dojox.layout.TableContainer");
      dojo.require("esri.arcgis.utils");
      dojo.require("dijit.form.CheckBox");
      dojo.require("dijit.layout.AccordionContainer");
   
   var units;
   var identifyTask, identifyParams; 
      var symbol;
      var layer7results, layer3results, layer4results, layer2results, layer0results, layer1results;
      var setSymbol, setSymbol1, setSymbol2, setSymbol3, setSymbol4, setSymbol5, setSymbol6;
      var layer, visible = [];
      var highlight_id1 = [], highlight_id2 = [], highlight_id3 = [], highlight_id4 = [], highlight_id5 = [], highlight_id6 = [];

      
      var map;
   var graphic;
   
      function init() {
        var initExtent = new esri.geometry.Extent({"xmin":186819,"ymin":230984,"xmax":506529,"ymax":407263,"spatialReference":{"wkid":27700}});
        map = new esri.Map("map",{
          extent:initExtent
        });

  dojo.connect(map, "onLoad", setUpIdentify);
  
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://sccw08ags/ArcGIS/rest/services/CABackground_Greyscale/MapServer");
        map.addLayer(basemap);
  
  var imageParameters = new esri.layers.ImageParameters();
        imageParameters.format = "png8";  //set the image type to PNG24, note default is PNG8.
  
  var dynamicMapService = new esri.layers.ArcGISDynamicMapServiceLayer("http://sccw08ags/ArcGIS/rest/services/APILBSR/MapServer", {"opacity":0.7});
        map.addLayer(dynamicMapService);

  dojo.connect(map, 'onLoad', function(theMap) { 
  var urlObject = esri.urlToObject(document.location.href);
  //pass url
   if(urlObject.query && urlObject.query.coords && urlObject.query.zoomLevel /*&& urlObject.query.layers*/){
        var coords = urlObject.query.coords.split(',');
 
  var x = parseFloat(coords[0]);
   console.log (coords[0]);
   //alert (coords[0]);
  var y = parseFloat(coords[1]);
   console.log (coords[1]);
   //alert (coords[1]);
        var zoomLevel = parseInt(urlObject.query.zoomLevel);
   console.log (urlObject.query.zoomLevel);
   
  /*var layers = parseInt(urlObject.query.layers);
  console.log (urlObject.query.layers);*/

   var point = esri.geometry.Point(new esri.geometry.Point(x, y));

         map.centerAndZoom(point,zoomLevel);
    if (!graphic) {
    addGraphic(point);
   }
   else { //move the graphic if it already exists
    graphic.setGeometry(point);
         }
   map.centerAt(point);
   }  
          //resize the map when the browser resizes
        dojo.connect(dijit.byId('map'), 'resize', map,map.resize);  
        });
   
   
   function addGraphic(point){
  var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 12,
          new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
          new dojo.Color([210, 105, 30, 0.5]), 8),
          new dojo.Color([210, 105, 30, 0.9])
        );
          graphic = new esri.Graphic(point, symbol);
           map.graphics.add(graphic);
  //map.graphics.add(new esri.Graphic(graphic));
   }
   
   }

      dojo.addOnLoad(init);
    </script>
  </head>
  
  <body class="claro">
    <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;">
      <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="border:1px solid #000;padding:0;">
     </div>
    </div>
 <!-- Div  for the info window order -->
 <div id="tabs" dojoType="dijit.layout.AccordionContainer">
  <div id="layer7Tab" dojoType="dijit.layout.ContentPane"></div>
  <div id="layer2Tab" dojoType="dijit.layout.ContentPane"></div>
  <div id="layer1Tab" dojoType="dijit.layout.ContentPane"></div>
  <div id="layer3Tab" dojoType="dijit.layout.ContentPane"></div>
  <div id="layer4Tab" dojoType="dijit.layout.ContentPane"></div>
  <div id="layer0Tab" dojoType="dijit.layout.ContentPane"></div>
    </div>
  </body>

</html>
0 Kudos
6 Replies
BillDaigle
Frequent Contributor
We use the following to handle any url parameters:

    
//fetch any parameters that were passed with the url
var urlParams = esri.urlToObject(document.location.href).query || {};
    
//convert each url parameter from a string to a javascript object   
for (var prop in urlParams) {
  if (urlParams.hasOwnProperty(prop)) {
    try {
      urlParams[prop] = dojo.fromJson(urlParams[prop]);
    } 
    catch (err) {
       //ignore the error
    }
  }
}


If you pass your layers as an array (i.e. layers=[0,1,2,3,4]), you should be good to go. 
Each parameter will end up as a property of the urlParams object.
0 Kudos
AndyBurns
Regular Contributor
Cheers, thats simplifies the url parameters alot.

Any ideas where i pass them to to activate those laters? I was looking at Layerinfo's but unsure.

thanks
0 Kudos
by Anonymous User
Not applicable
Try the setVisibleLayers method on the dynamic map service layer object:

dynamicMapService.setVisibleLayers(ids);
0 Kudos
AndyBurns
Regular Contributor
Hi mgleahy

thanks for the reply. I stumbled on that method a hour or so ago and it works as expected. Just need to pass my url objects as a array to the method and it should work, hardcoding works well.

Any ideas about my 404 error, still seem to be getting it :/. It seems to be missing the SR of the required image, very odd.

thanks
0 Kudos
by Anonymous User
Not applicable
Do you have an example of the /export URL that works (after you pan the map)?

The error message is complaining that the bboxSR is invalid (it is null in the URL that you've noted is receiving an error) - so I'd guess there's something that populates that parameter after the layer is initially added to the map, and that's maybe why it starts to work after you pan the map.
0 Kudos
AndyBurns
Regular Contributor
yep working url here

http://sccw08ags/ArcGIS/rest/services/APILBSR/MapServer/export?dpi=96&transparent=true&format=png8&layers=show%3A0%2C2%2C3%2C5%2C7&bbox=350098.6249894166%2C328579.59501735674%2C352190.1604224875%2C329639.25338667346&bboxSR=27700&imageSR=27700&size=1581%2C801&f=image


as you can see the bboxSR and imageSR have both been populated correctly...

I cant seem to replicate this any other time besides when the initial map loads.

Got the params working though, so cheers

     if ( urlObject.query.layers ){
     
      layers = parseInt(urlObject.query.layers);     
      var layers = urlObject.query.layers.split(',');
      console.log (layers);
      }
   


then on the map service -

    
    layer.setVisibleLayers(layers);
0 Kudos