AnsweredAssumed Answered

how to use traffic service in our application without using proxy

Question asked by craveinfotech on Mar 21, 2015
Latest reply on Mar 25, 2015 by nagrale

<!DOCTYPE html>

<html>

  <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

    <title>World Traffic</title>

 

    <link rel="stylesheet" href="http://js.arcgis.com/3.13/dijit/themes/claro/claro.css">

    <link rel="stylesheet" href="http://js.arcgis.com/3.13/esri/css/esri.css">

    <link rel="stylesheet" href="css/layout.css">

 

 

    <script src="http://js.arcgis.com/3.13/"></script>

    <script>

 

 

      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();

        //all requests to traffic.arcgis.com will proxy to the proxyUrl defined in this object.

        urlUtils.addProxyRule({

          urlPrefix: "traffic.arcgis.com", 

          proxyUrl: "/sproxy/"

        });

 

        arcgisUtils.createMap("327687e9b2664d65aa7a7f5c85398cff","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();

 

        });

 

        });

 

      });

 

 

    </script>

  </head>

 

  <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>

</html>

 

 

The above code works in ESRI Sandbox , but does not work when I use the above code in  separate .html file , may be because of proxyUrl.

Please help.......

Outcomes