Richter Kinderschuhe – Offizieller Webshop für hochwertige Kinderschuhe | Richter Kinderschuhe
function initMap(){ // Create the map. const map = new google.maps.Map(document.getElementById('storefinder67ff7f7e7fc27'), { zoom: 6, center: { lat: 51.9481510, lng: 10.265166 }, }); // Load the stores GeoJSON onto the map. map.data.loadGeoJson('https://cdn02.plentymarkets.com/gi09b7ak6jlw/frontend/storeFinder/RichterListStores0325.json', {idPropertyName: 'storeid'}); const apiKey = 'AIzaSyCAzo7d0yJfTzmjOyf9PjsEHodBP9CzrFc'; const infoWindow = new google.maps.InfoWindow(); // Show the information for a store when its marker is clicked. map.data.addListener('click', (event) => { const name = event.feature.getProperty('name'); const street = event.feature.getProperty('street'); const plz = event.feature.getProperty('plz'); const city = event.feature.getProperty('city'); const country = event.feature.getProperty('country'); const site = event.feature.getProperty('site'); const phone = event.feature.getProperty('phone'); const mail = event.feature.getProperty('mail'); const lat = event.feature.getProperty('lat'); const lang = event.feature.getProperty('lang'); const mapsroute = "https://www.google.com/maps/place/" + lat + "," + lang; const position = event.feature.getGeometry().get(); const blank = "_blank"; const content = "

"+name+"

"+street+", "+plz+", "+city+", "+country+"

"+site+"
"+phone+"
"+mail+"
Zur Route ›

"; infoWindow.setContent(content); infoWindow.setPosition(position); infoWindow.setOptions({pixelOffset: new google.maps.Size(0, -30)}); infoWindow.open(map); }); // Build and add the search bar const card = document.createElement('div'); const titleBar = document.createElement('div'); const title = document.createElement('div'); const container = document.createElement('div'); const input = document.createElement('input'); const options = { fields: ["address_components", "geometry", "icon", "name"], }; card.setAttribute('id', 'pac-card'); title.setAttribute('id', 'title'); title.textContent = 'Gib hier deinen Wohnort ein & finde die nächste Filiale'; titleBar.appendChild(title); container.setAttribute('id', 'pac-container'); input.setAttribute('id', 'pac-input'); input.setAttribute('type', 'text'); input.setAttribute('placeholder', 'Adresse eingeben'); container.appendChild(input); card.appendChild(titleBar); card.appendChild(container); map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card); // Make the search bar into a Places Autocomplete search bar and select // which detail fields should be returned about the place that // the user selects from the suggestions. const autocomplete = new google.maps.places.Autocomplete(input, options); autocomplete.setFields( ['address_components', 'geometry', 'name']); // Set the origin point when the user selects an address const originMarker = new google.maps.Marker({map: map}); originMarker.setVisible(false); let originLocation = map.getCenter(); autocomplete.addListener('place_changed', async () => { originMarker.setVisible(false); originLocation = map.getCenter(); const place = autocomplete.getPlace(); if (!place.geometry) { // User entered the name of a Place that was not suggested and // pressed the Enter key, or the Place Details request failed. window.alert('Wir konnten leider keine Adresse für Ihre Eingabe ermitteln: \'' + place.name + '\''); return; } // Recenter the map to the selected address originLocation = place.geometry.location; map.setCenter(originLocation); map.setZoom(9); originMarker.setPosition(originLocation); originMarker.setVisible(true); // Use the selected address as the origin to calculate distances // to each of the store locations const rankedStores = await calculateDistances(map.data, originLocation); showStoresList(map.data, rankedStores); return; }); } async function calculateDistances(data, origin) { const stores = []; const destinations = []; // Build parallel arrays for the store IDs and destinations data.forEach((store) => { const storeNum = store.getProperty('storeid'); const storeLoc = store.getGeometry().get(); stores.push(storeNum); destinations.push(storeLoc); }); // Retrieve the distances of each store from the origin // The returned list will be in the same order as the destinations list const service = new google.maps.DistanceMatrixService(); const getDistanceMatrix = (service, parameters) => new Promise((resolve, reject) => { service.getDistanceMatrix(parameters, (response, status) => { //console.log(status); //console.log(google.maps.DistanceMatrixStatus); if (status != google.maps.DistanceMatrixStatus.OK) { reject(response); } else { const distances = []; const results = response.rows[0].elements; var loopStartValue = 0; if(loopIndex > 0 ){ loopStartValue = loopIndex * (chunkSize); } for (let j = 0; j < results.length; j++) { const element = results[j]; const distanceText = element.distance.text; const distanceVal = element.distance.value; const distanceObject = { storeid: stores[loopStartValue + j], distanceText: distanceText, distanceVal: distanceVal, }; distances.push(distanceObject); } resolve(distances); } }); }); const chunkSize = 25; var distancesList = []; var loopIndex = 0; for (let i = 0; i < destinations.length; i += chunkSize) { const reducedDestinations = destinations.slice(i, i + chunkSize); calcDistance = await getDistanceMatrix(service, { origins: [origin], destinations: reducedDestinations, travelMode: 'DRIVING', unitSystem: google.maps.UnitSystem.METRIC, }); distancesList.push(...calcDistance) loopIndex++; } distancesList.sort((first, second) => { return first.distanceVal - second.distanceVal; }); return distancesList; } function showStoresList(data, stores) { if (stores.length == 0) { return; } let panel = document.createElement('div'); // If the panel already exists, use it. Else, create it and add to the page. if (document.getElementById('panel')) { panel = document.getElementById('panel'); // If panel is already open, close it if (panel.classList.contains('open')) { panel.classList.remove('open'); } } else { panel.setAttribute('id', 'panel'); const storeFWrapper = document.getElementById('storefinder67ff7f7e7fc27'); const body = document.body; //panel.appendTo("#storefinder67ff7f7e7fc27"); storeFWrapper.insertBefore(panel, storeFWrapper.childNodes[0]); //body.insertBefore(panel, body.childNodes[0]); } // Clear the previous details while (panel.lastChild) { panel.removeChild(panel.lastChild); } var storeOutputLimit = 10; stores.slice(0, storeOutputLimit).forEach((store) => { const currentStore = data.getFeatureById(store.storeid); var storeAdress = "https://www.google.com/maps/place/" + currentStore.getProperty('lat') + "," + currentStore.getProperty('lang'); // Add store details with text formatting const name = document.createElement('p'); const adress = document.createElement('p'); const route = document.createElement('a'); route.href = storeAdress; route.textContent = "Zur Route ›"; route.classList.add('routeLink'); route.setAttribute('target', '_blank') name.classList.add('place'); adress.classList.add('placeAddr'); name.textContent = currentStore.getProperty('name'); panel.appendChild(name); adress.textContent = currentStore.getProperty('street') + ", " + currentStore.getProperty('plz') + " " + currentStore.getProperty('city'); panel.appendChild(adress); const distanceText = document.createElement('p'); distanceText.classList.add('distanceText'); distanceText.textContent = store.distanceText; panel.appendChild(distanceText); panel.appendChild(route); }); // Open the panel panel.classList.add('open'); return; }