var overpassWizard=function(){"use strict";function e(r,n,t,u){this.message=r,this.expected=n,this.found=t,this.location=u,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,e)}function r(e){var r={};if(e||(e={}),!e){if("undefined"==typeof $)return!1;try{$.ajax("data/iD_presets.json",{async:!1,dataType:"json"}).success((function(r){e=r})).error((function(){throw new Error}))}catch(e){console.error("failed to load presets file","data/iD_presets.json",e)}}return Object.keys(e).map((function(r){var n=e[r];n.nameCased=n.name,n.name=n.name.toLowerCase(),n.terms=n.terms?n.terms.map((function(e){return e.toLowerCase()})):[]})),function(){if("undefined"!=typeof $&&"undefined"!=typeof i18n){var r=i18n.getLanguage();if("en"!=r){var n="data/iD_presets_"+r+".json";try{$.ajax(n,{async:!1,dataType:"json"}).success((function(r){Object.keys(r).map((function(n){var t=r[n];(n=e[n]).translated=!0;var u=n.name;n.nameCased=t.name,n.name=t.name.toLowerCase(),t.terms&&(n.terms=t.terms.split(",").map((function(e){return e.trim().toLowerCase()})).concat(n.terms)),n.terms.unshift(u)}))})).error((function(){throw new Error}))}catch(e){console.error("failed to load preset translations file: "+n)}}}}(),r.get_query_clause=function(r){var n=r.free.toLowerCase(),t=Object.keys(e).map((function(r){return e[r]})).filter((function(e){return!1!==e.searchable&&(e.name===n||(e._termsIndex=e.terms.indexOf(n),-1!=e._termsIndex))}));if(0===t.length)return!1;t.sort((function(e,r){return e.name===n?-1:r.name===n?1:e._termsIndex-r._termsIndex}));var u=t[0],a=[];return u.geometry.forEach((function(e){switch(e){case"point":case"vertex":a.push("node");break;case"line":a.push("way");break;case"area":a.push("way"),a.push("relation");break;case"relation":a.push("relation");break;default:console.error("unknown geometry type "+e+" of preset "+u.name)}})),{types:a.filter((function(e,r,n){return n.indexOf(e)===r})),conditions:Object.keys(u.tags).map((function(e){var r=u.tags[e];return{query:"*"===r?"key":"eq",key:e,val:r}}))}},r.fuzzy_search=function(r){var n=r.free.toLowerCase(),t=2+Math.floor(n.length/7);function u(e){return levenshteinDistance(e,n)<=t}var a=Object.keys(e).map((function(r){return e[r]})).filter((function(e){return!1!==e.searchable&&(!!u(e.name)||e.terms.some(u))}));if(0===a.length)return!1;function o(e){return[e.name].concat(e.terms).map((function(e,r){return levenshteinDistance(e,n)})).reduce((function(e,r){return e<=r?e:r}))}return a.sort((function(e,r){return o(e)-o(r)})),a[0].nameCased},r}var n;return function(e,r){function n(){this.constructor=e}n.prototype=r.prototype,e.prototype=new n}(e,Error),e.buildMessage=function(e,r){var n={literal:function(e){return'"'+u(e.text)+'"'},class:function(e){var r=e.parts.map((function(e){return Array.isArray(e)?a(e[0])+"-"+a(e[1]):a(e)}));return"["+(e.inverted?"^":"")+r+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(e){return e.description}};function t(e){return e.charCodeAt(0).toString(16).toUpperCase()}function u(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+t(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+t(e)}))}function a(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(e){return"\\x0"+t(e)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(e){return"\\x"+t(e)}))}function o(e){return n[e.type](e)}return"Expected "+function(e){var r,n,t=e.map(o);if(t.sort(),t.length>0){for(r=1,n=1;r",y("<>",!1),function(e,r){return{query:"neq",key:e,val:r}},"*",y("*",!1),function(e){return{query:"key",key:e}},"is",y("is",!1),"not",y("not",!1),"null",y("null",!1),"IS",y("IS",!1),"NOT",y("NOT",!1),"NULL",y("NULL",!1),function(e){return{query:"nokey",key:e}},"~=",y("~=",!1),"~",y("~",!1),"=~",y("=~",!1),function(e,r){return{query:"like",key:e,val:r.regex?r:{regex:r}}},"like",y("like",!1),"LIKE",y("LIKE",!1),function(e,r){return{query:"likelike",key:e.regex?e:{regex:e},val:r.regex?r:{regex:r}}},"!~",y("!~",!1),function(e,r){return{query:"notlike",key:e,val:r.regex?r:{regex:r}}},":",y(":",!1),function(e,r){return{query:"substr",key:e,val:r}},"type",y("type",!1),function(e){return{query:"type",type:e}},"user",y("user",!1),"uid",y("uid",!1),"newer",y("newer",!1),"id",y("id",!1),function(e,r){return{query:"meta",meta:e,val:r}},function(e){return{query:"free form",free:e}},k("Key"),/^[a-zA-Z0-9_:\-]/,m([["a","z"],["A","Z"],["0","9"],"_",":","-"],!1,!1),function(e){return e.join("")},'"',y('"',!1),"'",y("'",!1),function(e){return e[1]},k("string"),/^[^'" ()~=!*\/:<>&|[\]{}#+@$%?\^.,]/,m(["'",'"'," ","(",")","~","=","!","*","/",":","<",">","&","|","[","]","{","}","#","+","@","$","%","?","^",".",","],!0,!1),function(e){return e.join("")},"\\",y("\\",!1),{type:"any"},function(e){return e},function(e){return e},/^['"\\bfnrtv]/,m(["'",'"',"\\","b","f","n","r","t","v"],!1,!1),function(e){return e.replace("b","\b").replace("f","\f").replace("n","\n").replace("r","\r").replace("t","\t").replace("v","\v")},"/",y("/",!1),"i",y("i",!1),"",function(e){return{regex:e[1],modifier:e[3]}},"\\/",y("\\/",!1),function(){return"/"},k("whitespace"),/^[ \t\n\r]/,m([" ","\t","\n","\r"],!1,!1)],f=[q("%;;/:#;!/1$;;/($8#: #!!)(#'#(\"'#&'#"),q('%;"/Y#$;""6>7?.A &2@""6@7A.5 &2B""6B7C.) &2D""6D7E/H$$;h&&(h=p,d=[]),d.push(e))}function q(e){return e.split("").map((function(e){return e.charCodeAt(0)-32}))}if((t=function e(n){for(var t,u=f[n],a=0,o=[],i=u.length,c=[],$=[];;){for(;ap?(i=a+3+u[a+1],a+=3):(i=a+3+u[a+1]+u[a+2],a+=3+u[a+1]);break;case 18:c.push(i),o.push(a+4+u[a+2]+u[a+3]),r.substr(p,l[u[a+1]].length)===l[u[a+1]]?(i=a+4+u[a+2],a+=4):(i=a+4+u[a+2]+u[a+3],a+=4+u[a+2]);break;case 19:c.push(i),o.push(a+4+u[a+2]+u[a+3]),r.substr(p,l[u[a+1]].length).toLowerCase()===l[u[a+1]]?(i=a+4+u[a+2],a+=4):(i=a+4+u[a+2]+u[a+3],a+=4+u[a+2]);break;case 20:c.push(i),o.push(a+4+u[a+2]+u[a+3]),l[u[a+1]].test(r.charAt(p))?(i=a+4+u[a+2],a+=4):(i=a+4+u[a+2]+u[a+3],a+=4+u[a+2]);break;case 21:$.push(r.substr(p,u[a+1])),p+=u[a+1],a+=2;break;case 22:$.push(l[u[a+1]]),p+=l[u[a+1]].length,a+=2;break;case 23:$.push(s),0===g&&x(l[u[a+1]]),a+=2;break;case 24:$[$.length-1-u[a+1]],a+=2;break;case 25:p,a++;break;case 26:t=u.slice(a+4,a+4+u[a+3]).map((function(e){return $[$.length-1-e]})),$.splice($.length-u[a+2],u[a+2],l[u[a+1]].apply(null,t)),a+=4+u[a+3];break;case 27:$.push(e(u[a+1])),a+=2;break;case 28:g++,a++;break;case 29:g--,a++;break;default:throw new Error("Invalid opcode: "+u[a]+".")}if(!(c.length>0))break;i=c.pop(),a=o.pop()}return $[0]}(c))!==s&&p===r.length)return t;throw t!==s&&p.searchArea;"),c="(area.searchArea)";break;case"around":u.comment&&p.push("// adjust the search radius (in meters) here"),p.push("{{radius="+u.aroundRadius+"}}"),c="(around:{{radius}},{{geocodeCoords:"+a.area+"}})";break;case"bbox":c=u.globalBbox?"":"({{bbox}})";break;case"global":c=void 0;break;default:return console.error("unknown bounds condition: "+a.bounds),!1}function $(e){function r(e){return e.replace(/([()[{*+.$^\\|?])/g,"\\$1")}function n(e){if("string"==typeof e)return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\t/g,"\\t").replace(/\n/g,"\\n")}var t=n(e.key),u=n(e.val);switch("substr"===e.query&&(e.query="like",e.val={regex:r(e.val)}),""===u&&("eq"===e.query?(e.query="like",e.val={regex:"^$"}):"neq"===e.query&&(e.query="notlike",e.val={regex:"^$"})),""===t&&("key"===e.query?(e.query="likelike",e.key={regex:"^$"},e.val={regex:".*"}):"eq"===e.query?(e.query="likelike",e.key={regex:"^$"},e.val={regex:"^"+r(e.val)+"$"}):"like"===e.query&&(e.query="likelike",e.key={regex:"^$"})),e.query){case"key":return'["'+t+'"]';case"nokey":return'["'+t+'"!~".*"]';case"eq":return'["'+t+'"="'+u+'"]';case"neq":return'["'+t+'"!="'+u+'"]';case"like":return'["'+t+'"~"'+n(e.val.regex)+'"'+("i"===e.val.modifier?",i":"")+"]";case"likelike":return(e.key.modifier||"")==(e.val.modifier||"")?'[~"'+n(e.key.regex)+'"~"'+n(e.val.regex)+'"'+("i"===e.val.modifier?",i":"")+"]":"i"===e.val.modifier?'[~"'+n(e.key.regex)+'"~"'+n(e.val.regex)+'",i][~"'+n(e.key.regex)+'"~".*"]':'[~"'+n(e.key.regex)+'"~"'+n(e.val.regex)+'",i][~".*"~"'+n(e.val.regex)+'"]';case"notlike":return'["'+t+'"!~"'+n(e.val.regex)+'"'+("i"===e.val.modifier?",i":"")+"]";case"meta":switch(e.meta){case"id":return"("+u+")";case"newer":return e.val.match(/^-?\d+ ?(seconds?|minutes?|hours?|days?|weeks?|months?|years?)?$/)?'(newer:"{{date:'+u+'}}")':'(newer:"'+u+'")';case"user":return'(user:"'+u+'")';case"uid":return"(uid:"+u+")";default:return console.error("unknown query type: meta/"+e.meta),!1}case"free form":default:return console.error("unknown query type: "+e.query),!1}}function h(e){function r(e){return null===e.match(/^[a-zA-Z0-9_]+$/)?'"'+e.replace(/"/g,'\\"')+'"':e}function n(e){return null===e.regex.match(/^[a-zA-Z0-9_]+$/)||e.modifier?"/"+e.regex.replace(/\//g,"\\/")+"/"+(e.modifier||""):e.regex}switch(e.query){case"key":return i(r(e.key)+"=*");case"nokey":return i(r(e.key)+"!=*");case"eq":return i(r(e.key)+"="+r(e.val));case"neq":return i(r(e.key)+"!="+r(e.val));case"like":return i(r(e.key)+"~"+n(e.val));case"likelike":return i("~"+n(e.key)+"~"+n(e.val));case"notlike":return i(r(e.key)+"!~"+n(e.val));case"substr":return i(r(e.key)+":"+r(e.val));case"meta":switch(e.meta){case"id":return i("id:"+r(e.val));case"newer":return i("newer:"+r(e.val));case"user":return i("user:"+r(e.val));case"uid":return i("uid:"+r(e.val));default:return""}case"free form":return i(r(e.free));default:return""}}a.query=(l=a.query,(f={logical:"or",queries:[]}).queries=function e(r){if(!r.logical)return[{logical:"and",queries:[r]}];if("and"===r.logical){for(var n=e(r.queries[0]),t=e(r.queries[1]),u=[],a=0;a;"),p.push("out skel qt;")):"recursive_meta"===u.outputMode?(p.push("(._;>;);"),p.push("out meta;")):p.push("out "+u.outputMode+";"),p.join("\n")}}();