1/** 2 * @file Instantiates a Mapbox Geocoder and adds it to the map 3 */ 4 5/** 6 * @param {Object} map - Mapbox map 7 * @param {string} elementId - ID of the element to append the geocoder to 8 * @param {Array} centers - Array of center objects 9 * @param {Function} onResult - Function to run when a result is selected 10 */ 11export function addGeocoder(map, elementId, centers, onResult) { 12 const element = document.getElementById(elementId); 13 14 const geocoder = new MapboxGeocoder({ 15 accessToken: window.mapboxgl.accessToken, 16 countries: 'us,pr', 17 flyTo: false, 18 marker: false, 19 mapboxgl, 20 placeholder: dictionary.geocoderPlaceholder, 21 proximity: 'ip', 22 types: 'country,region,postcode,district,place,locality,neighborhood,address' 23 }); 24 25 geocoder.on('result', function (e) { 26 const result = e.result; 27 const location = result.center; 28 29 //GTM event tracking - Clicking on Select location returned as a result of search 30 if (dictionary && dictionary.gtmPlace) { 31 let yourLocation = "", 32 gtmPlace = Object.assign({}, dictionary.gtmPlace); 33 34 if (document.querySelector(".mapboxgl-ctrl-geocoder--input").value != "") { 35 yourLocation = document.querySelector(".mapboxgl-ctrl-geocoder--input").value; 36 } 37 38 if (gtmPlace.eventLabel.indexOf("{CENTER NAME CLICK RESULT}") >= 0) { 39 // Select location returned as a result of search | [Value available in search bar filed] 40 gtmPlace.eventLabel = (gtmPlace.eventLabel.replace("{CENTER NAME CLICK RESULT}", yourLocation)); 41 } 42 43 if (dictionary.fnGTMPushData) { 44 dictionary.fnGTMPushData(gtmPlace); 45 } 46 } 47 48 onResult(location, result.text); 49 }); 50 51 element.appendChild(geocoder.onAdd(map)); 52 53 return geocoder; 54}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.