function LrvCartographie(mapTypeParam) {

  this.routeNodes=[]
  this.myNode=undefined
  this.markerDragged=false
  this.isDragged=0
  this.lastIndex=undefined
  this.prevIndex=undefined
  this.allpointstab=[]
  this.pointsPassage=[]
  this.waypoints=[];
  this.gpolys=[]
  this.echelle = 5;
  this.mapType = mapTypeParam;
  this.isReadWrite = function() { return this.mapType=="RW";}
  
  this.setWaypointsFromCoordinates    = lrvCartographie_setWaypointsFromCoordinates;
  this.getCenter                       = lrvCartographie_getCenter;
  this.getStartGlatLng    = lrvCartographie_getStartGlatLng;
  this.getEndGlatLng    = lrvCartographie_getEndGlatLng;
  this.showMapInside    = lrvCartographie_showMapInside;
  
  
  this.setEchelle    = lrvCartographie_setEchelle;
  this.createGMap    = lrvCartographie_createGMap;
  
  this.addStartMarkers = lrvCartographie_addStartMarkers;
  this.addEndMarkers = lrvCartographie_addEndMarkers;
  
  this.getNewMapIcon = lrvCartographie_getNewMapIcon;
  this.setMapIconData = lrvCartographie_setMapIconData;
  this.setIconPointerData = lrvCartographie_setIconPointerData;
  
  this.setErrorHandler = lrvCartographie_setErrorHandler;
  
  this.errorHandler = function(code) {};
  
  this.loadGdirRead = lrvCartographie_loadGdirRead;
  this.loadGdirReadWrite = lrvCartographie_loadGdirReadWrite;
  this.onGDirectionsLoadWithSteps = lrvCartographie_onGDirectionsLoadWithSteps;
  
  this.splitFromPoint = lrvCartographie_splitFromPoint;
  this.manageDragnDrop = lrvCartographie_manageDragnDrop;
  
  this.freemarker_drag = lrvCartographie_freemarker_drag;
  
  this.freemarker_dragend = lrvCartographie_freemarker_dragend;
  
  this.createWaypointMarker = lrvCartographie_createWaypointMarker;
  
  this.waypointmarker_drag = lrvCartographie_waypointmarker_drag;
  
  this.getProximity=lrvCartographie_getProximity;
  
  this.getEchelle = function () { return this.echelle}
  
  this.waitForNoActivity=lrvCartographie_waitForNoActivity;
  
}

function lrvCartographie_setErrorHandler(errorHandlerParam) {
  this.errorHandler = errorHandlerParam;
}

function lrvCartographie_waitForNoActivity(callback) {
if (this.isDragged != 0) {
    window.setTimeout("savePointsAndSubmit()",200);
  } else {
    savePoints();
    document.adressesCorrectionConfirmForm.submit();
  }
}

function lrvCartographie_setWaypointsFromCoordinates(latDep, longDep, latArr, longArr, ptPassageLineString) {
   this.allpointstab[0]=new GLatLng(latDep, longDep);
    
    if (ptPassageLineString!=undefined && ptPassageLineString!="") {
  		var tableauPts = ptPassageLineString.split(";", -1);
  		for(var i=0;i<tableauPts.length-1;i++){
    	  var tabtemp = tableauPts[i].split(",",-1);
    	  this.allpointstab[this.allpointstab.length]=new GLatLng(parseFloat(tabtemp[0]), parseFloat(tabtemp[1]));
  	  }
  	}
  		   	   
    this.allpointstab[this.allpointstab.length]=new GLatLng(latArr, longArr);
}

function lrvCartographie_getCenter() {
  var latCenter=(this.getStartGlatLng().lat()+this.getEndGlatLng().lat())/2;
	var longCenter=(this.getStartGlatLng().lng()+this.getEndGlatLng().lng())/2;
  return new GLatLng(latCenter, longCenter);
}

function lrvCartographie_getStartGlatLng() {
  return this.allpointstab[0];
}

function lrvCartographie_getEndGlatLng() {
  return this.allpointstab[this.allpointstab.length-1];
}

