Evt_Draw_Circle.prototype=new Event();

function Evt_Draw_Circle(autoclear)
{
	this._w=0;
	this._h=0;
	this._jg= new jsGraphics(_MAP_ID);
	this._autoclear=autoclear;
	this._radius=0.0;
}

Evt_Draw_Circle.prototype.mouse_move=function(event)
{
	var x=0;
	var y=0;

	var px_coords=_MAP_WRAPPER.convert_to_relative_pixel_coords(event.clientX,event.clientY);
	
	this._x_mov=px_coords[0];
	this._y_mov=px_coords[1];
	
	//Vettore di spostamento
	var v = new Array();
	
	v[0]=this._x_mov-this._x_click;
	v[1]=this._y_mov-this._y_click;
	
	var m=Math.sqrt( Math.pow(v[0],2)+Math.pow(v[1],2) );
	m*=2;
	
	//alert(delta_x+"\n"+delta_y+"\n"+x2+"\n"+y2+"\n"+d);
	var vers = new Array();
	
	vers[0]=v[0]/m;
	vers[1]=v[1]/m;
	
	
	//A dipendenza del vettore di spostamento aggiungere o togliere la meta del modulo
	var x= vers[0] <= 0 ? this._x_click -(m/2) : this._x_click-(m/2);
	//Inizia da top left
	var y= vers[1] <= 0 ? this._y_click-(m/2) : this._y_click-(m/2);
	
	var p1=_MAP_WRAPPER.convert_to_geo(this._x_click,this._y_click);
	
	var p2 = _MAP_WRAPPER.convert_to_geo(this._x_mov,this._y_mov);
	this._radius=Math.sqrt( Math.pow((p2[0]-p1[0]),2)+Math.pow(p2[1]-p1[1],2)).toFixed(2);
	this._jg.clear();			
	this._jg.setColor("#fe8c01");
	this._jg.drawString(this._radius+" m",this._x_mov+12,this._y_mov);
	this._jg.drawLine(parseInt(this._x_click),parseInt(this._y_click),parseInt(this._x_mov),parseInt(this._y_mov));	
	this._jg.drawEllipse(x,y,m,m);
	this._jg.paint();
	
	stop_propagating_event(event);
	

};

Evt_Draw_Circle.prototype.mouse_up=function(event)
{
 	this._jg.clear();
	
};

Evt_Draw_Circle.prototype.get_radius=function()
{
	return this._radius;
};

/*
* Get center in coordinates
*/
Evt_Draw_Circle.prototype.get_center=function()
{
	return _MAP_WRAPPER.convert_to_geo(this._x_click,this._y_click);
};

Evt_Draw_Circle.prototype.do_operation=function()
{
	
};
