/* * MapaEmpresas.js * */ var elTexto=""; var objectsReady = false; var FACTOR_ALTURA = 0.1; var locConn = null; // ---------------------------------------------------------------------------------------------- // Devuelve un objeto con la lista completa de POIs indexada por su Id // Formato de argumento -> idlayer;icono;layer,layer,layer,...|idlayer;icono;layer,layer,layer,...|... // ---------------------------------------------------------------------------------------------- function getPOIs(strPois) { // Lista completa de POIs indexada por su Id, o sea, como properties de un objeto JavaScript var oPois=new Object(); if (strPois!=null && strPois!="") { var aPois=strPois.split("|"); for(var i=0; i idlayer;icono;layer,layer,layer,... // ---------------------------------------------------------------------------------------------- function POI(psPois) { var aPoi = psPois.split(";"); this.idlayer = aPoi[0]; this.icono = aPoi[1]; this.layers = aPoi[2].split(","); } // ---------------------------------------------------------------------------------------------- // Devuelve un array con los objetos POICliente que formarán la leyenda // Formato de string-> id,nombre,path,estado|id,nombre,path,estado|id,nombre,path,estado|... // ---------------------------------------------------------------------------------------------- function getPOIsDeLeyenda(strPois, oPoisDef) { var aPoisLeyenda = new Array(); if (strPois!=null && strPois!="") { var aPois=strPois.split("|"); for(var i=0, j=0; i id,nombre,path,estado // ---------------------------------------------------------------------------------------------- function POICliente(psPois, oPoisDef) { var aPoi = psPois.split(","); this.idlayer = aPoi[0]; if (aPoi.length>1) this.nombre = aPoi[1]; if (aPoi.length>2) this.path = aPoi[2]; if (aPoi.length>3) this.estado = (aPoi[3]=="true"); if (oPoisDef[this.idlayer]!= undefined) this.layers = oPoisDef[this.idlayer].layers; } // ---------------------------------------------------------------------------------------------- // Devuelve un string con los layers de los POIS separados por "|" // Argumentos: array con los nombres de los POIs, objeto con la definición de los POIs, Layers Std/Cus (True/False) // ---------------------------------------------------------------------------------------------- function getLayersDeCapas(aPois, oPoisDef, stdLayers) { // Se interpretarán los layers como Std<8000, y Custom >=8000 var aLayers=new Array(); for (var i=0; i0) for (var j=0; j 1 || aXIco[0] != 0 || cXG.length > 1 || cXG[0] != 0) { // 2. Hay un grupo de iconos o polígonos a centrar // 2.1 Mínimo rectángulo que los contiene a todos var iXMax = aXIco[0]!=0? aXIco[0]: cXG[0]; var iXMin = iXMax; var iYMax = aXIco[0]!=0? aYIco[0]: cYG[0]; var iYMin = iYMax; if(aXIco.length>1 || aXIco[0]!=0) { for(var i=1; i1 || cXG[0]!=0) for(i=(aXIco[0]!=0?0:1); i1 || cXG.length>1) { // El eje que mejor ajusta es el que hace cambiar de tamaño al otro if (Math.abs(iYMax-iYMin)/heigthimg > Math.abs(iXMax-iXMin)/widthimg) { var xMed=(iXMax+iXMin)/2; iXMin = xMed - widthimg/2 * Math.abs(iYMax-iYMin)/heigthimg; iXMax = xMed + widthimg/2 * Math.abs(iYMax-iYMin)/heigthimg; } else { var yMed=(iYMax+iYMin)/2; iYMin = yMed - heigthimg/2 * Math.abs(iXMax-iXMin)/widthimg; iYMax = yMed + heigthimg/2 * Math.abs(iXMax-iXMin)/widthimg; } } // 2.4. Devuelve lo calculado if ((iXMin == iXMax) && (iYMin == iYMax)) return {CenterLongitude:iXMin, CenterLatitude: iYMin, MinimumWidth: iAltura * FACTOR_ALTURA }; else return { UpperLeftLongitude: iXMin, UpperLeftLatitude: iYMax, LowerRightLongitude:iXMax, LowerRightLatitude: iYMin }; } else { // 3. Si todo falla, va hardcoded return {CenterLongitude:-3.70560105539829 * 60, CenterLatitude: 40.422033725768 * 60, MinimumWidth: 7500 * FACTOR_ALTURA }; } } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function getListaLayers(stdLayers) { var aCapasVisibles=new Array(); // Se leen los arrays originales y se copian... var aLayersFondo = stdLayers? aStdLayersDeFondo: aCusLayersDeFondo; if (aLayersFondo!=undefined && aLayersFondo.length>0) for (var i=0; i= Map24.MapApplication._MaxCommandsPerRequest ) Map24.MapApplication._sendCommands(); obj.show(); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function addLocation(params) { var myLoc = new Map24.Location(params); myLoc.commit(); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function cargarIconos() { var mapObjectIDs = new Array(); var commands = new Array(); // Los iconos deben ser accesibles desde el servidor de MapTP para el modo Applet... var icono = (iIDIco==0) ? cPathImg + "iconos/" + "IcoCliente_" + iIDCliente + ".gif": cPathImg + "iconos/" + "IcoGenerico" + iIDIco + ".gif"; for (var i=0; i 0) { commands.push( new Map24.WebServices.XMLCommandWrapper( { ControlMapObject: new Map24.WebServices.ControlMapObject( { MapObjectIDs: mapObjectIDs, Control: "ENABLE" }) })); locConn.mapletRemoteControl( new Map24.WebServices.Message.mapletRemoteControlRequest( { MapletRemoteControlRequest: new Map24.WebServices.MapletRemoteControlRequest( { Map24MRC: new Map24.WebServices.Map24MRC({ Commands: commands }) }) }) ); } // En su caso, crear una polilínea que los una if (bIconosUnidos) { var longs= ""; var lats = ""; for(i=0; iiAltMax * 1.1) { Map24.MapApplication.center({Longitude:e.PreClipRect.Center.X, Latitude: e.PreClipRect.Center.Y, MinimumWidth: (newWidth"+e.toString(),donemsg); return; } } } // Por si acaso, que se reactualicen los links updCambioMapaLinks(Map24.MapApplication.getMapType()); } // ---------------------------------------------------------------------------------------------- // Actualización del aspecto de los links de Mapa Dinámico/Estático // ---------------------------------------------------------------------------------------------- function updCambioMapaLinks(tipoMapa) { if (hayCambioMapa) { var mapstatic =document.getElementById("mapstatic"); var mapdinamic=document.getElementById("mapdinamic"); if (mapstatic) mapstatic.style.fontWeight = (tipoMapa=="Static"? 700:400); if (mapdinamic) mapdinamic.style.fontWeight= (tipoMapa=="Applet"? 700:400); } } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function eliminaTexto(index) { var myLabel = aTextos[index]; if (myLabel) { myLabel.remove(); aTextos.splice(index,1); } } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function centraTexto(index) { var myLabel = aTextos[index]; if (myLabel) myLabel.center(); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function colocarTexto(texto) { elTexto= texto; if (elTexto!="") { Map24.MapApplication.Map.addListener( "Map24.Event.MapClick", posicionaTexto); MEDialogs.upperLeftMessage(textoriginmsg); } } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function posicionaTexto(e) { // El ancho del div condiciona los saltos de carro... ¿se podría calcular en función del texto???? // Habría que sustituir en 'elTexto' los '\n' por '
', si están permitidos... var htmlContent="
" + elTexto + "
"; var myLabel = new Map24.HtmlObject( { Longitude: e.Coordinate.Longitude, Latitude: e.Coordinate.Latitude, Content: htmlContent }); myLabel.textContent = elTexto; // Se añade al array de Textos para su proceso posterior aTextos[aTextos.length]=myLabel; // Commit on the object myLabel.commit(); // Si se acabó la posición.... Map24.MapApplication.Map.removeListener( "Map24.Event.MapClick", posicionaTexto ); MEDialogs.closeupperLeftMessage(); // Para que no se propague el evento e.stop(); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function getMapletSession() { var get_mapletsession_request = new Map24.WebServices.Message.getMapletSessionRequest({ GetMapletSessionRequest: new Map24.WebServices.GetMapletSessionRequest({ Map24MRCMapObjectIDsFilter: [ "ControlLayer" ] })}); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function onMapClientReady(client) { updCambioMapaLinks(client.MapClient.Name); if (!objectsReady) { objectsReady = true; MEDialogs.closecenteredMessage(); // Activación de las capas iniciales // Carga de iconos, si los hay... cargarIconos(); // Carga de figuras geométricas, si las hay... cargarFiguras(); // Para la altura máxima hay que implementar el manejo de un evento que lo controle y lo fuerce Map24.MapApplication.Map.addListener( "Map24.Event.MapViewChanged", cambioEnMapa); var toolbartable = $('#toolbartable'); if (toolbartable) toolbartable.show(); // Redefinimos la función de respuesta de servicio para poder ocultar los diálogos de carga Map24.Network.ConnectJS.responseHandler = function(request_id, answer, success ) { if (answer.indexOf('Map24MapletRemoteControl') != -1) MEDialogs.closecenteredMessage(); Map24.Net.JavascriptConnection.responseHandler(request_id, answer, success); } actualizarLayers(); } } /* * Control the tiles component. * * On cmd SHOW the tiles components are shown (3 buttons Map, Hybrid, Satellite in the upper left corner) with the * drawing type specied in parameter drawingType (HYBRID, SATELLITE, or MAP). * drawingType * This example uses the core API of Map24 AJAX API. The SOAP request looks as follows: * * SHOW TILES setstate satellite * * @param cmd The command can be either SHOW or HIDE. * @param drawingState Sets the tiles drawing state to the given value. Possible values are "MAP", * "HYBRID" and "SATELLITE". * */ function controlComponentTiles( cmd, drawingState ) { locConn.mapletRemoteControl( new Map24.WebServices.Message.mapletRemoteControlRequest( { MapletRemoteControlRequest: new Map24.WebServices.MapletRemoteControlRequest( { Map24MRC: new Map24.WebServices.Map24MRC( { Commands: [ new Map24.WebServices.XMLCommandWrapper( { ControlComponent: new Map24.WebServices.ControlComponent( { Component: "TILES", Control: cmd, Properties: [ new Map24.WebServices.Property( { Key: "setstate", Value: drawingState }) ] }) }) ] }) }) }) ); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function onSuccess() { } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function map24ApiLoaded() { // Se ajusta el mapa al área adecuada según los parámetros de entrada Map24.MapApplication.setStartMapView (areaInicial(iX, iY, aXIco, aYIco, cXG, cYG)); // Tipo de Mapa que se desplegará: el que indiquen los argumentos, excepto si // indican 'Applet' pero no hay Java Map24.Browser.javaAvailable(); if ((sTipoMapa=="Applet" || sTipoMapa=="Auto") && !(Map24.Browser.JavaInstalled && Map24.Browser.JavaEnabled)) sTipoMapa="Static"; // Interfaz de usuario: comandos de cambio de mapa estático/dinámico updCambioMapaLinks((sTipoMapa=="Auto") ? "Applet" :sTipoMapa); if (debug_mapaempresas) { if (Map24.Browser.FIREFOX) Map24.Debug.LogToFirefoxConsole = true; Map24.Debug.enable(true, Map24.E_ALL); } //var mtype = (sTipoMapa == 'Applet') ? 'Auto' : sTipoMapa; Map24.MapApplication.init( { NodeName: "cuadroMapa", MapType: sTipoMapa} ); locConn = Map24.MapApplication.Map.Local.openConnection(); locConn.onSuccess = onSuccess; locConn.onError = function(){ MEDialogs.alert ("MapTP API Error Occured!"); }; locConn.onTimeout = function(){ MEDialogs.alert ("MapTP API Timeout Occured!"); }; Map24.MapApplication.Map.addListener( 'MapClientReady', onMapClientReady ); MEDialogs.centeredMessage(loadingmapmsg,"loading.gif"); controlComponentTiles(sControlModoMapa, sModoMapa); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- function goMap24() { // Se añade la tabla con la leyenda al div 'Pois' (si existe!) var poisDiv = document.getElementById("Pois"); if (poisDiv!=null) poisDiv.appendChild(tablaLeyenda); try{var a=Map24;} catch(e) { MEDialogs.centeredMessage("Cannot connect to Map24 server","forbidden.gif"); return; } Map24.loadApi( ["core_api", "wrapper_api"] , map24ApiLoaded ); } // ---------------------------------------------------------------------------------------------- // // ---------------------------------------------------------------------------------------------- $(document).ready(function() { goMap24(); });