﻿
//arcgisIdentifyTool = null;
//var pictometry_scrnpnt = null;
var pictometry_selectPosition = new Object();

ExternalLauncherTool = function(element) {
ExternalLauncherTool.initializeBase(this);
    //this._identifyIcon = null;
    //this._waitIcon = null;
    this._processing = false;
    this._toolType = 'pictometry';

    this._onSelection = Function.createDelegate(this, function(geom) {
        // don't continue if previous call is not finished
        if (!this._processing) {
            var map = $find("Map1");
            this._processing = true;

            // put the ajax activity indicator at cursor click and make visible
            var mappnt = new ESRI.ADF.Geometries.Point(geom.get_x(), geom.get_y());
            //pictometry_scrnpnt = this._map.toScreenPoint(mappnt);

            /**			
            var wicon = $find(this.get_id()+'_waiticon');
            if(wicon==null) {
            this.waitIcon = $create(ESRI.ADF.Graphics.GraphicFeature,
            {"id":this.get_id()+'_waiticon',"geometry":geom,"symbol":new ESRI.ADF.Graphics.MarkerSymbol(this._waitIcon,8,8)
            });
            this.waitIcon.get_symbol().set_imageFormat("gif");
            this.waitIcon.get_symbol().set_width(16);
            this.waitIcon.get_symbol().set_height(16);
            }
            else
            this.waitIcon.set_geometry(geom);
            map.addGraphic(this.waitIcon);
            **/

            // make callback for identify
            var argument = "mode=" + this._toolType + "&coords=" + geom.get_x() + ":" + geom.get_y();
            this.doCallback(argument, this);
        }
    });
    //arcgisIdentifyTool = this;
};


ExternalLauncherTool.prototype = {
    startExternalLauncherTool: function(a, b, c, d) {
        //arcgisIdentifyTool = this;
        this._toolType = b;
        this._processing = false;
        //tell the ESRI Map control to go into "getGeometry" mode
        this._map.getGeometry(
		    ESRI.ADF.Graphics.ShapeType.Point,
		    this._onSelection,
		    null,
		    'black',
		    'gray',
		    'pointer',
		    true);
    },
    processCallbackResult: function(action, params) {
        if (action == "mappoint") {
            this._processing = false;
            if (this.waitIcon) { this._map.removeGraphic(this.waitIcon); }
        }
        else if (action == 'error') {
            if (this.waitIcon) { map.removeGraphic(this.waitIcon); }
            alert("Error: " + params[0]);
            Sys.Debug.trace('Error: ' + params[0])
        }
    },
    doCallback: function(argument, context) {
        /// <summary>
        /// Performs a callback or partial postback depending on it's postback mode
        /// </summary>
        /// <param name="argument" type="String">The argument parsed back to the server control</param>
        /// <param name="context" type="string">The context of this callback</param>
        /// <returns />
        ESRI.ADF.System._doCallback(this._callbackFunctionString, this.get_uniqueID(), this.get_id(), argument, context);
    },
    get_uniqueID: function() {
        /// <value name="uniqueID" type="String">Gets or sets the unique ID used to identify the control serverside</value>
        return this._uniqueID;
    },
    set_uniqueID: function(value) {
        this._uniqueID = value;
    },
    get_callbackFunctionString: function() {
        /// <value name="callbackFunctionString" type="String">Gets or sets the callback function string used to call back to the serverside control.</value>
        /// <remarks>
        /// Executing the callbackfunctionstring will either generate a partial postback or a callback to the server, depending on the current AJAX mode.
        /// To perform a call to the servercontrol, use the <see cref="doCallback"/> method of this instance.
        /// </remarks>
        return this._callbackFunctionString;
    },
    set_callbackFunctionString: function(value) {
        this._callbackFunctionString = value;
    },
    get_map: function() {
        return this._map;
    },
    set_map: function(value) {
        this._map = value;
    },
    //get the page height
    getPageHeight: function() {
        var height = window.innerHeight;
        if (height == null) {
            if (document.documentElement && document.documentElement.clientHeight)
                height = document.documentElement.clientHeight;
            else
                height = document.body.clientHeight;
        }
        return height;

    }
};
ExternalLauncherTool.registerClass('ExternalLauncherTool', Sys.Component);

