/* * Copyright 2017 Google Inc. All rights reserved. * * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this * file except in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF * ANY KIND, either express or implied. See the License for the specific language governing * permissions and limitations under the License. */ // Style credit: https://snazzymaps.com/style/1/pale-dawn const mapStyle = [{ "featureType": "administrative", "elementType": "all", "stylers": [{ "visibility": "on" }, { "lightness": 33 } ] }, { "featureType": "landscape", "elementType": "all", "stylers": [{ "color": "#f2e5d4" }] }, { "featureType": "poi.park", "elementType": "geometry", "stylers": [{ "color": "#c5dac6" }] }, { "featureType": "poi.park", "elementType": "labels", "stylers": [{ "visibility": "on" }, { "lightness": 20 } ] }, { "featureType": "road", "elementType": "all", "stylers": [{ "lightness": 20 }] }, { "featureType": "road.highway", "elementType": "geometry", "stylers": [{ "color": "#c5c6c6" }] }, { "featureType": "road.arterial", "elementType": "geometry", "stylers": [{ "color": "#e4d7c6" }] }, { "featureType": "road.local", "elementType": "geometry", "stylers": [{ "color": "#fbfaf7" }] }, { "featureType": "water", "elementType": "geometry", "stylers": [{ "color": "#21a157" }] }, { "featureType": "water", "elementType": "all", "stylers": [{ "visibility": "on" }, { "color": "#acbcc9" } ] }, ]; // Escapes HTML characters in a template literal string, to prevent XSS. // See https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet#RULE_.231_-_HTML_Escape_Before_Inserting_Untrusted_Data_into_HTML_Element_Content function sanitizeHTML(strings) { const entities = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; let result = strings[0]; for (let i = 1; i < arguments.length; i++) { result += String(arguments[i]).replace(/[&<>'"]/g, (char) => { return entities[char]; }); result += strings[i]; } return result; } function initMap() { // Create the map. const map = new google.maps.Map(document.getElementsByClassName('map')[0], { zoom: 7, center: { lat: 52.1326, lng: 5.2913 }, styles: [{ "featureType": "water", "elementType": "geometry", "stylers": [{ "color": "#21a157" }] }] }); map.data.loadGeoJson('/stores.php'); //Define the custom marker icons, using the store's "category". map.data.setStyle(feature => { return { icon: { url: `/screens/images/raw-svg/${feature.getProperty('category')}_cc.svg`, scaledSize: new google.maps.Size(32, 32) } }; }); const apiKey = 'AIzaSyDHwMU_0zaP0bCS48BXqt1O81sSi0YZs-g'; const infoWindow = new google.maps.InfoWindow(); infoWindow.setOptions({ pixelOffset: new google.maps.Size(0, -30) }); // Show the information for a store when its marker is clicked. map.data.addListener('click', event => { const category = event.feature.getProperty('category'); const name = event.feature.getProperty('name'); const description = event.feature.getProperty('description'); const hours = event.feature.getProperty('hours'); const phone = event.feature.getProperty('phone'); const klanturl = event.feature.getProperty('klanturl'); const klanturlaanbod = event.feature.getProperty('klanturlaanbod'); const klantlogo = event.feature.getProperty('klantlogo'); const position = event.feature.getGeometry().get(); const content = sanitizeHTML `