function lrvCartographie_addStartMarkers() {
    var markerDep = new GMarker(this.getStartGlatLng(), {title:'Mon depart', icon:this.getNewMapIcon('common/img/mm_20_red.png')});
		var markerSecondDep = new GMarker(this.getStartGlatLng(), {title:'Mon depart', icon:this.getNewMapIcon('common/img/mm_A.png')});
		markerSecondDep.getIcon().iconSize = new GSize(24, 38);
		markerSecondDep.getIcon().iconAnchor = new GPoint(12, 34);		
		markerDep.genre='rouge';
	  this.map.addOverlay(markerDep);
		this.map.addOverlay(markerSecondDep);
		
		if (this.isReadWrite()) {
  		this.waypoints[0]=markerDep
  	}
		
}

function lrvCartographie_addEndMarkers() {
    var markerArr = new GMarker(this.getEndGlatLng(), {title:'Mon arrivee', icon:this.getNewMapIcon('common/img/mm_20_red.png')});
		var markerSecondArr = new GMarker(this.getEndGlatLng(), {title:'Mon arrivee', icon:this.getNewMapIcon('common/img/mm_B.png')});
		markerSecondArr.getIcon().iconSize = new GSize(24, 38);
		markerSecondArr.getIcon().iconAnchor = new GPoint(12, 34);
		markerArr.genre='rouge'
		this.map.addOverlay(markerArr);
		this.map.addOverlay(markerSecondArr);

		if (this.isReadWrite()) {
  		this.waypoints[1]=markerArr
  	}
}

function lrvCartographie_getNewMapIcon(style){
	var gIcon = new GIcon();
	this.setMapIconData(style,gIcon);
	return gIcon;
}

function lrvCartographie_setMapIconData(style, gIcon){
	gIcon.image = window.contextPath+"/"+style;
	gIcon.iconSize = new GSize(12, 20);
	gIcon.shadowSize = new GSize(22, 20);
	gIcon.iconAnchor = new GPoint(6, 20);
	gIcon.infoWindowAnchor = new GPoint(5, 1);
	return gIcon;
}

function lrvCartographie_setIconPointerData(gIcon) {
  	gIcon.shadow = '';
  	gIcon.image = contextPath+"/"+nodePointer;
    gIcon.iconSize = new GSize(10,10);
    gIcon.shadowSize = new GSize(0,0);
  	gIcon.iconAnchor = new GPoint(5,5);
    gIcon.infoWindowAnchor = new GPoint(5,5);
  	gIcon.dragCrossImage = 'empty.gif'; // undocumented String: indicates an image to be used as the drag cross. If you set it to the null string, you get the default drag_cross_67_16.png image.
  	gIcon.dragCrossSize = GSize(1, 1); //undocumented GSize(): indicates the size of the drag cross. 
  	gIcon.maxHeight = 1; //undocumented integer: The maximum difference in height between the marker anchor and the drag cross anchor during dragging. Setting the maxHeight to zero causes it to use the default 13.

}

function lrvCartographie_createGMap(domElement) {
    this.map = new GMap2(domElement);
		this.map.setCenter(this.getCenter(), this.getEchelle());

		this.map.addControl(new GLargeMapControl());
		this.map.addControl(new GMapTypeControl());
  	this.map.enableDoubleClickZoom();              
	  this.map.addControl(new GScaleControl()); 
    
    // for conversion between LatLng and screen pixels     
  	this.normalProj = G_NORMAL_MAP.getProjection(); 

	  this.addStartMarkers();
	  this.addEndMarkers();
		
  }

function lrvCartographie_showMapInside(domElement) {
    this.createGMap(domElement);
    
    this.gdir = new GDirections();
	addTrajetInfos(this.map, this.gdir, 'routeInfo', true);
    
    if (this.isReadWrite()) {
      GEvent.bind(this.gdir, "load", this,lrvCartographie_loadGdirReadWrite);
      this.manageDragnDrop(map);        		
      this.lastIndex = 0;              
    } else {
      GEvent.bind(this.gdir, "load", this,lrvCartographie_loadGdirRead);
    }
    
    GEvent.bind(this.gdir, "error", this, this.errorHandler);
    
    this.gdir.loadFromWaypoints(this.allpointstab,{getPolyline:true});
}


function lrvCartographie_loadGdirRead() { 
  var gp = this.gdir.getPolyline();
  //Première initialiation, on centre sur ce poly
  zoom = this.map.getBoundsZoomLevel(gp.getBounds() )
  this.map.setZoom(zoom);
  
  this.map.addOverlay(gp);
}

