﻿//Comportamiento para Mostrar la Informacion Alfanumerica asociada a un elemento
function WVAlphInf()
{
    var oThis           = this;
    var viewer          = null;
    var behaviorType    = WVBehaviorType.ALPHINF; //tipo de comportamiento
    var enabled         = false;//indica si este comportamiento está operativo para afectar al visor
    var ltnwindow       = null;
    var imgSrc          = null;
    var lstCustomFinalize = new Array();
    var lstCustomInit       = new Array();
    
    this.getEnabled=function()
    {
        return enabled;
    }
    
    this.setEnabled=function(enable)
    {
        enabled = enable;
    }
    
    //retorna si el comportamiento debe estar siempre activo
    this.alwaysKeepEnabled=function()
    {
        return false;
    }
    
    this.init=function (visor)
    {
        viewer       = visor;
        ltnwindow   = new LtnWinMsg(viewer);
        callCustomInit();
    }
    
    this.getBehaviorType=function()
    {
        return behaviorType;
    }
    
    this.onUpdate = function ()
    {
    }
    
    this.finalize=function()
    {
        if(ltnwindow.enabled)
            ltnwindow.finalize();
        callCustomFinalize(); 
        lstCustomFinalize = new Array();
        lstCustomInit     = new Array();
    }
    this.addParameters = function(p)
    {
        if(p.length == 0)return;
        imgSrc = p[0];
    }
    function  onInfCartOK ( resp )
    {
        if(resp.length>0)ltnwindow.createTableWindow(imgSrc, "Alphanumeric Information", resp.split(';'));
        else ltnwindow.finalize();
    }
    function  onInfCartError()
    {
        alert("Error en la solicitud de Informacion alfanumerica");
    }
    this.addPoint=function(pointPX)
    {
        var pointUTM = viewer.transformLocalToWorld(pointPX.x,pointPX.y);
        var url = "MapServer.ashx?op=4&VisorID="+viewer.getGUID()+"&IdFromCoords="+pointUTM.x+","+pointUTM.y+"&ratio="+parseInt(viewer.getScale()*10);
        var cnt = new HttpConnector();
	    cnt.init(30000);
	    cnt.connect(url, onInfCartOK, onInfCartError);
    }
    //Suscribe los metodos a invocar cuando se finalice el comportamiento
    this.registerCustomFinalize = function(cfinalize)
    {
        lstCustomFinalize.push(cfinalize);
    }
    
    //Elimina los metodos a invocar cuando se finalice el comportamiento
    this.unregisterCustomFinalize = function (cfinalize)
    {
        for (var i=0;i<lstCustomFinalize.length;i++)
            if (lstCustomFinalize[i]==cfinalize)
            {
                lstCustomFinalize.splice(i,1);
                break;
            }
    }
    //Invocacion cuando se finalice el comportamiento de los metodos agregados  
    function callCustomFinalize()
	{
        var n   = lstCustomFinalize.length;
        if ( n == 0 )return;
        for( var i = 0; i < n; i++ )
            lstCustomFinalize[i]();
	}
	
	//Suscribe los metodos a invocar cuando inicie el comportamiento
    this.registerCustomInit = function(cinit)
    {
        lstCustomInit.push(cinit);
    }
    
    //Elimina los metodos a invocar cuando inicie el comportamiento
    this.unregisterCustomInit = function (cinit)
    {
        for (var i=0;i<lstCustomInit.length;i++)
            if (lstCustomInit[i]==cinit)
            {
                lstCustomInit.splice(i,1);
                break;
            }
    }
    //Invocacion cuando inicie el comportamiento de los metodos agregados  
    function callCustomInit()
	{
        var n   = lstCustomInit.length;
        if ( n == 0 )return;
        for( var i = 0; i < n; i++ )
            lstCustomInit[i]();
	}
}

