OpenLayers.ProxyHost=ServerVars.serverPath+"/prox.html?url=";Map.Markers={getLayer:function(){var markerStyle={externalGraphic:Utils.imageLocation+"bluearrow.png",graphicWidth:16,graphicHeight:16,graphicYOffset:-16};var addMark=function(lonlat,imgTitle){var point=new OpenLayers.Geometry.Point(lonlat.lon,lonlat.lat);var feature=new OpenLayers.Feature.Vector(point,{title:imgTitle,clickable:'off'});this.addFeatures([feature]);};return new OpenLayers.Layer.Vector('Search markers',{style:markerStyle,addMark:addMark});},addMarker:function(lng,lat){Map.addMarker(lng,lat);},add:function(lat,lng,name){Map.addMarker(lng,lat,name);},clearMarkers:function(){this.map.getLayersByName('Search markers')[0].destroyFeatures();}};Map.doVectors=function(mapProjs,inputDone){var defaultInputDone=function(){if(this.feedCount==this.feedsRead){StatusLog.logMsg('mapsetup');if(this.zoomToFeatures===true){if(ServerVars.bbox){var bounds=OpenLayers.Bounds.fromString(ServerVars.bbox);if(this.projection!="EPSG:4326"){bounds.transform(this.displayProjection,this.baseLayer.projection);}
this.zoomToExtent(bounds);}else{if(this.featureExtent.bottom!==null){this.zoomToExtent(this.featureExtent);}
else{this.setCenter(this.defaultLonglat,this.defaultZoom);}}}
StatusLog.endMsg();}};this.addTooltipDiv=function(){jQuery('body').append('<div class="popup" id="tooltip" style="visibility: hidden"></div>');};OpenLayers.Util.extend(this.map,{feedsRead:0,feedCount:0,featureExtent:new OpenLayers.Bounds(),inputDone:inputDone||defaultInputDone,featureOver:function(feature){var fname=feature.attributes.name||feature.attributes.title||feature.attributes.id||feature.fid;if(feature.geometry.CLASS_NAME=="OpenLayers.Geometry.LineString"&&feature.layer.calcKm){fname+=' '+this.map.getLength(feature);}
var xy=this.map.getControl('ll_mouse').lastXy||new OpenLayers.Pixel(0,0);Utils.showTooltip(fname,xy.x,xy.y);},getLength:function(feature){return Math.round(feature.geometry.getGeodesicLength(feature.layer.map.baseLayer.projection)*0.1)/100+'km';}});if(this.specifics.addTc){this.addTc(this.specifics.addTc);}
var mapThis=this;var createVectorLayer=function(layerName,inOptions){var options;if(inOptions.passThrough){options=inOptions.passThrough;}
else{options={};}
var otherOptions={};if(inOptions.strategyTypes){options.strategies=[];for(var i=0;i<inOptions.strategyTypes.length;i++){options.strategies.push(new OpenLayers.Strategy[inOptions.strategyTypes[i]]);}}
if(inOptions.type=='FS'){options.serverLocation=window.location.hostname=="localhost"?"/test/fs/featureserver.cgi/":"/cgi-bin/fs/";inOptions.format='geo';inOptions.protocolOptions={url:options.serverLocation+inOptions.fsFile};}
if(inOptions.type=='GMD'){inOptions.format='kml';inOptions.protocolOptions={url:ServerVars.featureFeed};inOptions.protocolType='GoogleMapsData';if(!ServerVars.gstyle||ServerVars.gstyle!='n'){inOptions.extractStyles=true;}}
options.protocolOptions=inOptions.protocolOptions||{};options.protocolOptions.format=inOptions.protocolOptions.format||createFormat(inOptions.format,inOptions.extractStyles,inOptions.mapProjs);var protocolType=inOptions.protocolType||'HTTP';options.protocol=new OpenLayers.Protocol[protocolType](options.protocolOptions);if(inOptions.defaultStyle){options.styleMap=mapThis.Styles.createStyleMap(inOptions.defaultStyle,inOptions.rulesArray,inOptions.poiStyleWanted);}
if(inOptions.includeInInitialZoom){otherOptions.includeInInitialZoom=inOptions.includeInInitialZoom;}
if(inOptions.featureAdded){otherOptions.featureAdded=inOptions.featureAdded;}
var layer=new Map.OberVector(layerName,options,otherOptions);if(layer.strategies){for(i=0;i<layer.strategies.length;i++){if(layer.strategies[i].CLASS_NAME=="OpenLayers.Strategy.Save"){layer.saveSuccess=function(event){alert('Changes saved');};layer.saveFail=function(event){alert('Error! Changes not saved');};layer.strategies[i].events.on({'success':layer.saveSuccess,'fail':layer.saveFail,scope:layer});}}}
return layer;};this.specifics.setupVectorOptions();var layerOptions=this.specifics.layerOptions;var layers=Array();for(var layerName in layerOptions){layerOptions[layerName].mapProjs=mapProjs;var layer=createVectorLayer(layerName,layerOptions[layerName]);if(this.specifics.afterAdd){this.specifics.afterAdd(layer);}
layers.push(layer);if(layerOptions[layerName].lineLayer){this.map.lineLayerId=layer.id;}
if(layerOptions[layerName].addSelect){layer.featureSelect=this.Controls.selects[layerOptions[layerName].addSelect];}}
if(this.specifics.poi===true){layerOptions=this.getPoiLayerOptions();for(layerName in layerOptions){layerOptions[layerName].mapProjs=mapProjs;layers.push(createVectorLayer(layerName,layerOptions[layerName]));}
this.specifics.switcher=true;}
if(this.specifics.placesLayer){layerOptions=this.getPlacesLayerOptions(this.specifics.placesLayer);layerOptions.mapProjs=mapProjs;layers.push(createVectorLayer('Places',layerOptions));}
this.map.addLayers(layers);OpenLayers.Util.extend(this.map,this.specifics.mapOptions);if(this.specifics.switcher===true){this.Controls.switcher=true;}
if(this.specifics.features=='n'){this.features=false;}
else{this.features=true;}
function createFormat(format,extractStyles,mapProjs){var formats={gml:OpenLayers.Format.GML,kml:OpenLayers.Format.KML,wkt:OpenLayers.Format.WKT,geo:OpenLayers.Format.GeoJSON,atom:OpenLayers.Format.Atom};var options={};if(mapProjs){options.internalProjection=mapProjs.int;options.externalProjection=mapProjs.ext;}
if(extractStyles){if(format=='kml'||format=='atom'){options.extractStyles=true;}}
if(format=='atom'){options.kmlContent=true;options.georssContent=false;}
if(format=='geo'){options.ignoreExtraDims=true;}
return new formats[format](options);}};Map.getVectorControls=function(vectorControls){var controls=Array();for(var i=0;i<vectorControls.length;i++){if(vectorControls[i]=='selectFeature'){var options=this.specifics.selectFeature;if(typeof options.selectFunction=="string"){options.selectFunction=this.Controls.selects[options.selectFunction];}
this.addTooltipDiv();if(options.dialog=='feature'){Dialogs.setups.wiki();}
if(Dialogs.setups[options.dialog]){Dialogs.setups[options.dialog]();}
var controlOptions={callbacks:{over:this.map.featureOver,out:Utils.hideTooltip},onSelect:options.selectFunction};if(options.geometryTypes){controlOptions.geometryTypes=options.geometryTypes;}
var layers=this.map.getLayersByClass('OpenLayers.Layer.Vector');var selectControl=new OpenLayers.Control.SelectFeature(layers,controlOptions);this.map.addControl(selectControl);selectControl.activate();}
if(vectorControls[i]=='baselayerChange'){controls.push(this.Controls.getBaselayerChange(this.map));this.map.getOtherMap=this.Controls.getOtherMap;}
if(vectorControls[i]=='palette'){controls.push(this.Controls.getPalette(this.map));this.map.changeColour=this.Controls.changeColour;}
if(vectorControls[i]=='print'){this.map.print=function(){var perma=this.map.getControl('thisPerma');var params=perma.createParams();var base=perma.base.split('?')[0];base+=ServerVars.bbox?'?bbox='+ServerVars.bbox+'&':'?';var url=base+'zoom='+params.zoom+'&lat='+params.lat+'&lon='+params.lon+'&layers='+params.layers+'&print=y';var w=window.open(url,"MapPrint");w.focus();};var func=this.Controls.getPrintButton();func.trigger=this.map.print;controls.push(func);}
if(vectorControls[i]=='editToolbar'){this.addTooltipDiv();var layerName='Vectors';var noAdd;if(this.specifics.editToolbar){options=this.specifics.editToolbar;if(options.layerName){layerName=options.layerName;}
if(options.noAdd){noAdd=options.noAdd;}}
var layer=this.map.getLayersByName(layerName)[0];layer.newAttribute=this.Controls.newAttribute;layer.enterAttributes=this.Controls.enterAttributes;layer.editAttributes=this.Controls.editAttributes;layer.freshAttributes=this.Controls.freshAttributes;this.map.addControl(this.Controls.getEditToolbar(layer,this.Styles.styles.edit,noAdd));}}
return controls;};Map.OberVector=OpenLayers.Class(OpenLayers.Layer.Vector,{calcKm:false,initialize:function(name,options,otherOptions){OpenLayers.Layer.Vector.prototype.initialize.apply(this,[name,options]);otherOptions=otherOptions||{};if(otherOptions.includeInInitialZoom){this.events.register('loadstart',this,function(){StatusLog.logMsg('fetch',name);});this.events.register('loadend',this,this.loaded);}
if(otherOptions.featureAdded){this.events.register('featureadded',this,otherOptions.featureAdded);}},loaded:function(event){StatusLog.logMsg('loaded',event.object.name);this.map.featureExtent.extend(this.getDataExtent());this.map.feedsRead++;this.map.inputDone();},getTemplate:function(feature){var atts=feature.attributes;var featureId=this.protocol.entries?this.protocol.entries[feature.fid].link[0].href.substr(this.protocol.entries[feature.fid].link[0].href.lastIndexOf('/')+1):feature.fid;var template='<i>featureId</i>: '+featureId;for(var att in atts){if(atts[att]!=''){if(atts[att].substring(0,7)=='http://'){template+='<br /><i>'+att+'</i>: <a target="linktab" href="'+atts[att]+'">'+atts[att]+'</a>';}
else{template+='<br /><i>'+att+'</i>: '+atts[att];}}}
if(feature.geometry.CLASS_NAME=="OpenLayers.Geometry.LineString"){template+='<br />'+this.map.getLength(feature)+' (calculated from map)';if(ServerVars.routeProfile){feature.coords=Array();var clone=feature.geometry.clone();if(this.map.projection!="EPSG:4326"){clone.transform(feature.layer.projection,this.map.displayProjection);}
var vertices=clone.getVertices();for(var i=0;i<vertices.length;i++){feature.coords[i]=[vertices[i].y,vertices[i].x];}
template+='<br /><a id="profile" href="#">Show height profile</a>';template+='<div id="profile"></div>';}}
return template;}});Map.Styles={styles:{select:{strokeColor:"red",fillColor:"red"}},filters:{type_ne_null:{type:OpenLayers.Filter.Comparison.NOT_EQUAL_TO,property:"type",value:null}},rules:{elseFilter:{elseFilter:true}},createStyleMap:function(defaultStyle,rulesArray,poiStyleWanted){if(typeof defaultStyle=="string"){defaultStyle=this.styles[defaultStyle];}
if(poiStyleWanted){OpenLayers.Util.extend(defaultStyle,this.styles.poi);}
var sty=OpenLayers.Util.applyDefaults(defaultStyle,OpenLayers.Feature.Vector.style["default"]);var sm=new OpenLayers.StyleMap({'default':sty,'select':this.styles.select});if(rulesArray){var rules=Array();var mvr=this.rules;for(i=0;i<rulesArray.length;i++){var ruleParams={};if(mvr[rulesArray[i]].filter){ruleParams.filter=new OpenLayers.Filter.Comparison(this.filters[mvr[rulesArray[i]].filter]);}
if(mvr[rulesArray[i]].elseFilter){ruleParams.elseFilter=true;}
if(mvr[rulesArray[i]].minScaleDenominator){ruleParams.minScaleDenominator=mvr[rulesArray[i]].minScaleDenominator;}
if(mvr[rulesArray[i]].symbolizer){ruleParams.symbolizer=this.styles[mvr[rulesArray[i]].symbolizer];}
var rule=new OpenLayers.Rule(ruleParams);rules.push(rule);}
sm.styles['default'].addRules(rules);}
return sm;}};Dialogs.setups.feature=function(){Dialogs.divs.feature='<div id="feature" title="Feature details" style="font-size: 10px"></div>';Dialogs.params.feature={position:'top',autoOpen:false};Dialogs.setup('feature');};Dialogs.setups.wiki=function(){Dialogs.divs.wiki='<div id="wiki" title="Wiki Entry"></div>';Dialogs.params.wiki={position:'top',width:600,maxHeight:300,autoOpen:false};Dialogs.functions.wiki=function(){appendCSS('#p-logo, .generated-sidebar, #p-lang, #p-tb, #p-search, #p-cactions, #p-personal, #footer {display:none;} #mw_content {margin: 0 0 .6em 0;}');};Dialogs.setup('wiki');};Map.Controls.selects={feature:function(feature){if(feature.attributes.clickable=='off'){return;}
if(feature.attributes.wiki){Dialogs.urls.wiki=ServerVars.wiki+feature.attributes.wiki+'?printable=yes';Dialogs.open('wiki',true);}else{var html=feature.layer.getTemplate(feature);jQuery('#feature').html(html);jQuery('#feature').dialog('open');jQuery('#profile').click(jQuery.proxy(function(){topoDrawGraph($('profile'),this.coords,600,250);return false;},feature));}}};;Map.Styles.styles.cyanLine={strokeColor:"cyan"};Map.Styles.styles.route={strokeColor:"blue",strokeOpacity:"0.7",strokeWidth:3,cursor:"pointer"};Map.Styles.rules.cyanLine={filter:'type_ne_null',symbolizer:'cyanLine'}
Map.Controls.getPrintButton=function(){return new OpenLayers.Control.Button({displayClass:"printButton",title:'Open printable page'});};Map.Styles.styles.poi={externalGraphic:Utils.iconLocation+"${type}.png",graphicWidth:32,graphicHeight:37,graphicYOffset:-37,graphicOpacity:1,cursor:"pointer"};Map.Styles.styles.question={strokeColor:"blue",strokeWidth:2,externalGraphic:Utils.imageLocation+"question.png",graphicWidth:32,graphicHeight:32,graphicYOffset:-32,graphicOpacity:1,cursor:"pointer"};Map.Styles.styles.smallerIcon={graphicWidth:24,graphicHeight:27.75,graphicYOffset:-27.75};Map.Styles.filters.type_eq_null={type:OpenLayers.Filter.Comparison.EQUAL_TO,property:"type",value:null}
Map.Styles.rules.iconType={filter:'type_ne_null',symbolizer:'poi'};Map.Styles.rules.invalidIcon={filter:'type_eq_null',symbolizer:'edit'};Map.Styles.rules.questionIcon={filter:'type_eq_null',symbolizer:'question'}
Map.Styles.rules.smallerIcon={minScaleDenominator:300000,symbolizer:'smallerIcon'};Map.getPoiLayerOptions=function(){var layerOptions={};for(var i=0;i<ServerVars['categories'].length;i++){var cat=ServerVars['categories'][i];var options={strategyTypes:['Fixed'],type:'FS',fsFile:"poi?bbox=",passThrough:{visibility:false},defaultStyle:'poi',rulesArray:['smallerIcon','elseFilter']};options.fsFile+=ServerVars['poiExtent']+"&category="+cat;layerOptions[cat]=options;}
return layerOptions;};Map.Controls.getBaselayerChange=function(map){jQuery('#mapbases').dialog({width:400,autoOpen:false});jQuery('#mapbaseForm').submit(function(){map.getOtherMap();return false;});return new OpenLayers.Control.Button({displayClass:"mapButton",trigger:function(){Dialogs.open('mapbases');},title:'View this on another mapbase'});}
Map.Controls.getPalette=function(map){Dialogs.divs.palette='<div id="palette" title="Pick a colour" style="font-size: 10px"></div>';Dialogs.params.palette={width:150,autoOpen:false};Dialogs.urls.palette='/palette.html';Dialogs.functions.palette=function(){jQuery('#paletteForm').submit(function(){map.changeColour();return false;});};Dialogs.setup('palette');return new OpenLayers.Control.Button({displayClass:"paletteButton",trigger:function(){Dialogs.open('palette')},title:'Change routeline colour'});}
Map.Controls.changeColour=function(){var layer=this.getLayersBy('id',this.lineLayerId)[0];var style=layer.styleMap.styles["default"].defaultStyle;style.strokeColor=jQuery('[name=colour]:checked').val()
layer.redraw();}
Map.Controls.getOtherMap=function(){var newmapbase=jQuery('[name=mapbase]:checked').val();var perma=this.getControl('thisPerma');var params=perma.createParams();var newall=false;var oldall=false;for(j=0;j<ServerVars['allCountries'].length;j++){if(newmapbase==ServerVars['allCountries'][j])
var newall=true;if(ServerVars['mapType']==ServerVars['allCountries'][j])
var oldall=true;}
if(oldall==true&&newall==false){params.zoom-=6;}
if(newall==true&&oldall==false){params.zoom+=6;}
var base=perma.base.split('?')[0];base+=ServerVars['bbox']?'?bbox='+ServerVars['bbox']+'&':'?';var url=base+'zoom='+params.zoom+'&lat='+params.lat+'&lon='+params.lon+'&layers='+params.layers;location.href=url.replace('/'+ServerVars['mapType']+'/','/'+newmapbase+'/');};Map.specifics={controls:['perma'],vectorControls:['selectFeature','baselayerChange','palette','print'],mapOptions:{feedCount:1},poi:false,layerOptions:{'Bboxes':{type:'OberVector',format:'geo',protocolOptions:{url:'../../bboxes/'},strategyTypes:['Fixed'],includeInInitialZoom:true,defaultStyle:{strokeColor:"#ff00ff",strokeWidth:3,fillOpacity:0,cursor:"pointer"}},'Route sections':{type:'FS',defaultStyle:'route',rulesArray:['cyanLine','elseFilter'],passThrough:{calcKm:true},addSelect:'feature',lineLayer:true}},selectFeature:{selectFunction:function(feature){if(feature.geometry.CLASS_NAME=="OpenLayers.Geometry.Polygon"){var linesLayer=this.map.getLayersByName('Route sections')[0];linesLayer.protocol.read({url:linesLayer.serverLocation+'details/'+feature.fid,scope:linesLayer,callback:function(resp){this.addFeatures(resp.features)}});feature.destroy();Utils.hideTooltip();}else{this.layers[1].featureSelect(feature);}},dialog:'bbox'},setupVectorOptions:function(){if(!ServerVars['zoom'])
this.mapOptions.zoomToFeatures=true;if(ServerVars['poiExtent'])
this.poi=true;this.layerOptions['Bboxes'].protocolOptions.url+=Utils.getPageName();if(ServerVars['routeAttribution'])
this.layerOptions['Route sections'].passThrough.attribution='Route lines: '+ServerVars['routeAttribution'];Dialogs.setups['feature']();Dialogs.setups['wiki']();}}