function lrvCartographie_loadGdirReadWrite() {
    
  var gp = this.gdir.getPolyline();
  
  if (this.gpolys.length==0) {
      //Première initialiation, on centre sur ce poly
      zoom = this.map.getBoundsZoomLevel(gp.getBounds() )
      this.map.setZoom(zoom);  
    
    //Première initialisation des données
    this.gpolys.push(gp);
    this.map.addOverlay(gp);
    gp.halfDistance = this.gdir.getDistance().meters;
  	gp.halfDuration= this.gdir.getDuration().seconds;
  	for (var i = 1; i <this.allpointstab.length-1;i++) {
  	   this.lastIndex=i;
  	   this.createWaypointMarker(this.allpointstab[i],i-1 );
  	   this.splitFromPoint(gp, this.gdir)
  	}
  	for (var i = 0; i <this.gdir.getNumRoutes();i++) {
  		 this.gpolys[i].halfDistance=this.gdir.getRoute(i).getDistance().meters;
  		 this.gpolys[i].halfDuration=this.gdir.getRoute(i).getDuration().seconds;
  	}
  	
  	this.markerDragged=false;
  	
  }
  else {
		  //Drag n drop
  		if (this.prevIndex >= 0) {
        // not the last waypoint was dragged
  		  this.splitFromPoint(gp,this.gdir)
	    	this.gpolys[this.lastIndex - 1].halfDistance = this.gdir.getRoute(0).getDistance().meters;
      	this.gpolys[this.lastIndex - 1].halfDuration= this.gdir.getRoute(0).getDuration().seconds;
      	
        this.gpolys[this.lastIndex].halfDistance = this.gdir.getRoute(1).getDistance().meters;
        this.gpolys[this.lastIndex].halfDuration= this.gdir.getRoute(1).getDuration().seconds;
  	}
  		else {
        // last waypoint was dragged
  			this.map.removeOverlay(this.gpolys[this.lastIndex]);
    		this.gpolys[this.lastIndex] = gp;
      	this.map.addOverlay(this.gpolys[this.lastIndex]);
      	this.gpolys[this.lastIndex].halfDistance = this.gdir.getDistance().meters;
        this.gpolys[this.lastIndex].halfDuration= this.gdir.getDuration().seconds;
  		}
  	}
  	
  	
		this.routeNodes = [];
		this.getProximity();
		
    this.onGDirectionsLoadWithSteps();

		this.isDragged = 0; // tag that there is no dragged waypoints or waiting for GDir to complete 
		
	
		if (this.markerDragged) {
      // marker was dragged again until GDir2 was loaded
			this.isDragged = 1; // tag that there is dragged waypoint
			GEvent.trigger(this.markerDragged, 'drag'); // trigger recalculation of route
		}
}

function lrvCartographie_onGDirectionsLoadWithSteps(){
	 
	  var fullPolyline = new Object();
	  fullPolyline.gpolys = this.gpolys;
	  
	  fullPolyline.vertexCount=0;
	  fullPolyline.getVertexCount = function() {return this.vertexCount}
	  
	  fullPolyline.distance = new Object();
	  fullPolyline.getDistance = function() {return this.distance;}

    fullPolyline.duration = new Object();
	  fullPolyline.getDuration = function() {return this.duration;}
	  
	  fullPolyline.distance.meters = 0;
	  fullPolyline.duration.seconds = 0;
	  fullPolyline.maxIndexes = [];
	  fullPolyline.firstIndexes = [];
	  
    for(var i=0;i <this.gpolys.length; i++) {
        fullPolyline.distance.meters+=this.gpolys[i].halfDistance;
        fullPolyline.duration.seconds+=this.gpolys[i].halfDuration;
        fullPolyline.vertexCount+=this.gpolys[i].getVertexCount();
        if (i==0)  {
          fullPolyline.maxIndexes[i]=this.gpolys[i].getVertexCount()-1
          fullPolyline.firstIndexes[i]=0;
        }
        else {
          fullPolyline.firstIndexes[i]=fullPolyline.maxIndexes[i-1]+1;
          fullPolyline.maxIndexes[i]=fullPolyline.firstIndexes[i]+  this.gpolys[i].getVertexCount()-1;
        }
    }
    
    fullPolyline.getVertex = function(vertexIndex) {
      for(var i=0; i < this.maxIndexes.length; i++) {
          if (vertexIndex <= this.maxIndexes[i])
            return this.gpolys[i].getVertex(vertexIndex-this.firstIndexes[i]);
      }
      
    }
	
		this.onloadFromPolyLine(fullPolyline)
		
		this.allpointstab=[];
		for(var i=0; i < this.waypoints.length; i ++) {
		  this.allpointstab[i]=this.waypoints[i].getLatLng();
		}
		
		this.pointsPassage=[];
		for(var i=1; i < this.waypoints.length-1; i ++) {
		  this.pointsPassage[i-1]=this.waypoints[i]
		}
		
		
	}

