measure distance and change back to moving around

Discussion created by hallilindal on Jul 2, 2010
Latest reply on Nov 23, 2010 by kathy68

so I'm trying to make my program work that way, that when I check my checkbox I will start measuring distance on my map, At the moment I can only do that when I have it active when I load the map, by that I mean when I have it all out side the checkbox so it doesn't matter if it is clicked or not I just measure the distance. and I was wondering if any one her know how I could fix this will put some cod her bellow so you can see how I did it.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTM...tp://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7" />

  <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dojox/grid/resources/Grid.css">
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dojox/grid/resources/tundraGrid.css">

    <link type="text/css" href="../src/themes/base/jquery.ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="../src/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../src/ui/jquery.ui.core.js"></script>
<script type="text/javascript" src="../src/ui/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../src/ui/jquery.ui.button.js"></script>
<link type="text/css" href="../demos.css" rel="stylesheet" />
<script type="text/javascript">
  djConfig = {
  #format { margin-top: 2em; }

  <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">

<script type="text/javascript" src="../src/dojo.js.uncompressed.js" ></script>
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
    <script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
    <script type="text/javascript">

      var map, startExtent;
      var grid;
      var geometryService;

function init() {
     dojo.connect(grid, "onRowClick", onRowClickHandler);
  startExtent = new esri.geometry.Extent({"xmin":yourinfo,"ymin":yourinfo,"xmax":yourinfo,"ymax":yourinfo,"spatialReference":{"wkid":yourinfo}});
        map = new esri.Map("map", { extent: startExtent });

        dojo.connect(map,"onLoad", function(map) {map.infoWindow.resize(250, 100);} );
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("yourinfo");

        geometryService = new esri.tasks.GeometryService("yourinfo");
        var resizeTimer;
        dojo.connect(map, 'onLoad', function(theMap) {
          dojo.connect(dijit.byId('map'), 'resize', function() {  //resize the map if the div is resized
            resizeTimer = setTimeout( function() {
            }, 500);
   //teikna línu fyrir veglengd.
       function initFunctionality(map) {
            var tb = new esri.toolbars.Draw(map);

              //on draw end add graphic, project it, and get new length
              dojo.connect(tb, "onDrawEnd", function(geometry) {
              var graphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol()));.
              geometryService.project([graphic],new esri.SpatialReference({"wkid":yourinfo}));

    //output distanse
           function outputDistance(result) {
            dojo.byId("distance").innerHTML = dojo.number.format(result.lengths[0] / 1000) + " kilometers";

   function validateVegalengd(veg){
   dojo.connect(map, "onLoad", initFunctionality);

   dojo.connect(geometryService, "onLengthsComplete", outputDistance);
   dojo.connect(geometryService, "onProjectComplete", function(graphics) {



<body class="tundra">
  <div id="cool" >
      <form name="Sup">
<input type="checkbox" id="check1" name=veg1 onclick="return validateVegalengd(veg1);"/><label for="check1">Vegalengd</label>
<div dojotype="dijit.layout.BorderContainer"  gutters="false"
    style="width: 100%; height: 100%; margin: 0;">
      <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="overflow:hidden;">

I tried to make the code as shot as possible, not sure how good job I did,   but as it is now if you click the check box it takes you to validatevegalengd there it checks if the checkbox was checked or unchecked after that it should be able to start the drawing function but it dose not matter. on the other hand if I start with he drawing function no the checkbox validation just inside the main function where I load the map at start it works fine. so if there is some one that can help me fix this it would be awesome:)