﻿/**
* @requires OpenLayers/Handler/Path.js
*/

/**
* Class: OpenLayers.Handler.DigitizePath
* Extends Path handler.
*
* Inherits from:
*  - <OpenLayers.Handler.Path>
*/
OpenLayers.Handler.DigitizePath = OpenLayers.Class(OpenLayers.Handler.Path, {

    /** 
    * Property: clickCount  
    * Counts clicks
    */
    clickCount: 0,

    /**
    * Constructor: OpenLayers.Handler.DigitizePath
    * Create a new path hander
    */
    initialize: function(control, callbacks, options) {
        OpenLayers.Handler.Path.prototype.initialize.apply(this, arguments);
    },

    /**
    * Method: mouseup
    * Handle mouse up.  Send the latest point in the geometry to
    * the control. Return determines whether to propagate the event on the map.
    * 
    * Parameters:
    * evt - {Event} The browser event
    *
    * Returns: 
    * {Boolean} Allow event propagation
    */
    mouseup: function(evt) {
        this.clickCount++;
        this.mouseDown = false;
        if (this.drawing) {
            if (this.freehandMode(evt)) {
                this.removePoint();
                this.finalize();
            } else {
                if (this.lastUp == null) {
                    this.addPoint(evt.xy);
                }
                this.lastUp = evt.xy;
            }
            if (this.clickCount == 2) {
                this.dblclick(evt);
                this.clickCount = 0;
            }
            return false;
        }
        return true;
    },

    CLASS_NAME: "OpenLayers.Handler.DigitizePath"
});