function lrvCartographie_splitFromPoint(gpolyline, gdirections) {
    this.map.removeOverlay(this.gpolys[this.lastIndex]);
  	this.map.removeOverlay(this.gpolys[this.lastIndex-1]);
  
  	var minD, minI, points=[];
  	var p0 = this.waypoints[this.lastIndex].getPoint();
  			
  	for (var i = 0; i < gpolyline.getVertexCount(); i++) { // search closest vertex to dragged waypoint for splitting received route at it into two routes between waypoints
  		var p = gpolyline.getVertex(i);
  		points.push(p);
  	
  		var d = p0.distanceFrom(p);
  	
  		if (i == 0 || minD > d) {
  			minD = d;
  			minI = i;
  		}	
  	}
  
  	this.gpolys[this.lastIndex - 1] = new GPolyline(points.slice(0, minI + 1)); //+1,  because slice extracts up to, but not including, the 'end' element
  	this.gpolys[this.lastIndex - 1].halfDistance = gdirections.getDistance().meters/2;
  	this.gpolys[this.lastIndex - 1].halfDuration= gdirections.getDuration().seconds/2;
  	
  	this.gpolys[this.lastIndex] = new GPolyline(points.slice(minI, points.length));
  	this.gpolys[this.lastIndex].halfDistance = gdirections.getDistance().meters/2;
  	this.gpolys[this.lastIndex].halfDuration= gdirections.getDuration().seconds/2;
  	
  	this.map.addOverlay(this.gpolys[this.lastIndex - 1]);
    this.map.addOverlay(this.gpolys[this.lastIndex]);
}

function lrvCartographie_manageDragnDrop() {
		GEvent.bind(this.map, 'mousemove', this, lrvCartographie_getProximity);
    GEvent.bind(this.map, 'zoomend', this, lrvCartographie_map_zoomend);
    
  	this.iconNode = this.getNewMapIcon();
  	this.setIconPointerData(this.iconNode);
  		
  	// create marker for displaying and dragging when mouse is over displayed route
  	this.myNode = new GMarker(this.map.getCenter(), {icon:this.iconNode, draggable:true, bouncy:false, zIndexProcess:function(marker,b) {return 1;}});
  	this.map.addOverlay(this.myNode);
  	this.myNode.show(); // sometimes .hide() does not work without .show() at first ???
  	this.myNode.hide(); // hide this marker initially
  	
  	GEvent.bind(this.myNode, "drag", this, lrvCartographie_freemarker_drag);
	  GEvent.bind(this.myNode, "dragend", this, lrvCartographie_freemarker_dragend);		

}

/**
 * Appelé en cas de fin de zoom sur la carte
 */ 
function lrvCartographie_map_zoomend() { // mouse was over displayed route and user drags the displayed marker
    // clear cached coordinates in pixels of displayed route vertexes, the coordinates have to be recalculated on new zoom level
    this.routeNodes = []; 
}

/**
 * Drag function du free marker : le marker que l'on va chercher sur un gpoly pour créer un nouveau point de passage
 */ 
function lrvCartographie_freemarker_drag() { // mouse was over displayed route and user drags the displayed marker
      this.myNode.show();
  		if (this.isDragged == 2) { // already waiting for GDir2.load to complete - so just remember that marker was dragged again
  			this.markerDragged = this.myNode; // remember which marker was dragged
  			return;
  		}
  		
  		if (this.myNode.MyIndex < this.waypoints.length) {
  			this.isDragged = 2; // tag that GDir2.load is started
  			this.markerDragged = false;
  			
  			this.lastIndex = this.myNode.MyIndex;	
  			this.prevIndex = -1;
  			// recalculate route between waypoints before and after myNode on the displayed line
  			this.gdir.loadFromWaypoints([this.waypoints[this.lastIndex].getPoint(),this.myNode.getPoint(),this.waypoints[this.lastIndex+1].getPoint()], {getPolyline:true,preserveViewport:true});
  		}
  	}
  	
