/*
MapBBCode, a JavaScript library for parsing, displaying and editing [map] code.
Version 1.2.0 built on 25.12.2013
http://mapbbcode.org
(c) 2013, Ilya Zverev
*/
!function(window,document,undefined){var L=window.L;if(window._tempLL=window.layerList,window.layerList={list:{OpenStreetMap:"L.tileLayer('http://tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: 'Map © OpenStreetMap', minZoom: 0, maxZoom: 19 })","OpenStreetMap DE":"L.tileLayer('http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png', { attribution: 'Map © OpenStreetMap', minZoom: 0, maxZoom: 18 })","OpenStreetMap FR":"L.tileLayer('http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', { subdomains: 'abc', attribution: 'Map © OpenStreetMap | Tiles © OSM France', minZoom: 0, maxZoom: 20 })","Hike & Bike":"L.layerGroup([ L.tileLayer('http://toolserver.org/tiles/hikebike/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Colin Marquardt' } ), L.tileLayer('http://toolserver.org/~cmarqu/hill/{z}/{x}/{y}.png', { minZoom: 0, maxZoom: 17 }) ])",CycleMap:"L.tileLayer('http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Andy Allan', minZoom: 0, maxZoom: 18 })",OpenMapSurfer:"L.tileLayer('http://openmapsurfer.uni-hd.de/tiles/roads/x={x}&y={y}&z={z}', { attribution: 'Map © OSM | Tiles © GIScience Heidelberg', minZoom: 0, maxZoom: 19 })","OpenMapSurfer Contour":"L.layerGroup([ L.tileLayer('http://openmapsurfer.uni-hd.de/tiles/roads/x={x}&y={y}&z={z}', { attribution: 'Map © OSM | Tiles © GIScience Heidelberg', minZoom: 0, maxZoom: 19 }), L.tileLayer('http://openmapsurfer.uni-hd.de/tiles/asterc/x={x}&y={y}&z={z}') ])","OpenMapSurfer Grayscale":"L.tileLayer('http://openmapsurfer.uni-hd.de/tiles/roadsg/x={x}&y={y}&z={z}', { attribution: 'Map © OSM | Tiles © GIScience Heidelberg', minZoom: 0, maxZoom: 19 })",Humanitarian:"L.tileLayer('http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', { attribution: 'Map © OpenStreetMap | Tiles © Humanitarian OSM Team', minZoom: 0, maxZoom: 19 })",Transport:"L.tileLayer('http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Andy Allan', minZoom: 0, maxZoom: 18 })",Landscape:"L.tileLayer('http://{s}.tile3.opencyclemap.org/landscape/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Andy Allan', minZoom: 0, maxZoom: 18 })",Outdoors:"L.tileLayer('http://{s}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Andy Allan', minZoom: 0, maxZoom: 18 })","MapQuest Open":"L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg', { attribution: 'Map © OSM | Tiles © MapQuest', subdomains: '1234', minZoom: 0, maxZoom: 18 })","Stamen Toner":"L.tileLayer('http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Stamen Design', minZoom: 0, maxZoom: 20 })","Stamen Toner Lite":"L.tileLayer('http://{s}.tile.stamen.com/toner-lite/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Stamen Design', minZoom: 0, maxZoom: 20 })","Stamen Watercolor":"L.tileLayer('http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © Stamen Design', minZoom: 3, maxZoom: 16 })",Cloudmade:"L.tileLayer('http://{s}.tile.cloudmade.com/{apiKey}/{styleID}/256/{z}/{x}/{y}.png', { attribution: 'Map © OSM | Tiles © CloudMade', apiKey: '{key:http://account.cloudmade.com/register}', styleID: '1', minZoom: 0, maxZoom: 18 })",MapBox:"L.tileLayer('http://{s}.tiles.mapbox.com/v3/{key:https://www.mapbox.com/#signup}/{z}/{x}/{y}.png', { subdomains: 'abcd', attribution: 'Map © OpenStreetMap' })"},getSortedKeys:function(){var t,e=[];for(t in this.list)this.list.hasOwnProperty(t)&&e.push(t);return e.sort(),e},requiresKey:function(t){var e=/{key(?::[^}]+)?}/,i=this.list[t];return i&&e.test(i)},getKeyLink:function(t){var e=/{key:([^}]+)}/,i=this.list[t],o=i&&i.match(e);return o&&o.length>1&&o[1]?o[1]:""},getLayerName:function(t){if("string"!=typeof t)return"";var e=t.indexOf(":"),i=t.indexOf("|"),o=e>i&&i>0?i:e;return o>0?t.substring(0,o):t},getLeafletLayer:function(layerId,LL){var L=LL||window.L,reKeyC=/{key(?::[^}]+)?}/,m=layerId.match(/^(.+?\|)?(.+?)(?::([^'"]+))?$/),idx=m&&m.length>2&&m[2]?m[2]:"",title=m&&m.length>1&&m[1]&&m[1].length>0?m[1]:idx,keys=m&&m.length>3&&m[3]?m[3].split(":"):[];if(this.list[idx]){for(var layer=this.list[idx],keyPos=0;reKeyC.test(layer)&&keyPoss&&this.isOpenStreetMapLayer(r)&&(s=n.length-1))}if(s>0){var a=n[s];n[s]=n[0],n[0]=a}else 0>s&&n.length>0&&n.unshift(this.getLeafletLayer("OpenStreetMap",e));return n},isOpenStreetMapLayer:function(t){if("string"==typeof t||t.substring)return t.indexOf("openstreetmap.org")>0;var e=t.options&&t._url?t:t.getLayers?t.getLayers()[0]:{};return e.options&&e._url?e.options.attribution&&e.options.attribution.indexOf("openstreetmap.org")>0||e._url.indexOf("tile.openstreetmap.")>0||e._url.indexOf("opencyclemap.org")>0||e._url.indexOf("stamen.com")>0||e._url.indexOf("server.arcgisonline.com")>0:!1}},window._tempLL){if(window._tempLL.list){var i;for(i in window._tempLL.list)window._tempLL.list.hasOwnProperty(i)&&(window.layerList.list[i]=window._tempLL.list[i])}delete window._tempLL}window.MapBBCodeConfig=L.Class.extend({includes:L.Mixin.Events,options:{layers:[],defaultZoom:2,defaultPosition:[22,11],viewWidth:600,viewHeight:300,fullViewHeight:600,editorHeight:400,windowWidth:800,windowHeight:500,fullFromStart:!1,editorInWindow:!0,editorTypeFixed:!1,maxLayers:5},strings:{},initialize:function(t){L.setOptions(this,t)},setStrings:function(t){this.strings=L.extend({},this.strings,t)},addLayer:function(t){this._layerSwitcher.addLayer(t)},_updateDivSize:function(t){var e,i,o=this._mode;"view"===o&&this.options.fullFromStart&&(o="full"),"edit"===o&&this.options.editorInWindow&&(o="window"),"view"===o?(e=""+this.options.viewWidth+"px",i=""+this.options.viewHeight+"px"):"full"===o?(e="100%",i=""+this.options.fullViewHeight+"px"):"edit"===o?(e="100%",i=""+this.options.editorHeight+"px"):"window"===o&&(e=this.options.windowWidth||this.options.viewWidth,i=this.options.windowHeight||this.options.editorHeight,e&&(e+="px"),i&&(i+="px")),t.style.width=e,t.style.height=i},_latLngToArray:function(t){return[L.Util.formatNum(t.lat,5),L.Util.formatNum(t.lng,5)]},_updateFullTitle:function(t,e){"view"===this._mode?(t.setContent(this.strings.view),t.setTitle(this.strings.viewTitle),e.setContent(this.options.fullFromStart?this.strings.viewFull:this.strings.viewNormal),e.setTitle(this.options.fullFromStart?this.strings.viewFullTitle:this.strings.viewNormalTitle)):"edit"===this._mode&&(t.setContent(this.strings.editor),t.setTitle(this.strings.editorTitle),e.setContent(this.options.editorInWindow?this.strings.editInWindow:this.strings.editInPanel),e.setTitle(this.options.editorInWindow?this.strings.editInWindowTitle:this.strings.editInPanelTitle))},bindLayerAdder:function(t){function e(t){return"string"==typeof t?document.getElementById(t):t}var i=e(t.select),o=e(t.button),n=e(t.keyBlock),s=e(t.keyTitle),r=e(t.keyValue);n.style.display="none",r.value="",o.value||(o.value=this.strings.addLayer);var a=function(e){var i=window.event&&window.event.srcElement||e.target||e.srcElement,a=i.value,l=a?window.layerList.getKeyLink(a):"";l?(s.innerHTML=this.strings.keyNeeded.replace("%s",l),r.value="",n.style.display=t.keyBlockDisplay||"inline"):n.style.display="none",o.disabled=a?!1:!0};L.DomEvent.on(i,"change",a,this);var l=function(){var t,e=window.layerList.getSortedKeys(),o=this.options.layers,n=[];for(t=0;tMapBBCode');var n=L.staticLayerSwitcher(this.options.layers,{editable:!0,maxLayers:this.options.maxLayers,enforceOSM:!0});o.addControl(n),n.on("layerschanged",function(t){this.options.layers=t.layers,this.fire("change",this.options)},this),n.on("selectionchanged",function(t){this.fire("layerselected",{id:t.selectedId})},this),this.options.layers=n.getLayerIds(),this._layerSwitcher=n,o.on("moveend zoomend",function(){this.options.defaultPosition=this._latLngToArray(o.getCenter()),this.options.defaultZoom=o.getZoom(),this.fire("change",this.options)},this);var s=L.functionButtons([{content:"full"}],{position:"topright"}),r=L.functionButtons([{content:"mode"}],{position:"topright"}),a=L.functionButtons([{content:'◂',title:this.strings.shrinkTitle},{content:'▸',title:this.strings.growTitle}],{position:"bottomright"}),l=L.functionButtons([{content:'▴',title:this.strings.shrinkTitle},{content:'▾',title:this.strings.growTitle}],{position:"bottomleft"}),h=function(){var t="view"===this._mode?this.options.fullFromStart:!this.options.editorInWindow;t?o.removeControl(a):o.addControl(a)};s.on("clicked",function(){var t="view"===this._mode?this.options.fullFromStart:!this.options.editorInWindow;"view"===this._mode?this.options.fullFromStart=!t:this.options.editorInWindow=t,h.call(this),this._updateFullTitle(r,s),this._updateDivSize(i),o.invalidateSize(),this.fire("change",this.options)},this),r.on("clicked",function(){this._mode="view"===this._mode?"edit":"view",this.options.fullFromStart==this.options.editorInWindow&&h.call(this),this.options.editorTypeFixed&&("view"===this._mode?o.addControl(s):o.removeControl(s)),this._updateFullTitle(r,s),this._updateDivSize(i),o.invalidateSize()},this),a.on("clicked",function(t){var e=100*t.idx-50,n="view"===this._mode?this.options.viewWidth:this.options.windowWidth;n+e>=400&&1e3>=n+e&&("view"===this._mode?this.options.fullFromStart||(this.options.viewWidth+=e,this._updateDivSize(i),o.invalidateSize(),this.fire("change",this.options)):"edit"===this._mode&&this.options.editorInWindow&&(this.options.windowWidth+=e,this._updateDivSize(i),o.invalidateSize(),this.fire("change",this.options)))},this),l.on("clicked",function(t){var e,n=100*t.idx-50;"view"===this._mode?e=this.options.fullFromStart?this.options.fullViewHeight:this.options.viewHeight:"edit"===this._mode&&(e=this.options.editorInWindow?this.options.windowHeight:this.options.editorHeight),e+n>=200&&800>=e+n&&("view"===this._mode?this.options.fullFromStart?this.options.fullViewHeight+=n:this.options.viewHeight+=n:"edit"===this._mode&&(this.options.editorInWindow?this.options.windowHeight+=n:this.options.editorHeight+=n),this._updateDivSize(i),o.invalidateSize(),this.fire("change",this.options))},this),o.addControl(r),o.addControl(s),o.addControl(a),o.addControl(l),this._updateFullTitle(r,s),this.fire("show",this.options)}}}),L.StaticLayerSwitcher=L.Control.extend({includes:L.Mixin.Events,options:{position:"topright",editable:!1,bgColor:"white",selectedColor:"#ddd",enforceOSM:!1,maxLayers:7},initialize:function(t,e){if(L.setOptions(this,e),this._layers=[],this._selected=0,this._layerList=window.layerList&&"isOpenStreetMapLayer"in window.layerList,t)if("push"in t&&"splice"in t)for(var i=0;i0&&this._selected0&&this._selected=0&&this._layers[i];if(o&&o.id!==e){if(o.id=e,o.fromList){var n=this._map&&this._map.hasLayer(t),s=this._layerList?window.layerList.getLeafletLayer(e):null;n&&this._map.removeLayer(t),s?(o.layer=s,n&&this._map.addLayer(s)):this._layers.splice(i,1)}return this._update(),t}return null},addLayer:function(t,e){if(!(this._layers.length>=this.options.maxLayers)){var i=e||this._layerList&&window.layerList.getLeafletLayer(t);if(i){this._layers.push({id:t,layer:i,fromList:!e});var o=this._findFirstOSMLayer();if(o>0){var n=this._layers[o];this._layers[o]=this._layers[0],this._layers[0]=n}return this._map&&this._addMandatoryOSMLayer(),this._update(),this.fire("layerschanged",{layers:this.getLayerIds()}),1==this._layers.length&&this.fire("selectionchanged",{selected:this.getSelectedLayer(),selectedId:this.getSelectedLayerId()}),e}return null}},removeLayer:function(t){var e=this._findLayer(t);if(e>=0){var i=this._selected==e;if(i&&this._map.removeLayer(t),this._layers.splice(e,1),0===e){var o=this._findFirstOSMLayer();if(o>0){var n=this._layers[o];this._layers[o]=this._layers[0],this._layers[0]=n}}return this._selected>=this._layers.length&&this._selected>0&&(this._selected=this._layers.length-1),this._addMandatoryOSMLayer(),this._update(),this.fire("layerschanged",{layers:this.getLayerIds()}),i&&this.fire("selectionchanged",{selected:this.getSelectedLayer(),selectedId:this.getSelectedLayerId()}),t}return null},moveLayer:function(t,e){var i=this._findLayer(t),o=e?i+1:i-1;if(i>=0&&o>=0&&o1))return;o=n}var s=this._layers[i];this._layers[i]=this._layers[o],this._layers[o]=s,i==this._selected?this._selected=o:o==this._selected&&(this._selected=i),this._update(),this.fire("layerschanged",{layers:this.getLayerIds()})}},_findFirstOSMLayer:function(t){if(!this._layerList||!this.options.enforceOSM)return t||0;for(var e=t||0;e=this._layers.length&&(e=-1),e},_addMandatoryOSMLayer:function(){if(this.options.enforceOSM&&this._layers.length>0&&this._findFirstOSMLayer()<0){var t=L.tileLayer("http://tile.openstreetmap.org/{z}/{x}/{y}.png",{attribution:'Map © OpenStreetMap',minZoom:0,maxZoom:19});this._selected0&&"position"in t[0]&&(e={position:t[0].position}),L.Control.prototype.initialize.call(this,e)},onAdd:function(t){this._map=t,this._links=[];for(var e=L.DomUtil.create("div","leaflet-bar"),i=0;i=this._buttons.length)){var e=this._buttons[t],i=e.link,o=e.content;if(i)if(o===undefined||o===!1||null===o||""===o)i.innerHTML=e.alt||" ";else if("string"==typeof o){var n=o.length<4?"":o.substring(o.length-4),s="data:image/"===o.substring(0,11);".png"===n||".gif"===n||".jpg"===n||s?(i.style.width=""+(e.imageSize||26)+"px",i.style.height=""+(e.imageSize||26)+"px",i.style.padding="0",i.style.backgroundImage="url("+o+")",i.style.backgroundRepeat="no-repeat",i.style.backgroundPosition=e.bgPos?-e.bgPos[0]+"px "+-e.bgPos[1]+"px":"0px 0px"):i.innerHTML=o}else{for(;i.firstChild;)i.removeChild(i.firstChild);i.appendChild(o)}}},setContent:function(t,e){e===undefined&&(e=t,t=0),thow to get it)',keyNeededAlert:"This layer needs a developer key"}})}(window,document);