Arkitech

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

Discussion created by Arkitech on Sep 27, 2012
Latest reply on Oct 1, 2012 by Arkitech
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&bbox=349996.0987426975%2C328803.49911099824%2C352815.9012573025%2C329692.50088900176&bboxSR=null&imageSR=null&size=1421%2C448&f=image" 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>

Outcomes