SHARE
TWEET

Untitled

a guest Jun 17th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var map;
  2.  
  3. var markers = [];
  4.  
  5.  
  6. //---------------------Data of Locations-----------------
  7.  
  8. let locations = [{
  9.         name: 'one',
  10.         tour: 'gaudi',
  11.         coords: { lat: 41.403706, lng: 2.173504 },
  12.         content: 'google',
  13.     },
  14.     {
  15.         name: 'one',
  16.         tour: 'gaudi',
  17.         coords: { lat: 41.4145, lng: 2.1527 },
  18.         content: 'maps',
  19.     },
  20.     {
  21.         name: 'two',
  22.         tour: 'gothic',
  23.         coords: { lat: 41.3839, lng: 2.1821 },
  24.         content: 'are'
  25.     },
  26.     {
  27.         name: 'two',
  28.         tour: 'gothic',
  29.         coords: { lat: 41.3840, lng: 2.1762 },
  30.         content: 'annoying'
  31.     }
  32. ];
  33.  
  34. //---------------------Initializing Map-----------------
  35.  
  36. function initMap() {
  37.     var mapOptions = {
  38.         center: new google.maps.LatLng(41.3851, 2.1734),
  39.         zoom: 12
  40.     };
  41.  
  42.  
  43.     map = new google.maps.Map(document.getElementById("map"), mapOptions);
  44.  
  45. }
  46. //---------------------Markers-----------------
  47.  
  48.  
  49.  
  50. function addMarker(props) {
  51.     var marker = new google.maps.Marker({
  52.         position: props.coords,
  53.         map: map,
  54.         icon: props.iconImage
  55.     });
  56.  
  57.     //checking for icon
  58.     if (props.iconImage) {
  59.         marker.setIcon(props.iconImage);
  60.     }
  61.  
  62.     //checking for infowindow
  63.     if (props.content) {
  64.         var infoWindow = new google.maps.InfoWindow({
  65.             content: props.content
  66.         });
  67.  
  68.         marker.addListener('click', function() {
  69.             infoWindow.open(map, marker);
  70.         });
  71.     }
  72. }
  73.  
  74. function updateMarkers() {
  75.     createMarkers();
  76.     for (var i = 0; i < locations.length; i++) {
  77.        addMarker(locations[i]);
  78.     }
  79. }
  80.  
  81. //---------------------Select Tour-----------------
  82.  
  83. function createMarkers() {
  84.     let selectedLocations = locations.filter(function(obj) {
  85.         var selectedTour = document.getElementById("selectTour").value;
  86.         return obj.tour === selectedTour;
  87.     });
  88.  
  89.     let resultlist = [];
  90.  
  91.  
  92.     if (document.getElementById("one").checked) {
  93.         let one = selectedLocations.filter(function(obj) {
  94.             return obj.name === 'one';
  95.         });
  96.         resultlist = resultlist.concat(one);
  97.     }
  98.  
  99.     if (document.getElementById("two").checked) {
  100.         let two = selectedLocations.filter(function(obj) {
  101.             return obj.name === 'two';
  102.         });
  103.         resultlist = resultlist.concat(two);
  104.     }
  105.  
  106.     for (var i = 0; i < resultlist.length;) {
  107.         markers.push({
  108.             coords: {
  109.                 lat: resultlist[i].lat,
  110.                 lng: resultlist[i].lng
  111.             },
  112.             content: resultlist[i].name
  113.         });
  114.     }
  115. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top