/**
 * DragEnd function du free marker : le marker que l'on va chercher sur un gpoly pour créer un nouveau point de passage
 */   
function lrvCartographie_freemarker_dragend(){ // when user finished dragging the line, create new waypoint with permanent marker at the location
	var point = this.myNode.getPoint();
			
	var marker= this.createWaypointMarker(point, this.myNode.MyIndex);
	
	
	if (this.myNode.MyIndex < this.waypoints.length) {
		// recalculate route between previous and next waypoints going through new inserted waypoint
		this.gdir.loadFromWaypoints([this.waypoints[this.lastIndex - 1].getPoint(),point.toUrlValue(6), this.waypoints[this.lastIndex + 1].getPoint()], {getPolyline:true});
	}
}  	

/**
 * Fonction pour créer un nouveau marker pour un waypoint
 */ 
function lrvCartographie_createWaypointMarker(thePoint, waypointIndex) {
  		var marker = new GMarker(thePoint, {icon:this.iconNode, draggable:true, dragCrossMove:false, bouncy:false, zIndexProcess:function(marker,b) {return 1;}});

  		this.waypoints.splice(waypointIndex + 1, 0, marker); //insert new waypoint into waypoints array

  		for (var i = waypointIndex; i < this.waypoints.length; i++) // reindex next waypoints
  			this.waypoints[i].MyIndex = i;

	   	var dummy = new GPolyline([thePoint]); // insert empty segment into route segments array - GDir2.load will replace it with new route segment

  		this.map.addOverlay(dummy);
  		this.gpolys.splice(waypointIndex + 1, 0, dummy);
       
  		this.map.addOverlay(marker);

  		if (waypointIndex < this.waypoints.length) {
  			this.lastIndex = waypointIndex + 1;
        this.prevIndex = this.lastIndex - 1;
  		}

      marker.lrvCartographie=this;
  		// add event listeners for marker of new waypoint - so route will be recalculated when user drags waypoint
  		GEvent.addListener(marker, "dragstart", function() { this.lrvCartographie.isDragged = 1; this.lrvCartographie.myNode.hide(); });
  		GEvent.addListener(marker, "dragend", function() { this.lrvCartographie.isDragged = 0; } );
  		GEvent.addListener(marker, "drag", function() { this.lrvCartographie.waypointmarker_drag(this);});
		

      return marker;
}


/**
 * Evenement drag des markers qui sont posés comme point de passage
 **/ 
function lrvCartographie_waypointmarker_drag(markerObjectTarget) { // when waypoint marker is being dragged, start calculation of new route
	if (this.isDragged == 2) { // exit if already waiting for GDir2.load to complete 
		this.markerDragged = markerObjectTarget;
		return; 
	}				
	this.isDragged = 2; // tag that calculation of new route is started
	
	if (this.markerDragged) { //determine which marker triggered the recalculation
		this.marker = this.markerDragged;
		this.markerDragged = false;
	}
	else {
		this.marker = markerObjectTarget;
	}
	
	this.lastIndex = this.marker.MyIndex;
	var point = this.marker.getPoint();
			
	if (this.lastIndex > 0) {
		if (this.lastIndex < this.waypoints.length - 1) {
			this.prevIndex = this.lastIndex - 1;	
			this.gdir.loadFromWaypoints([this.waypoints[this.lastIndex - 1].getPoint(),point.toUrlValue(6),this.waypoints[this.lastIndex + 1].getPoint()],{getPolyline:true});	
		}
		else {
			this.prevIndex = -1;
      this.lastIndex = this.lastIndex - 1; // recalculate path to this point
			this.gdir.loadFromWaypoints([this.waypoints[this.lastIndex].getPoint(),point.toUrlValue(6)],{getPolyline:true});
		}
	}
	else if (this.waypoints.length > 1) {
		this.prevIndex = -1;
		this.gdir.loadFromWaypoints([point.toUrlValue(6),this.waypoints[1].getPoint()],{getPolyline:true});
	}
}



function lrvCartographie_myErrorHandler() {
  this.errorHandler(gdir.getStatus().code)
}

function lrvCartographie_setEchelle(echelleParam) {
  this.echelle = echelleParam;
}

