OpenLayers.DOTS_PER_INCH=96;OpenLayers.IMAGE_RELOAD_ATTEMPTS=1;OpenLayers.Util.onImageLoadErrorColor="transparent";OpenLayers.Util.onImageLoadError=function(){this.src="http://www.conselldemallorca.net/sit/libs/openlayers/img/blank.gif";this.style.display="";};function cimPHistoricMap(){this.map=null;this.printScale=new Array(800000,400000,200000,100000,50000,25000,12500,5000,3000,1500);}
cimPHistoricMap.prototype.init=function(){this.lat=4381000;this.lon=495000;this.zoom=0;this.options={'controls':[],maxExtent:new OpenLayers.Bounds(400000,420000,630000,4480000),restrictedExtent:new OpenLayers.Bounds(406151.054102116864,4254301.845737015808,622898.154262984192,4471048.945897883136),maxResolution:211.667090000847,scales:[800000,400000,200000,100000,50000,25000,12500,6250,3125,1562.5],tileOrigin:new OpenLayers.LonLat(-5120900,9998100),tileSize:new OpenLayers.Size(512,512),projection:'EPSG:25831',units:'m',allOverlays:true};this.map=new OpenLayers.Map($('center'),this.options);this.layerMapa=new OpenLayers.Layer.ArcGISCache("Mapa","http://www.conselldemallorca.net/mapcache/demo_base/MAPA/_alllayers",{type:'png',tileSize:new OpenLayers.Size(256,256),tileOrigin:new OpenLayers.LonLat(-5120900,9998100),useArcGISServer:false,maxExtent:new OpenLayers.Bounds(400000,420000,630000,4480000),resolutions:[211.667090000847,105.833545000423,52.9167725002117,26.4583862501058,13.2291931250529,6.61459656252646,3.30729828126323,1.65364914063161,0.826824570315807,0.41341228515790368],transitionEffect:'resize',visibility:true,isBaseLayer:false,printLayer:'10',buffer:1});this.map.addLayer(this.layerMapa);this.layerOrto=new OpenLayers.Layer.ArcGISCache("PNOA(SITIBSA)","http://www.conselldemallorca.net/mapcache/orto2008/Layers/_alllayers",{type:'jpg',tileOrigin:new OpenLayers.LonLat(-5120900,9998100),tileSize:new OpenLayers.Size(256,256),useArcGISServer:false,maxExtent:new OpenLayers.Bounds(400000,420000,630000,4480000),resolutions:[211.667090000847,105.833545000423,52.9167725002117,26.4583862501058,13.2291931250529,6.61459656252646,3.30729828126323,1.65364914063161,0.826824570315807,0.41341228515790368],transitionEffect:'resize',visibility:false,isBaseLayer:false,printLayer:'9',buffer:1});this.map.addLayer(this.layerOrto);this.layerTopo5000=new OpenLayers.Layer.WMS("Topo5000(SITIBSA)","http://ideib.caib.es/pub_ideib/public/MTIB/MapServer/WMSServer",{layers:'40,41,42,43,44,45,46,47,48,49,50,51,52,53',format:'image/gif'},{isBaseLayer:false,visibility:false,maxResolution:6.61459656252646,printLayer:'8',buffer:0});this.map.addLayer(this.layerTopo5000);this.layerCartociudad=new OpenLayers.Layer.WMS("Cartociudad","http://www.cartociudad.es/wms/CARTOCIUDAD/CARTOCIUDAD",{layers:'FondoUrbano,CodigoPostal,SeccionCensal,Toponimo,Portal,Vial',format:'image/gif',transparent:'TRUE'},{isBaseLayer:false,visibility:false,opacity:0.8,maxResolution:6.61459656252646,printLayer:'7',buffer:0});this.map.addLayer(this.layerCartociudad);this.layerCadastre=new OpenLayers.Layer.WMS("Cadastre","http://ovc.catastro.meh.es/Cartografia/WMS/ServidorWMS.aspx",{layers:'Catastro',format:'image/png',transparent:'TRUE'},{isBaseLayer:false,visibility:false,maxResolution:6.61459656252646,singleTile:true,ratio:1.2,printLayer:'6',buffer:0});this.map.addLayer(this.layerCadastre);this.layerBC_limit=new OpenLayers.Layer.ArcGIS93Rest("BC_limit","http://"+location.host+"/ide_rest/services/ws_patrimoni/MapServer/export",{layers:'show:6',format:'png',transparent:'true'},{isBaseLayer:false,opacity:0.6,visibility:false,printLayer:'5',buffer:0});this.map.addLayer(this.layerBC_limit);this.layerBIC_limit=new OpenLayers.Layer.ArcGIS93Rest("BIC_limit","http://"+location.host+"/ide_rest/services/ws_patrimoni/MapServer/export",{layers:'show:5',format:'png',transparent:'true'},{isBaseLayer:false,opacity:0.6,visibility:true,printLayer:'4',buffer:0});this.map.addLayer(this.layerBIC_limit);this.layerBC=new OpenLayers.Layer.ArcGIS93Rest("BC","http://"+location.host+"/ide_rest/services/ws_patrimoni/MapServer/export",{layers:'show:2,4',format:'png',transparent:'true'},{isBaseLayer:false,visibility:false,printLayer:'1 3',buffer:0});this.map.addLayer(this.layerBC);this.layerBIC=new OpenLayers.Layer.ArcGIS93Rest("BIC","http://"+location.host+"/ide_rest/services/ws_patrimoni/MapServer/export",{layers:'show:1,3',format:'png',transparent:'true'},{isBaseLayer:false,visibility:true,printLayer:'0 2',buffer:0});this.map.addLayer(this.layerBIC);this.map.addControl(new OpenLayers.Control.Navigation());this.map.addControl(new OpenLayers.Control.ScaleLine({maxWidth:200}));var click=new OpenLayers.Control.Click();this.map.addControl(click);click.activate();layerMapaGuia=new OpenLayers.Layer.ArcGISCache("Mapa guía","http://www.conselldemallorca.net/mapcache/MapaGuia/MAPA/_alllayers",{type:'png',tileOrigin:new OpenLayers.LonLat(-5120900,9998100),useArcGISServer:false,buffer:0});var options={maxExtent:new OpenLayers.Bounds(280000,4130000,750000,4610000),resolutions:new Array(846.668360003387,423.334180001693,211.667090000847,105.833545000423,52.9167725002117,26.4583862501058),maxResolution:846.668360003387,tileSize:new OpenLayers.Size(256,256),tileOrigin:new OpenLayers.LonLat(-5120900,9998100),projection:'EPSG:25831',units:'m'};var ovmap=new OpenLayers.Control.OverviewMap({layers:[layerMapaGuia],mapOptions:options,maxRatio:64,minRatio:16});this.map.addControl(ovmap);ovmap.maximizeControl();}
cimPHistoricMap.prototype.getMap=function(){return this.map;}
cimPHistoricMap.prototype.getVisibleLayers=function(){var listLayers="";var layers=this.map.layers;for(i=0;i<(layers.length);i++)
if(layers[i].getVisibility()&&layers[i].printLayer!==undefined)
listLayers+=" "+layers[i].options.printLayer;listLayers=listLayers.substring(1);if(app.cim_map.layerBIC.getVisibility()){if(filterBIC!=null)listLayers+="&filterBIC="+filterBIC.join(',');}
if(app.cim_map.layerBC.getVisibility()){if(filterBC!=null)listLayers+="&filterBC="+filterBC.join(',');}
var lyOrto=app.cim_map.layerOrto;if(lyOrto.getVisibility()){if(lyOrto.opacity<1){listLayers+="&opacity="+Math.round((1-lyOrto.opacity)*100);}}
return listLayers;}
function searchStringInArray(stringArray,str){for(var j=0;j<stringArray.length;j++){if(stringArray[j].match(str))return j;}
return-1;}
OpenLayers.Control.Click=OpenLayers.Class(OpenLayers.Control,{defaultHandlerOptions:{'single':true,'double':false,'pixelTolerance':0,'stopSingle':true,'stopDouble':false},initialize:function(options){this.handlerOptions=OpenLayers.Util.extend({},this.defaultHandlerOptions);OpenLayers.Control.prototype.initialize.apply(this,arguments);this.handler=new OpenLayers.Handler.Click(this,{'click':this.trigger},this.handlerOptions);},trigger:function(e){app.dataStoreBIC.clearFilter();var lonLatMin=this.map.getLonLatFromViewPortPx(e.xy.add(-5,+5));var lonLatMax=this.map.getLonLatFromViewPortPx(e.xy.add(+10,-10));app.dataStoreBIC.filterBy(function(record,id){if(app.cim_map.layerBIC.visibility==false)return false;if(filterBIC!=null){if(searchStringInArray(filterBIC,record.data['TIPOLOGIA'])==-1)return false;}
if(parseFloat(record.data['COORD_X'])>=lonLatMin.lon&&parseFloat(record.data['COORD_X'])<=lonLatMax.lon&&parseFloat(record.data['COORD_Y'])>=lonLatMin.lat&&parseFloat(record.data['COORD_Y'])<=lonLatMax.lat){return true;}else
return false;});if(app.dataStoreBIC.getCount()>0){app.info.getComponent('formulariCercaBIC').hide();app.info.getComponent('formulariCercaBC').hide();app.info.getComponent('viewResultatsBIC').show();app.info.getComponent('viewResultatsBC').show();}
else{app.info.getComponent('formulariCercaBIC').hide();app.info.getComponent('formulariCercaBC').hide();}
app.dataStoreBC.clearFilter();var lonLatMin=this.map.getLonLatFromViewPortPx(e.xy.add(-5,+5));var lonLatMax=this.map.getLonLatFromViewPortPx(e.xy.add(+10,-10));app.dataStoreBC.filterBy(function(record,id){if(app.cim_map.layerBC.visibility==false)return false;if(filterBC!=null){if(searchStringInArray(filterBC,record.data['TIPOLOGIA'])==-1)return false;}
if(parseFloat(record.data['COORD_X'])>=lonLatMin.lon&&parseFloat(record.data['COORD_X'])<=lonLatMax.lon&&parseFloat(record.data['COORD_Y'])>=lonLatMin.lat&&parseFloat(record.data['COORD_Y'])<=lonLatMax.lat){return true;}else
return false;});if(app.dataStoreBC.getCount()>0){app.info.getComponent('formulariCercaBIC').hide();app.info.getComponent('formulariCercaBC').hide();app.info.getComponent('viewResultatsBIC').show();app.info.getComponent('viewResultatsBC').show();}else{app.info.getComponent('formulariCercaBIC').hide();app.info.getComponent('formulariCercaBC').hide();}
if(app.dataStoreBIC.getCount()>0||app.dataStoreBC.getCount()>0)
app.info.getComponent('labelNoResultats').hide();else
app.info.getComponent('labelNoResultats').show();app.info.expand(true);}});
