Select to view content in your preferred language

Help beginner

760
5
09-18-2013 09:37 PM
PhuongNguyen_Thanh
Emerging Contributor
:cool: Hi everybody ! Nice to meet you !

I'm practicing about the Direction and Routing sample in https://developers.arcgis.com/en/javascript/jssamples/routetask_basic_servicearea.html

My question is how can we dot a state (ex: Atlanta) and show us everywhere in the state we dotted that we can go by car in 12 minute ?

Please help me !!!! 😞
0 Kudos
5 Replies
KenBurcham
Deactivated User
Hi Phuong,

  I think you are right to study that sample.  It is very similar to what you are trying to do.  What specifically are you having trouble with?  Can you post some code?  We don't want to do your work for you, just help if you get stuck.  😉

ken.
0 Kudos
PhuongNguyen_Thanh
Emerging Contributor
Hi Phuong,

  I think you are right to study that sample.  It is very similar to what you are trying to do.  What specifically are you having trouble with?  Can you post some code?  We don't want to do your work for you, just help if you get stuck.  😉

ken.


Hi Ken,

Thank you for your reply, I will post code soon 🙂 wish you a good lucky day and best working day !!!!!
0 Kudos
PhuongNguyen_Thanh
Emerging Contributor
Hi Phuong,

  I think you are right to study that sample.  It is very similar to what you are trying to do.  What specifically are you having trouble with?  Can you post some code?  We don't want to do your work for you, just help if you get stuck.  😉

ken.


Hi Ken! Here is my code

<!DOCTYPE html>

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">

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

    <script type="text/javascript">djConfig = { parseOnLoad:true };</script>

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

    <title>Routing</title>
    <style>
        html, body, #map{
        height: 100%;
        margin: 0;
        padding: 0;
        }
    </style>

    <script>
        dojo.require("esri.map");
        dojo.require("esri.arcgis.utils");
        dojo.require("esri.tasks.servicearea");

        var map, serviceAreaTask, params, clickpoint;
        function init()
        {
         
map = new esri.Map("map", {
        basemap: "streets",
        center: [-86.18, 32.22],
        zoom: 12
      });

            dojo.connect(map, "onClick", mapClickHandler);

            params = new esri.tasks.ServiceAreaParameters();
            params.defaultBreaks = [12];
            params.outSpatialReference = map.spatialReference;
            params.returnFacilities = false;

            serviceAreaTask = new esri.tasks.ServiceAreaTask("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Service Area");
        }

       function mapClickHandler(evt) {
      clickpoint = evt;
      map.graphics.clear(); //clear existing graphics   
      //define the symbology used to display the results and input point
      var pointSymbol = new esri.symbol.SimpleMarkerSymbol(
        esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND,
        20,
        new esri.symbol.SimpleLineSymbol(
          esri.symbol.SimpleLineSymbol.STYLE_SOLID,
          new dojo.Color([88,116,152]), 2
        ),
        new dojo.Color([88,116,152,0.45])
      );
      var inPoint = new esri.geometry.Point(evt.mapPoint.x,evt.mapPoint.y,map.spatialReference);
      var location = new esri.Graphic(inPoint,pointSymbol);

      map.graphics.add(location);
      var features = [];
      features.push(location);
      var facilities = new esri.tasks.FeatureSet();
      facilities.features = features;
      params.facilities = facilities;

      //solve
      serviceAreaTask.solve(params,function(solveResult){
        var result = solveResult;
        var serviceAreaSymbol = new esri.symbol.SimpleFillSymbol(
          esri.symbol.SimpleFillSymbol.STYLE_SOLID, 
          new esri.symbol.SimpleLineSymbol(
            esri.symbol.SimpleLineSymbol.STYLE_SOLID,
            new dojo.Color([232,104,80]), 2
          ),
          new dojo.Color([232,104,80,0.25])
        );
        var polygonSymbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,  new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
              new dojo.Color([232,104,80]), 2),new dojo.Color([232,104,80,0.25]));
        dojo.forEach(solveResult.serviceAreaPolygons, function(serviceArea){
          serviceArea.setSymbol(polygonSymbol);
          map.graphics.add(serviceArea);
        });
       
      },function(err){
        console.log(err.message);
      });
    }    

    dojo.ready(init);
    </script>
</head>
<body class="claro">
    <div id="map"></div>
</body>
</html>

     params.defaultBreaks = [12];  in [] if I type 2, it will give me a result 2 minute ?
0 Kudos
KenBurcham
Deactivated User
Yes, that's correct.
0 Kudos
PhuongNguyen_Thanh
Emerging Contributor
Yes, that's correct.


Many thanks, Ken !!!!!

Can you explain for me some codes ?

1/ How can I know the exactly the Latitude and Longitude of a state of America. In my code, I use this code "center: [-86.18, 32.22]" to know the direction of Alabama capitol?

2/ params.outSpatialReference = map.spatialReference;
params.returnFacilities = false;
-----------------------------------------------------
var features = [];
features.push(location);
var facilities = new esri.tasks.FeatureSet();
facilities.features = features;
params.facilities = facilities;

what do these code mean 😄 ?

I will be grateful if you help me 🙂

Best Regards,

Phuong Nguyen
0 Kudos