/**
 * modified: sitrotate deselection, see NEW LINE below
 */
createMap = function() {
  myform = document.forms['carto_form'];
  
  // create a new map object with a className as argument
  mainmap = new Map("map");
  
  mainmap.geoTag = xGetElementById(div_geo_id);
  if (mainmap.geoTag != null) {
    mainmap.geoUnits = mainmap.geoTag.innerHTML;
    mainmap.geoTag.innerHTML = sprintf(mainmap.geoUnits, "_", "_");
    xShow(mainmap.geoTag);
  }
  mainmap.distanceTag = xGetElementById(div_distance_id);
  if (mainmap.distanceTag != null) {
    mainmap.distanceUnits = mainmap.distanceTag.innerHTML;
  }
  mainmap.surfaceTag = xGetElementById(div_surface_id);
  if (mainmap.surfaceTag != null) {
    mainmap.surfaceUnits = mainmap.surfaceTag.innerHTML;
  }

  initMap();

  mainmap.displayFeaturesCount();
  mainmap.snap("map");
  
  // initial selected tool
  if (typeof cw3_initial_selected_tool != "undefined") {
    // prevent interface failure if last selected tool was pdfrotate, set it to default zoomin 
    cw3_initial_selected_tool = cw3_initial_selected_tool.replace(/pdfrotate/g, "zoomin");
    cw3_initial_selected_tool = cw3_initial_selected_tool.replace(/sitrotate/g, "zoomin"); /* NEW LINE */
    eval (cw3_initial_selected_tool);
  }
  
  xHide(xGetElementById('loadbarDiv'));
};

/**
 * modified: distance rounding, see NEW CONTENT below
 */
Map.prototype.distance = function(aDisplay) {
  this.resetMapEventHandlers();
  this.setCurrentLayer('distance');
  this.getDisplay(aDisplay).setTool('draw.line');
  this.getDisplay(aDisplay).useSnapping = false;
  this.onClic = function(aFeature) {
    var distance = aFeature.getLength();
    distance = (factor == 1000) ? Math.round(distance /1000 * 100) / 100 : Math.round(distance * 10) / 10; /* NEW CONTENT */
    this.distanceTag.innerHTML = sprintf(this.distanceUnits, distance);
    this.distanceTag.style.display = "block";
    if (this.distanceTag.style.position == "absolute")
      xMoveTo(this.distanceTag, mouse_x, mouse_y);
  }
  this.onNewFeature = function(aFeature) {
    this.onToolUnset();
  };
  this.onFeatureInput = function(aFeature) {
    aFeature.operation = "";
  };
  this.onToolUnset = function() {
    //clear the distance's display layer
    this.getDisplay(aDisplay).clearLayer('distance');
    this.onCancel();
  };
  this.onCancel = function(aFeature) {
    this.distanceTag.style.display = "none";
  };
};