function lrvCartographie_getProximity(mouseLatLng, marker) { // detecting if mouse is over displayed route
	var dist, zoom;
	if (this.routeNodes.length == 0) { // calculate and cache coordinates of displayed polylines in pixels for better performance in routeNodes array

		dist = 0;
		zoom =this.map.getZoom();
		
		if (this.gpolys.length > 0 && this.gpolys[0].getVertexCount() > 0 ) //store first point
			this.routeNodes.push(this.normalProj.fromLatLngToPixel(this.gpolys[0].getVertex(0), zoom));
				
		for (var i = 0; i < this.gpolys.length; i++) {
			dist += this.gpolys[i].getLength();
			
			for (var j = 1; j < this.gpolys[i].getVertexCount(); j++) {
				var point = this.normalProj.fromLatLngToPixel(this.gpolys[i].getVertex(j), zoom)
				point.MyIndex = i; // store the index of polyline containing this node
				this.routeNodes.push(point);
			}
		}
	}
	
	if (!mouseLatLng || this.routeNodes.length <= 1 || this.isDragged > 0) // no route is displayed or route is already being dragged
		return;

	zoom = this.map.getZoom();
	var mousePx = this.normalProj.fromLatLngToPixel(mouseLatLng, zoom);
	
	var minDist = 999;
	var minX = mousePx.x; // we will search closest point on the line to mouse position for displaying marker there available for dragging
	var minY = mousePx.y;
	
	if (this.routeNodes.length > 1) {
		var x,y, d1,d2,d;
		var dx = mousePx.x - this.routeNodes[0].x;
		var dy = mousePx.y - this.routeNodes[0].y;
		d2 = dx*dx + dy*dy; // distance^2 from mouse to start of segment 1 in pixels
		
		for (var n = 0 ; ++n < this.routeNodes.length; ) {
			d1 = d2; // distance^2 from mouse to start of segment n in pixels
			
			x = this.routeNodes[n].x; dx = mousePx.x - x;
			y = this.routeNodes[n].y; dy = mousePx.y - y;
			d2 = dx*dx + dy*dy; // distance^2 from mouse to end of segment n in pixels
			
			dx = x - this.routeNodes[n-1].x; 
			dy = y - this.routeNodes[n-1].y;
			d = dx*dx + dy*dy; // lenght^2 of segment n			

			var u = ((mousePx.x - x) * dx + (mousePx.y - y) * dy) / d; // a bit of vector algebra :)
			x += (u*dx); // x,y coordinates in pixels of closest point to mouse in segment n
			y += (u*dy);
				
			dx = mousePx.x - x;
			dy = mousePx.y - y;
			dist = dx*dx + dy*dy; // distance^2 from mouse to closest point in segment n

			if ((d1 - dist) + (d2 - dist) > d) { // closest point is outside the segment, so the real closest point is either start or end of segment
				if (d1 < d2) {
					dist = d1; 
					x = this.routeNodes[n-1].x;
					y = this.routeNodes[n-1].y;
				}
				else {
					dist = d2; 
					x = this.routeNodes[n].x;
					y = this.routeNodes[n].y;
				}				
			};  

			if (minDist > dist) { // closest point in segment n is closest point overall so far
				minDist = dist;
				minX = x;
				minY = y;
				this.myNode.MyIndex = this.routeNodes[n].MyIndex; // remember segment closest to mouse
			}
		}
		
		if (minDist > 25) { // mouse is not close enough to the displayed line
			this.myNode.hide(); // do not display marker for dragging the polyline
		}	
		else {	
			for (n = this.waypoints.length; --n >= 0;) { // check if mouse is not too close to existing waypoints markers
				var markerPx = this.normalProj.fromLatLngToPixel(this.waypoints[n].getPoint(), zoom);
				
				dx = markerPx.x - minX;
				dy = markerPx.y - minY;
				
				if ((dx*dx + dy*dy) < 25) { // mouse is too close to existing marker
					this.myNode.hide(); // do not show additional marker for dragging the line - the user is about to drag existing waypoint
					return;
				}	
			}
			
			this.myNode.setPoint(this.normalProj.fromPixelToLatLng(new GPoint(minX, minY), zoom));
			this.myNode.show(); // display marker for dragging the polyline
		}

		//document.getElementById('panel').innerHTML = '<br>Mouse distance to line ' + n + ': ' + minDist.toFixed(2);		
	}
}


