{"size": 21372, "ext": "js", "max_stars_repo_path": "app/lib/scripts/leaflet-geocoder-mapzen.min.js", "max_stars_repo_name": "mvexel/thenandnow", "max_stars_repo_stars_event_min_datetime": "2015-03-05T10:32:13.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-17T20:59:14.000Z", "max_issues_repo_path": "app/lib/scripts/leaflet-geocoder-mapzen.min.js", "max_issues_repo_name": "mvexel/thenandnow", "max_issues_repo_issues_event_min_datetime": "2015-08-04T17:36:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T20:34:17.000Z", "max_forks_repo_path": "app/lib/scripts/leaflet-geocoder-mapzen.min.js", "max_forks_repo_name": "mvexel/thenandnow", "max_forks_repo_forks_event_min_datetime": "2015-08-04T05:29:30.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-09T17:19:53.000Z"}
{"max_stars_count": 56, "max_issues_count": 6, "max_forks_count": 9, "avg_line_length": 21372.0, "max_line_length": 21372, "alphanum_fraction": 0.8000187161}
(function(factory){var L;if(typeof define==="function"&&define.amd){define(["leaflet"],factory)}else if(typeof module!=="undefined"){L=require("leaflet");module.exports=factory(L)}else{if(typeof window.L==="undefined"){throw new Error("Leaflet must be loaded first")}factory(window.L)}})(function(L){"use strict";var MINIMUM_INPUT_LENGTH_FOR_AUTOCOMPLETE=1;var FULL_WIDTH_MARGIN=20;var FULL_WIDTH_TOUCH_ADJUSTED_MARGIN=4;var RESULTS_HEIGHT_MARGIN=20;var API_RATE_LIMIT=250;var TEXT_STRINGS={INPUT_PLACEHOLDER:"Search",INPUT_TITLE_ATTRIBUTE:"Search",RESET_TITLE_ATTRIBUTE:"Reset",NO_RESULTS:"No results were found.",ERROR_403:"A valid API key is needed for this search feature.",ERROR_404:"The search service cannot be found. :-(",ERROR_408:"The search service took too long to respond. Try again in a second.",ERROR_429:"There were too many requests. Try again in a second.",ERROR_500:"The search service is not working right now. Please try again later.",ERROR_502:"Connection lost. Please try again later.",ERROR_DEFAULT:"The search service is having problems :-("};(function(){var noop=function(){};var console=window.console=window.console||{};if(!("log"in console)){console.log=noop}if(!("warn"in console)){console.warn=console.log}})();L.Control.Geocoder=L.Control.extend({version:"1.8.1",includes:L.Evented?L.Evented.prototype:L.Mixin.Events,options:{position:"topleft",attribution:'Geocoding by <a href="https://mapzen.com/projects/search/">Mapzen</a>',url:"https://search.mapzen.com/v1",placeholder:null,bounds:false,focus:true,layers:null,panToPoint:true,pointIcon:true,polygonIcon:true,fullWidth:650,markers:true,overrideBbox:false,expanded:false,autocomplete:true,place:false,textStrings:TEXT_STRINGS},initialize:function(apiKey,options){if(window.XDomainRequest){this.options.url="//search.mapzen.com/v1"}if(typeof apiKey==="object"&&!!apiKey){options=apiKey}else{this.apiKey=apiKey}if(options&&typeof options.latlng!=="undefined"){if(typeof options.focus==="undefined"){options.focus=options.latlng}console.warn("[leaflet-geocoder-mapzen] DEPRECATION WARNING:","As of v1.6.0, the `latlng` option is deprecated. It has been renamed to `focus`. `latlng` will be removed in a future version.")}if(options&&typeof options.title!=="undefined"){options.textStrings=options.textStrings||{};options.textStrings.INPUT_TITLE_ATTRIBUTE=options.title;console.warn("[leaflet-geocoder-mapzen] DEPRECATION WARNING:","As of v1.8.0, the `title` option is deprecated. Please set the property `INPUT_TITLE_ATTRIBUTE` on the `textStrings` option instead. `title` will be removed in a future version.")}if(options&&typeof options.placeholder!=="undefined"){if(!(options.textStrings&&typeof options.textStrings.INPUT_PLACEHOLDER!=="undefined")){options.textStrings=options.textStrings||{};options.textStrings.INPUT_PLACEHOLDER=options.placeholder}}if(options&&typeof options.textStrings==="object"){for(var prop in this.options.textStrings){if(typeof options.textStrings[prop]==="undefined"){options.textStrings[prop]=this.options.textStrings[prop]}}}L.Util.setOptions(this,options);this.markers=[]},reset:function(){this._input.value="";L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden");this.removeMarkers();this.clearResults();this.fire("reset")},getLayers:function(params){var layers=this.options.layers;if(!layers){return params}params.layers=layers;return params},getBoundingBoxParam:function(params){var bounds=this.options.bounds;if(!bounds){return params}if(bounds===true){bounds=this._map.getBounds();params=makeParamsFromLeaflet(params,bounds)}else if(typeof bounds==="object"&&bounds.isValid&&bounds.isValid()){params=makeParamsFromLeaflet(params,bounds)}else if(L.Util.isArray(bounds)){var latLngBounds=L.latLngBounds(bounds);if(latLngBounds.isValid&&latLngBounds.isValid()){params=makeParamsFromLeaflet(params,latLngBounds)}}function makeParamsFromLeaflet(params,latLngBounds){params["boundary.rect.min_lon"]=latLngBounds.getWest();params["boundary.rect.min_lat"]=latLngBounds.getSouth();params["boundary.rect.max_lon"]=latLngBounds.getEast();params["boundary.rect.max_lat"]=latLngBounds.getNorth();return params}return params},getFocusParam:function(params){var focus=this.options.focus;if(!focus){return params}if(focus===true){var mapCenter=this._map.getCenter();params["focus.point.lat"]=mapCenter.lat;params["focus.point.lon"]=mapCenter.lng}else if(typeof focus==="object"){var latlng=L.latLng(focus);params["focus.point.lat"]=latlng.lat;params["focus.point.lon"]=latlng.lng}return params},getParams:function(params){params=params||{};params=this.getBoundingBoxParam(params);params=this.getFocusParam(params);params=this.getLayers(params);if(this.apiKey){params.api_key=this.apiKey}var newParams=this.options.params;if(!newParams){return params}if(typeof newParams==="object"){for(var prop in newParams){params[prop]=newParams[prop]}}return params},search:function(input){if(!input)return;var url=this.options.url+"/search";var params={text:input};this.callPelias(url,params,"search")},autocomplete:throttle(function(input){if(!input)return;var url=this.options.url+"/autocomplete";var params={text:input};this.callPelias(url,params,"autocomplete")},API_RATE_LIMIT),place:function(id){if(!id)return;var url=this.options.url+"/place";var params={ids:id};this.callPelias(url,params,"place")},handlePlaceResponse:function(response){},maxReqTimestampRendered:(new Date).getTime(),callPelias:function(endpoint,params,type){params=this.getParams(params);L.DomUtil.addClass(this._search,"leaflet-pelias-loading");var reqStartedAt=(new Date).getTime();AJAX.request(endpoint,params,function(err,results){L.DomUtil.removeClass(this._search,"leaflet-pelias-loading");if(err){var errorMessage;switch(err.code){case 403:errorMessage=this.options.textStrings["ERROR_403"];break;case 404:errorMessage=this.options.textStrings["ERROR_404"];break;case 408:errorMessage=this.options.textStrings["ERROR_408"];break;case 429:errorMessage=this.options.textStrings["ERROR_429"];break;case 500:errorMessage=this.options.textStrings["ERROR_500"];break;case 502:errorMessage=this.options.textStrings["ERROR_502"];break;default:errorMessage=this.options.textStrings["ERROR_DEFAULT"];break}this.showMessage(errorMessage);this.fire("error",{results:results,endpoint:endpoint,requestType:type,params:params,errorCode:err.code,errorMessage:errorMessage})}if(results&&results.geocoding&&results.geocoding.errors){errorMessage=results.geocoding.errors[0];this.showMessage(errorMessage);this.fire("error",{results:results,endpoint:endpoint,requestType:type,params:params,errorCode:err.code,errorMessage:errorMessage});return}if(results&&results.features){if(type==="autocomplete"||type==="search"){if(this._input.value===""||this.maxReqTimestampRendered>=reqStartedAt){return}else{this.maxReqTimestampRendered=reqStartedAt}}if(type==="place"){this.handlePlaceResponse(results)}if(type==="autocomplete"||type==="search"){this.showResults(results.features,params.text)}this.fire("results",{results:results,endpoint:endpoint,requestType:type,params:params})}},this)},highlight:function(text,focus){var r=RegExp("("+escapeRegExp(focus)+")","gi");return text.replace(r,"<strong>$1</strong>")},getIconType:function(layer){var pointIcon=this.options.pointIcon;var polygonIcon=this.options.polygonIcon;var classPrefix="leaflet-pelias-layer-icon-";if(layer.match("venue")||layer.match("address")){if(pointIcon===true){return{type:"class",value:classPrefix+"point"}}else if(pointIcon===false){return false}else{return{type:"image",value:pointIcon}}}else{if(polygonIcon===true){return{type:"class",value:classPrefix+"polygon"}}else if(polygonIcon===false){return false}else{return{type:"image",value:polygonIcon}}}},showResults:function(features,input){if(features.length===0){this.showMessage(this.options.textStrings["NO_RESULTS"]);return}var resultsContainer=this._results;resultsContainer.innerHTML="";resultsContainer.style.display="block";resultsContainer.style.maxHeight=this._map.getSize().y-resultsContainer.offsetTop-this._container.offsetTop-RESULTS_HEIGHT_MARGIN+"px";var list=L.DomUtil.create("ul","leaflet-pelias-list",resultsContainer);for(var i=0,j=features.length;i<j;i++){var feature=features[i];var resultItem=L.DomUtil.create("li","leaflet-pelias-result",list);resultItem.feature=feature;resultItem.layer=feature.properties.layer;resultItem.coords=feature.geometry.coordinates;var icon=this.getIconType(feature.properties.layer);if(icon){var layerIconContainer=L.DomUtil.create("span","leaflet-pelias-layer-icon-container",resultItem);var layerIcon;if(icon.type==="class"){layerIcon=L.DomUtil.create("div","leaflet-pelias-layer-icon "+icon.value,layerIconContainer)}else{layerIcon=L.DomUtil.create("img","leaflet-pelias-layer-icon",layerIconContainer);layerIcon.src=icon.value}layerIcon.title="layer: "+feature.properties.layer}resultItem.innerHTML+=this.highlight(feature.properties.label,input)}},showMessage:function(text){var resultsContainer=this._results;resultsContainer.innerHTML="";resultsContainer.style.display="block";var messageEl=L.DomUtil.create("div","leaflet-pelias-message",resultsContainer);messageEl.appendChild(document.createTextNode(text))},removeMarkers:function(){if(this.options.markers){for(var i=0;i<this.markers.length;i++){this._map.removeLayer(this.markers[i])}this.markers=[]}},showMarker:function(text,latlng){this._map.setView(latlng,this._map.getZoom()||8);var markerOptions=typeof this.options.markers==="object"?this.options.markers:{};if(this.options.markers){var marker=new L.marker(latlng,markerOptions).bindPopup(text);this._map.addLayer(marker);this.markers.push(marker);marker.openPopup()}},fitBoundingBox:function(bbox){this._map.fitBounds([[bbox[1],bbox[0]],[bbox[3],bbox[2]]],{animate:true,maxZoom:16})},setSelectedResult:function(selected,originalEvent){var latlng=L.GeoJSON.coordsToLatLng(selected.feature.geometry.coordinates);this._input.value=selected.textContent||selected.innerText;var layer=selected.feature.properties.layer;if(layer!=="venue"&&layer!=="address"&&selected.feature.bbox&&!this.options.overrideBbox){this.removeMarkers();this.fitBoundingBox(selected.feature.bbox)}else{this.removeMarkers();this.showMarker(selected.innerHTML,latlng)}this.fire("select",{originalEvent:originalEvent,latlng:latlng,feature:selected.feature});this.blur();if(this.options.place){this.place(selected.feature.properties.gid)}},focus:function(){if(!L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.expand()}this._input.focus()},blur:function(){this._input.blur();this.clearResults();if(this._input.value===""&&this._results.style.display!=="none"){L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden");if(!this.options.expanded){this.collapse()}}},clearResults:function(force){this._results.style.display="none";if(this._input.value===""||force===true){this._results.innerHTML=""}},expand:function(){L.DomUtil.addClass(this._container,"leaflet-pelias-expanded");this.setFullWidth();this.fire("expand")},collapse:function(){L.DomUtil.removeClass(this._container,"leaflet-pelias-expanded");this._input.blur();this.clearFullWidth();this.clearResults();this.fire("collapse")},setFullWidth:function(){if(this.options.fullWidth){this._map.invalidateSize();var mapWidth=this._map.getSize().x;var touchAdjustment=L.Browser.touch?FULL_WIDTH_TOUCH_ADJUSTED_MARGIN:0;var width=mapWidth-FULL_WIDTH_MARGIN-touchAdjustment;if(typeof this.options.fullWidth==="number"&&mapWidth>=window.parseInt(this.options.fullWidth,10)){this.clearFullWidth();return}this._container.style.width=width.toString()+"px"}},clearFullWidth:function(){if(this.options.fullWidth){this._container.style.width=""}},onAdd:function(map){var container=L.DomUtil.create("div","leaflet-pelias-control leaflet-bar leaflet-control");this._body=document.body||document.getElementsByTagName("body")[0];this._container=container;this._input=L.DomUtil.create("input","leaflet-pelias-input",this._container);this._input.spellcheck=false;L.DomEvent.addListener(this._input,"focus",function(e){this.fire("focus",{originalEvent:e})},this);L.DomEvent.addListener(this._input,"blur",function(e){this.fire("blur",{originalEvent:e})},this);if(this.options.textStrings["INPUT_TITLE_ATTRIBUTE"]){this._input.title=this.options.textStrings["INPUT_TITLE_ATTRIBUTE"]}if(this.options.textStrings["INPUT_PLACEHOLDER"]){this._input.placeholder=this.options.textStrings["INPUT_PLACEHOLDER"]}this._search=L.DomUtil.create("a","leaflet-pelias-search-icon",this._container);this._reset=L.DomUtil.create("div","leaflet-pelias-close leaflet-pelias-hidden",this._container);this._reset.innerHTML="×";this._reset.title=this.options.textStrings["RESET_TITLE_ATTRIBUTE"];this._results=L.DomUtil.create("div","leaflet-pelias-results leaflet-bar",this._container);if(this.options.expanded){this.expand()}L.DomEvent.on(this._container,"click",function(e){this._input.focus()},this).on(this._input,"focus",function(e){if(this._input.value&&this._results.children.length){this._results.style.display="block"}},this).on(this._map,"click",function(e){this.blur()},this).on(this._search,"click",function(e){L.DomEvent.stopPropagation(e);if(L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){if(this.options.expanded===true){this._input.focus()}else{L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden");this.collapse()}}else{if(this._input.value.length>0){L.DomUtil.removeClass(this._reset,"leaflet-pelias-hidden")}this.expand();this._input.focus()}},this).on(this._reset,"click",function(e){this.reset();this._input.focus();L.DomEvent.stopPropagation(e)},this).on(this._input,"keydown",function(e){var list=this._results.querySelectorAll(".leaflet-pelias-result");var selected=this._results.querySelectorAll(".leaflet-pelias-selected")[0];var selectedPosition;var self=this;var panToPoint=function(selected,options){if(selected&&options.panToPoint){var layer=selected.feature.properties.layer;if(layer!=="venue"&&layer!=="address"&&selected.feature.bbox&&!options.overrideBbox){self.removeMarkers();self.fitBoundingBox(selected.feature.bbox)}else{self.removeMarkers();self.showMarker(selected.innerHTML,L.GeoJSON.coordsToLatLng(selected.feature.geometry.coordinates))}}};var scrollSelectedResultIntoView=function(selected){var selectedRect=selected.getBoundingClientRect();var resultsRect=self._results.getBoundingClientRect();if(selectedRect.bottom>resultsRect.bottom){self._results.scrollTop=selected.offsetTop+selected.offsetHeight-self._results.offsetHeight}else if(selectedRect.top<resultsRect.top){self._results.scrollTop=selected.offsetTop}};for(var i=0;i<list.length;i++){if(list[i]===selected){selectedPosition=i;break}}switch(e.keyCode){case 13:if(selected){this.setSelectedResult(selected,e)}else{var text=(e.target||e.srcElement).value;this.search(text)}L.DomEvent.preventDefault(e);break;case 38:if(list.length===0||this._results.style.display==="none"){return}if(selected){L.DomUtil.removeClass(selected,"leaflet-pelias-selected")}var previousItem=list[selectedPosition-1];var highlighted=selected&&previousItem?previousItem:list[list.length-1];L.DomUtil.addClass(highlighted,"leaflet-pelias-selected");scrollSelectedResultIntoView(highlighted);panToPoint(highlighted,this.options);this._input.value=highlighted.textContent||highlighted.innerText;this.fire("highlight",{originalEvent:e,latlng:L.GeoJSON.coordsToLatLng(highlighted.feature.geometry.coordinates),feature:highlighted.feature});L.DomEvent.preventDefault(e);break;case 40:if(list.length===0||this._results.style.display==="none"){return}if(selected){L.DomUtil.removeClass(selected,"leaflet-pelias-selected")}var nextItem=list[selectedPosition+1];var highlighted=selected&&nextItem?nextItem:list[0];L.DomUtil.addClass(highlighted,"leaflet-pelias-selected");scrollSelectedResultIntoView(highlighted);panToPoint(highlighted,this.options);this._input.value=highlighted.textContent||highlighted.innerText;this.fire("highlight",{originalEvent:e,latlng:L.GeoJSON.coordsToLatLng(highlighted.feature.geometry.coordinates),feature:highlighted.feature});L.DomEvent.preventDefault(e);break;default:break}},this).on(this._input,"keyup",function(e){var key=e.which||e.keyCode;var text=(e.target||e.srcElement).value;if(text.length>0){L.DomUtil.removeClass(this._reset,"leaflet-pelias-hidden")}else{L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden")}if(key===13||key===38||key===40){return}if(key===27){if(text.length===0||this._results.style.display==="none"){this._input.blur();if(!this.options.expanded&&L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.collapse()}}this.clearResults(true);L.DomUtil.removeClass(this._search,"leaflet-pelias-loading");return}if(text!==this._lastValue){this._lastValue=text;if(text.length>=MINIMUM_INPUT_LENGTH_FOR_AUTOCOMPLETE&&this.options.autocomplete===true){this.autocomplete(text)}else{this.clearResults(true)}}},this).on(this._results,"click",function(e){L.DomEvent.preventDefault(e);L.DomEvent.stopPropagation(e);var _selected=this._results.querySelectorAll(".leaflet-pelias-selected")[0];if(_selected){L.DomUtil.removeClass(_selected,"leaflet-pelias-selected")}var selected=e.target||e.srcElement;var findParent=function(){if(!L.DomUtil.hasClass(selected,"leaflet-pelias-result")){selected=selected.parentElement;if(selected){findParent()}}return selected};findParent();if(selected){L.DomUtil.addClass(selected,"leaflet-pelias-selected");this.setSelectedResult(selected,e)}},this).on(this._results,"mouseover",function(e){this._scrollWheelZoomEnabled=map.scrollWheelZoom.enabled();if(this._scrollWheelZoomEnabled){map.scrollWheelZoom.disable()}},this).on(this._results,"mouseout",function(e){if(this._scrollWheelZoomEnabled){map.scrollWheelZoom.enable()}},this);if(this.options.fullWidth){L.DomEvent.on(window,"resize",function(e){if(L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.setFullWidth()}},this)}L.DomEvent.on(this._map,"mousedown",this._onMapInteraction,this);L.DomEvent.on(this._map,"touchstart",this._onMapInteraction,this);L.DomEvent.disableClickPropagation(this._container);if(map.attributionControl){map.attributionControl.addAttribution(this.options.attribution)}return container},_onMapInteraction:function(event){this.blur();if(!this.options.expanded){if(!this._input.value&&L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.collapse()}}},onRemove:function(map){map.attributionControl.removeAttribution(this.options.attribution)}});L.control.geocoder=function(apiKey,options){return new L.Control.Geocoder(apiKey,options)};var AJAX={serialize:function(params){var data="";for(var key in params){if(params.hasOwnProperty(key)){var param=params[key];var type=param.toString();var value;if(data.length){data+="&"}switch(type){case"[object Array]":value=param[0].toString()==="[object Object]"?JSON.stringify(param):param.join(",");break;case"[object Object]":value=JSON.stringify(param);break;case"[object Date]":value=param.valueOf();break;default:value=param;break}data+=encodeURIComponent(key)+"="+encodeURIComponent(value)}}return data},http_request:function(callback,context){if(window.XDomainRequest){return this.xdr(callback,context)}else{return this.xhr(callback,context)}},xhr:function(callback,context){var xhr=new XMLHttpRequest;xhr.onerror=function(e){xhr.onreadystatechange=L.Util.falseFn;var error={code:xhr.status,message:xhr.statusText};callback.call(context,error,null)};xhr.onreadystatechange=function(){var response;var error;try{response=JSON.parse(xhr.responseText)}catch(e){response=null;error={code:500,message:"Parse Error"}}if(xhr.readyState===4){if(xhr.status!==200){error={code:xhr.status,message:xhr.statusText};callback.call(context,error,response)}else{if(!error&&response.error){error=response.error}xhr.onerror=L.Util.falseFn;callback.call(context,error,response)}}};return xhr},xdr:function(callback,context){var xdr=new window.XDomainRequest;xdr.onerror=function(e){xdr.onload=L.Util.falseFn;var error={code:500,message:"XMLHttpRequest Error"};callback.call(context,error,null)};xdr.onload=function(){var response;var error;try{response=JSON.parse(xdr.responseText)}catch(e){response=null;error={code:500,message:"Parse Error"}}if(!error&&response.error){error=response.error;response=null}xdr.onerror=L.Util.falseFn;callback.call(context,error,response)};return xdr},request:function(url,params,callback,context){var paramString=this.serialize(params);var httpRequest=this.http_request(callback,context);httpRequest.open("GET",url+"?"+paramString);if(httpRequest.constructor.name==="XMLHttpRequest"){httpRequest.setRequestHeader("Accept","application/json")}setTimeout(function(){httpRequest.send(null)},0)}};function throttle(func,wait,options){var context,args,result;var timeout=null;var previous=0;if(!options)options={};var later=function(){previous=options.leading===false?0:(new Date).getTime();timeout=null;result=func.apply(context,args);if(!timeout)context=args=null};return function(){var now=(new Date).getTime();if(!previous&&options.leading===false)previous=now;var remaining=wait-(now-previous);context=this;args=arguments;if(remaining<=0||remaining>wait){if(timeout){clearTimeout(timeout);timeout=null}previous=now;result=func.apply(context,args);if(!timeout)context=args=null}else if(!timeout&&options.trailing!==false){timeout=setTimeout(later,remaining)}return result}}function escapeRegExp(str){return str.replace(/[-[\]\/{}()*+?.\\^$|]/g,"\\$&")}});