/*
  SelectPolygon.js: Used for marking and selecting an irregularly shaped area.
                    Note that this tool should not actually appear in the button bar (do not set enabledSrc or disabledSrc)
*/

OpenLayers.Control.SelectPolygon = 
  OpenLayers.Class( OpenLayers.Control, {
    type: OpenLayers.Control.TYPE_TOOL,
    draw: function() {
      this.handler = new OpenLayers.Handler.Polygon( this, {done: this.selectPolygon}, {keyMask: this.keyMask} );
    },
    selectPolygon: function(polygonObject) {
      if (polygonObject instanceof OpenLayers.Geometry.Polygon) {
        //this.handler.deactivate();      // turn off select polygon tool after selection
        // convert pixel values to lat/lon
        var polygon = polygonObject.components[0];
        var lonlats = new Array();
        // NOTE: Do not include final point (same as first point)
        for (var i = 0; i < polygon.components.length - 1; i++) {
          lonlats.push([polygon.components[i].x, polygon.components[i].y]); // x/y are already longitude/latitude (no need to convert)
        }
          
        AddToNewLULCList(lonlats);
      }
      else {   // pixel
        alert("A polygon must be selected.");
      }
    },
    CLASS_NAME: "OpenLayers.Control.SelectPolygon"
  });

