/*
Project: HUMBOLDT GEOPISTA
File: controladorCarga.js
Author: Angel Monterde <angel.monterde.gpl@gmail.com>
Team Geopista: 
	Jorge Elia <jorgelia82@gmail.com>
	Paula Garcia <paulicagg@gmail.com>
	Pablo Gallardo <pgallardo@geopista.es>
	Juan Martin <jmartin@geopista.es>
	Angel Monterde <angel.monterde.gpl@gmail.com>	

Date: 29/05/2007
 
HUMBOLDT GEOPISTA - Light WebClient/viewer for OGC Web Map Services.
Copyright (C) 2007
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

//////////////////////////////////////////////////////////////////////////////////////////
// DEFINICION DE CAPAS Y ESTILOS
//////////////////////////////////////////////////////////////////////////////////////////
// IDEE:

GEOPISTA.Base.CapaEstilo.C_CATASTRO = "Catastro";
GEOPISTA.Base.CapaEstilo.C_IDEE_HIDROGRAFIA = "Hidrografia";
GEOPISTA.Base.CapaEstilo.C_IDEE_TRANSPORTE = "transporte";
GEOPISTA.Base.CapaEstilo.C_IDEE_TEXTOS = "bcn_et";
GEOPISTA.Base.CapaEstilo.C_IDEE_INTERES = "bcn_lugares_interes";
GEOPISTA.Base.CapaEstilo.C_IDEE_MDT = "modelo_sombreado";
GEOPISTA.Base.CapaEstilo.C_IDEE_CORINE = "corine00";
GEOPISTA.Base.CapaEstilo.C_ORTOFOTO = "83";
GEOPISTA.Base.CapaEstilo.C_CURVAS = "29";
GEOPISTA.Base.CapaEstilo.C_CASCOS = "0";
GEOPISTA.Base.CapaEstilo.C_EDIFICIOS = "15";
GEOPISTA.Base.CapaEstilo.C_CONSTRU = "26";

GEOPISTA.Base.CapaEstilo.E_IDEE_DEFAULT = "default";
GEOPISTA.Base.CapaEstilo.E_IDEE_CORINE = "nivel5_sm";
GEOPISTA.Base.CapaEstilo.E_CASTILLA_LEON = " ";

//////////////////////////////////////////////////////////////////////////////////////////

GEOPISTA.Base.Servidor.CATASTRO = "ovc.catastro.meh.es";
GEOPISTA.Base.Servidor.CATASTRO_RUTA ="/Cartografia/WMS/ServidorWMS.aspx";

GEOPISTA.Base.Servidor.CASCOS = "www.sitcyl.jcyl.es";
GEOPISTA.Base.Servidor.CASCOS_RUTA = "/wms/com.esri.wms.Esrimap/MapaRegional";

GEOPISTA.Base.Servidor.CURVAS = "www.sitcyl.jcyl.es";
GEOPISTA.Base.Servidor.CURVAS_RUTA = "/wms/com.esri.wms.Esrimap/BasicaTerritorialE10";

GEOPISTA.Base.Servidor.IDEE = "www.idee.es";
GEOPISTA.Base.Servidor.IDEE_RUTA = "/wms/IDEE-Base/IDEE-Base";

GEOPISTA.Base.Servidor.CORINE = "www.idee.es";
GEOPISTA.Base.Servidor.CORINE_RUTA = "/wms/IGN-Corine/IGN-Corine";

GEOPISTA.Base.Servidor.ORTOFOTO = "www.sitcyl.jcyl.es";
GEOPISTA.Base.Servidor.ORTOFOTO_RUTA = "/wms/com.esri.wms.Esrimap/ImagenesRaster";

GEOPISTA.Base.SERVIDOR_CATASTRO = new GEOPISTA.Base.Servidor(GEOPISTA.Base.Servidor.CATASTRO, GEOPISTA.Base.Servidor.CATASTRO_RUTA);

GEOPISTA.Base.SERVIDOR_CURVAS = new GEOPISTA.Base.Servidor(GEOPISTA.Base.Servidor.CURVAS, GEOPISTA.Base.Servidor.CURVAS_RUTA);

GEOPISTA.Base.SERVIDOR_CASCOS = new GEOPISTA.Base.Servidor(GEOPISTA.Base.Servidor.CASCOS, GEOPISTA.Base.Servidor.CASCOS_RUTA);

GEOPISTA.Base.SERVIDOR_IDEE = new GEOPISTA.Base.Servidor(GEOPISTA.Base.Servidor.IDEE, GEOPISTA.Base.Servidor.IDEE_RUTA);

GEOPISTA.Base.SERVIDOR_CORINE = new GEOPISTA.Base.Servidor(GEOPISTA.Base.Servidor.CORINE, GEOPISTA.Base.Servidor.CORINE_RUTA);

GEOPISTA.Base.SERVIDOR_ORTOFOTO = new GEOPISTA.Base.Servidor(GEOPISTA.Base.Servidor.ORTOFOTO, GEOPISTA.Base.Servidor.ORTOFOTO_RUTA);

// TIPO PETICION
GEOPISTA.Base.REQUEST_VERSION_1_1_1 = "?VERSION=1.1.1&REQUEST=";
GEOPISTA.Base.GET_MAP_VERSION_1_1_1=GEOPISTA.Base.REQUEST_VERSION_1_1_1+"GetMap";
GEOPISTA.Base.GET_FEATURE_INFO_1_1_1 = GEOPISTA.Base.REQUEST_VERSION_1_1_1+"GetFeatureInfo";

GEOPISTA.Base.REQUEST_VERSION_1_1_0 = "?VERSION=1.1.0&REQUEST=";
GEOPISTA.Base.GET_MAP_VERSION_1_1_0=GEOPISTA.Base.REQUEST_VERSION_1_1_0+"GetMap";
GEOPISTA.Base.GET_FEATURE_INFO_1_1_0 = GEOPISTA.Base.REQUEST_VERSION_1_1_0+"GetFeatureInfo";


GEOPISTA.Base.FORMATO_SALIDA_TEXT_PLAIN = "text/plain";

//////////////////////////////////////////////////////////////////////////////////////////
// ASOCIACION DE CAPAS Y ESTILOS CON LAS PETICIONES
//////////////////////////////////////////////////////////////////////////////////////////

var CATASTRO = "CATASTRO";
var CORINE = "CORINE";
var MDT = "MDT";
var EDIFICIOS = "EDIFICIOS";
var CASCOS = "CASCOS";
var CURVAS = "CURVAS";
var IDEE = "IDEE";
var ORTOFOTO = "ORTOFOTO";
var CAPAS_PETICIONES_SERVIDORES_EXTERNOS = {
    "peticiones":[
	{"id": IDEE, "servidor": GEOPISTA.Base.SERVIDOR_IDEE, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_1, "zIndex": 6,"idMunicipio":null, "capasYEstilos":[
        {"capa":GEOPISTA.Base.CapaEstilo.C_IDEE_HIDROGRAFIA, "estilo": GEOPISTA.Base.CapaEstilo.E_IDEE_DEFAULT, "siempreVisible": false, "idLeyenda": "rios"},
        {"capa":GEOPISTA.Base.CapaEstilo.C_IDEE_TRANSPORTE, "estilo":GEOPISTA.Base.CapaEstilo.E_IDEE_DEFAULT, "siempreVisible": false, "idLeyenda": "carreteras"},
	  {"capa":GEOPISTA.Base.CapaEstilo.C_IDEE_TEXTOS, "estilo":GEOPISTA.Base.CapaEstilo.E_IDEE_DEFAULT, "siempreVisible": false, "idLeyenda": "rios"},
	  {"capa":GEOPISTA.Base.CapaEstilo.C_IDEE_INTERES, "estilo":GEOPISTA.Base.CapaEstilo.E_IDEE_DEFAULT, "siempreVisible": false, "idLeyenda": "carreteras"}
        ]}
    ,{"id": CASCOS, "servidor": GEOPISTA.Base.SERVIDOR_CASCOS, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_1, "zIndex": 5,"idMunicipio":null, "capasYEstilos":[
        {"capa":GEOPISTA.Base.CapaEstilo.C_CASCOS, "estilo": GEOPISTA.Base.CapaEstilo.E_CASTILLA_LEON, "siempreVisible": false, "idLeyenda": "CASCOS"}]}
    ,{"id": CURVAS, "servidor": GEOPISTA.Base.SERVIDOR_CURVAS, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_1, "zIndex": 3,"idMunicipio":null, "capasYEstilos":[
        {"capa":GEOPISTA.Base.CapaEstilo.C_CURVAS, "estilo": GEOPISTA.Base.CapaEstilo.E_CASTILLA_LEON, "siempreVisible": false, "idLeyenda": "CURVASL"}]}
   ,{"id": EDIFICIOS, "servidor": GEOPISTA.Base.SERVIDOR_CURVAS, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_1, "zIndex": 4,"idMunicipio":null, "capasYEstilos":[
        {"capa":GEOPISTA.Base.CapaEstilo.C_EDIFICIOS, "estilo": GEOPISTA.Base.CapaEstilo.E_CASTILLA_LEON, "siempreVisible": false, "idLeyenda": "EDIFICIOS"},
	  {"capa":GEOPISTA.Base.CapaEstilo.C_CONSTRU, "estilo": GEOPISTA.Base.CapaEstilo.E_CASTILLA_LEON, "siempreVisible": false, "idLeyenda": "EDIFICIOS"}
        ]}
    ,{"id": ORTOFOTO, "servidor": GEOPISTA.Base.SERVIDOR_ORTOFOTO, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_1, "zIndex": 2,"idMunicipio":null, "capasYEstilos":[
        {"capa":GEOPISTA.Base.CapaEstilo.C_ORTOFOTO, "estilo": GEOPISTA.Base.CapaEstilo.E_CASTILLA_LEON, "siempreVisible": false, "idLeyenda": "FOTO"}]},
     {"id": MDT, "servidor": GEOPISTA.Base.SERVIDOR_IDEE, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_0, "zIndex": 0,"idMunicipio":null, "capasYEstilos":[
        {"capa":GEOPISTA.Base.CapaEstilo.C_IDEE_MDT, "estilo":GEOPISTA.Base.CapaEstilo.E_IDEE_DEFAULT, "siempreVisible": false, "idLeyenda": "MDT"}  
        ]},
    {"id": CORINE, "servidor": GEOPISTA.Base.SERVIDOR_CORINE, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_0, "zIndex": 1,"idMunicipio":null, "capasYEstilos":[
        {"capa":GEOPISTA.Base.CapaEstilo.C_IDEE_CORINE, "estilo":GEOPISTA.Base.CapaEstilo.E_IDEE_CORINE, "siempreVisible": false, "idLeyenda": "CORINE"} 
        ]}
   ,{"id": CATASTRO, "servidor": GEOPISTA.Base.SERVIDOR_CATASTRO, "versionGetMap": GEOPISTA.Base.GET_MAP_VERSION_1_1_1, "zIndex":7, "idMunicipio":null, "capasYEstilos":[
        {"capa": GEOPISTA.Base.CapaEstilo.C_CATASTRO, "estilo": GEOPISTA.Base.CapaEstilo.E_IDEE_DEFAULT, "siempreVisible": false, "idLeyenda": "catastro"}]}
   
    ]};        
    
    //////////////////////////////////////////////////////////////////////////////////////////	
    
    var WIDTH_LEYENDA = 218;
    var HEIGHT_ARRIBA = 130;
    
    var PIXELES_POR_CENTIMETRO = 1080/28.5;
    
    var leyendas = { "leyenda":[

  {"idLeyenda": "catastro", "texto": "Catastro", "checkboxActivo":false, "desplegado": false, "iconos":[
	{"idIcono": "Catastro", "width": "120px", "height": "50px", "src": "img/catastro.jpg", "texto": " "},
       {"idIcono": "leyendaCatastro", "width": "160px", "height": "500px", "src": "img/leyendaCatastro.png", "texto": " "}
       ]},
   {"idLeyenda": "carreteras", "texto": "Carreteras", "checkboxActivo":true, "desplegado": true, "iconos":[
      {"idIcono": "IDEE", "width": "90px", "height": "40px", "src": "img/logoidee220.gif", "texto": " "},
      {"idIcono": "autoviaAutopista", "width": "30px", "height": "30px", "src": "img/IDEE_AutoviaAutopista.png", "texto": "Autovias/Autopista"},
      {"idIcono": "carreteraNacional", "width": "30px", "height": "30px", "src": "img/IDEE_Nacional.png", "texto": "Nacional"},
      {"idIcono": "carretera1", "width": "30px", "height": "30px", "src": "img/IDEE_Carretera1.png", "texto": "Carretera 1 orden"},
      {"idIcono": "carretera2", "width": "30px", "height": "30px", "src": "img/IDEE_Carretera2.png", "texto": "Carretera 2 orden"},
      {"idIcono": "carretera3", "width": "30px", "height": "30px", "src": "img/IDEE_Carretera3.png", "texto": "Carretera 3 orden"},
      {"idIcono": "ferrocarril", "width": "30px", "height": "30px", "src": "img/IDEE_Ferrocarril.png", "texto": "Ferrocarril"},
      {"idIcono": "otrasVias", "width": "30px", "height": "30px", "src": "img/IDEE_OtrasVias.png", "texto": "Otras vias"}
      ]},
  {"idLeyenda": "rios", "texto": "Rios", "checkboxActivo":true, "desplegado": false, "iconos":[
       {"idIcono": "IDEE", "width": "90px", "height": "40px", "src": "img/logoidee220.gif", "texto": " "},
       {"idIcono": "caudalPermanente", "width": "30px", "height": "30px", "src": "img/IDEE_CaudalPermanente.png", "texto": "Caudal Permanente"},
       {"idIcono": "caudalNoPermanente", "width": "30px", "height": "30px", "src": "img/IDEE_CaudalNoPermanente.png", "texto": "Caudal no Permanente"},
       {"idIcono": "lagosYEmbalses", "width": "30px", "height": "30px", "src": "img/IDEE_LagosYEmbalses.png", "texto": "Lagos y Embalses"},
       {"idIcono": "acequiasYCanales", "width": "30px", "height": "30px", "src": "img/IDEE_AcequiasYCanales.png", "texto": "Acequias y Canales"}
       ]},
  {"idLeyenda": "CASCOS", "texto": "Cascos Urbanos", "checkboxActivo":true, "desplegado": false, "iconos":[
	{"idIcono": "sitcyl", "width": "200px", "height": "30px", "src": "img/sitcyl.PNG", "texto": " "}]},
  {"idLeyenda": "EDIFICIOS", "texto": "Edificios", "checkboxActivo":true, "desplegado": false, "iconos":[
	{"idIcono": "sitcyl", "width": "200px", "height": "30px", "src": "img/sitcyl.PNG", "texto": " "}]},
  {"idLeyenda": "CURVASL", "texto": "Curvas", "checkboxActivo":true, "desplegado": false, "iconos":[
	{"idIcono": "sitcyl", "width": "200px", "height": "30px", "src": "img/sitcyl.PNG", "texto": " "}]},
  {"idLeyenda": "FOTO", "texto": "Ortofoto", "checkboxActivo":false, "desplegado": false, "iconos":[
	 {"idIcono": "sitcyl", "width": "200px", "height": "30px", "src": "img/sitcyl.PNG", "texto": " "}
	]},
{"idLeyenda": "CORINE", "texto": "Usos del Suelo CLC", "checkboxActivo":false, "desplegado": false, "iconos":[
	{"idIcono": "IDEE", "width": "90px", "height": "40px", "src": "img/logoidee220.gif", "texto": " "},
	{"idIcono": "corine", "width": "600px", "height": "1900px", "src": "img/corine.gif", "texto": " "}
]},
{"idLeyenda": "MDT", "texto": "Elevaciones MDT", "checkboxActivo":false, "desplegado": false, "iconos":[
	{"idIcono": "IDEE", "width": "90px", "height": "40px", "src": "img/logoidee220.gif", "texto": " "}]}



       ]
    };
    
    if(!GEOPISTA){
        var GEOPISTA = new Object();
    }
    
    if(!GEOPISTA.Operacion){
        GEOPISTA.Operacion = new Object();
    }
    
    GEOPISTA.Operacion.CHINCHETAS_MAXIMAS = 1;
