/* Copyright (c) 2008 Geosignal, published under the Clear BSD
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 * full text of the license. */


/**
 * @requires OpenLayers/Control.js
 * @requires OpenLayers/Feature/Vector.js
 * @requires OpenLayers/Handler/Feature.js
 */

/**
 * Class: OpenLayers.Control.SelectPoint
 * Selects gsMap features from a given layer on click. 
 *
 * Inherits from:
 *  - <OpenLayers.Control>
 */
OpenLayers.Control.SelectPoint = OpenLayers.Class(OpenLayers.Control, {
  

    /**
     * Constructor: <OpenLayers.Control.SelectPoint>
     *
     * Parameters:
     * layer - {<OpenLayers.Layer.gsMap>} 
     * options - {Object} 
     */
    initialize: function(layer, options) {
    		this.options = options;
    		this.handlerOptions = {persist: true, sides: 40};
        OpenLayers.Control.prototype.initialize.apply(this, [options]);
        this.callbacks = OpenLayers.Util.extend({done: this.sendRequest},
                                                this.callbacks);
        this.layer = layer;   
        this.handler = new OpenLayers.Handler.Point(this, this.callbacks, this.handlerOptions);
        this.handler.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {pointRadius: 1,fillColor:'#f00'});
    },
    
		sendRequest: function(feature){
				var ptClick = feature;
        var query = "typeSelection=point&ctrl=0&ptDown="+ptClick.x+','+ptClick.y;        
        setSelection(
        	{
        		x: ptClick.x,
        		y : ptClick.y
        	},
        	{
        		x: ptClick.x,
        		y : ptClick.y
        	}
        );
        this.handler.clear();
return ;

        if(!this.layer)return ;
        //ToDo si plusieurs layers OU layer actif ?!
        this.layer.query = query;
        this.layer.redraw();
        this.layer.query = "";
        this.handler.clear();

        if(this.options.afterSelect) {
        	this.options.afterSelect();
        }
		},
    /** 
     * Method: setMap
     * Set the map property for the control. 
     * 
     * Parameters:
     * map - {<OpenLayers.Map>} 
     */
    setMap: function(map) {
        this.handler.setMap(map);
        OpenLayers.Control.prototype.setMap.apply(this, arguments);
    },

    CLASS_NAME: "OpenLayers.Control.SelectPoint"
});

