Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css">
<section id="page-header" class="" "="">
    <div class="wrap-max-site-width">
        <div class="content">
          <header class="page-header ">
            <h1 class="page-title">Locations</h1>
            <p class="doc-link">Looking for a doctor's office? Use our <a href="/find-doctor">Doctor Finder</a>. </p>
            <input id="autocompleteInput" type="text"
        placeholder="Enter a location">
            </header>
        </div>
    </div>
    <a class="view-all button " href="#loc-map">View All Locations <i aria-hidden="true" class="icon-arrow-down"></i></a>
</section>
                                                                                                                
                                                                     <div id="vue-map">

  <div id="map_canvas2"></div>
    
         <div class="box">
                <div class="notification">
                    <i class="fas fa-bell"></i>
                    <span v-if="!noVisibleMarkers" class="num"> {{ visibleMarkers.length }}</span>
                <div class="mapNotifications">
                        <h2 v-if="noVisibleMarkers">There are no stores in the current view. Listing stores in 400km radius from your location:</h2>
    <h2 v-else>Your viewport contains {{ visibleMarkers.length }} stores, if you want to show specific stores, please zoom in or type your request into the search field.</h2>
                </div>
            </div>
    </div>
  <div class="locationsList">      
  <ul class="" id="results-list" v-if="!noVisibleMarkers">
    <li v-for="(marker, i) in visibleMarkers"  v-on:mouseover="mouselog(event, marker.id)" >
      <strong>{{ marker.name }}</strong><br/>
      <span>is boutique: {{ marker.boutique ? 'yes' : 'no'}}</span><br/>
      <span v-if="currentLocation">distance from your location: {{ Math.round(marker.distanceFromCenter / 1000) + ' km' }}<br/></span>
      <span>lat: {{ marker.position.lat() }}</span><br/>
      <span>lng: {{ marker.position.lng() }}</span>
      <button v-bind:data-id='marker.id' @click='centerMapToMarker'>show on map</button>
    </li>
  </ul>
  
</div>
</div>



<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js">
    </script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDlfHdTSE_d9zwwYKs5gbL01mHElMLCFgE&libraries=places,geometry"></script>
              
            
!

CSS

              
                #page-header{
    height: 400px;
    display: flex;
    

      justify-content: center;
    width: 100%;
    position: relative;
    color: #fff;
    background-image: linear-gradient(135deg,#3BBEAA 0%,#170F86);
}
.wrap-max-site-width{
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
#autocompleteInput{
  width: 100%;
}
#vue-map{
  display: flex;
  flex-direction: row;
  width: 100%;
  flex-wrap: wrap;
  padding: 0px;
  margin: 0px;
  position: relative;
}
#map_canvas2 {
  width: 69%;
  height: 500px;
  border: 1px solid black;
  order: 2;
  padding: 0px;
  margin: 0px;
   display: block;
  position: relative;
}

.locationsList{
  width: 30%;
  display: block;
  position: relative;
  order: 1;
  padding: 0px;
  margin: 0px;
  margin-top: 50px;
}

#results-list{
   padding: 0px;
  margin: 0px;
}
li{
  padding: 25px 0 25px 60px;
  counter-increment: item;
      border-bottom: 1px solid #dadedf;
    counter-increment: item;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
  flex-direction: column;
    margin-bottom: 0;
    position: relative;
    -webkit-transition: all 0.6s;
    transition: all 0.6s;
}
li:before{
    background: #041f48;
    border-radius: 100%;
    color: white;
    content: counter(item);
    display: inline-block;
    margin: 0 0 0 -35px;
    text-align: center;
    width: 1.7em;
    min-width: 1.7em;
    height: 1.7em;
    -webkit-transition: all 0.6s;
    transition: all 0.6s;
    font-weight: 700;
  } 

li:hover:after{
    content: '';
    height: 100%;
    width: 6px;
    position: absolute;
    background: #378fdb;
    top: 0;
    left: -6px;
    -webkit-transition: all 0.6s;
    transition: all 0.6s;
}
li:after{
content: '';
    height: 100%;
    width: 0px;
    position: absolute;
    background: #378fdb;
    top: 0;
    left: -6px;
    -webkit-transition: all 0.6s;
    transition: all 0.6s;
}
input {
  height: 50px;
  line-height: 50px;
  font-size: 30px;
  margin: 1em 0;
  padding: .25em;
}

.box{
      display: flex;
    position: absolute;
    width: 100%;
    flex-direction: row;
    align-items: right;
    justify-content: initial;
    align-content: flex-end;
    left: -0px;
  top: -30px;
}
.notification{
    width: 100%;
  display: flex;
    flex-direction: row;
}

.notification .fas{
    color: #cecece;
    line-height: 60px;
    font-size: 30px;
  width: 60px;
    height: 60px;
    background: #fff;
    border-radius: 30px;
    box-sizing: border-box;
    text-align: center;
  position: relative;
  margin-right: -30px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.notification .num{
    position: absolute;
    top: -10px;
    left:40px;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    background: #995cfa;
    color: #fff;
    line-height: 25px;
    font-family: sans-serif;
    text-align: center;
}

.mapNotifications{
    width: 30%;
    font-size: 14px;
    display: flex;
    align-items: center;
    font-weight: 500;
    flex-direction: row;
    align-items: right;
    justify-content: initial;
    align-content: flex-end;
    right: 0px;
    background: #fff;
    padding-left: 40px;
    padding-right: 10px;
    line-height: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.mapNotifications h2{
  font-weight: 500;
  font-size: 20px;
  margin: 0px;
  padding: 0px;
}
.background{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: linear-gradient(135deg,#3BBEAA 0%,#170F86);
}
              
            
!

JS

              
                var demo = new Vue({
  el: "#vue-map",
  data: {
    options: {
      zoom: 3,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: new google.maps.LatLng(-31.563910, 140.19179)
    },
    map: "",
    zoomTreshold: 4,
    radiusTreshold: 400000, // in meters
    locations: [
      { lat: -31.563910, lng: 147.154312 },
      { lat: -33.718234, lng: 150.363181 },
      { lat: -33.727111, lng: 150.371124 },
      { lat: -33.848588, lng: 151.209834 },
      { lat: -33.851702, lng: 151.216968 },
      { lat: -34.671264, lng: 150.863657 },
      { lat: -35.304724, lng: 148.662905, boutique: true },
      { lat: -36.817685, lng: 175.699196 },
      { lat: -36.828611, lng: 175.790222 },
      { lat: -37.750000, lng: 145.116667 },
      { lat: -37.759859, lng: 145.128708 },
      { lat: -37.765015, lng: 145.133858 },
      { lat: -37.770104, lng: 145.143299 },
      { lat: -37.773700, lng: 145.145187 },
      { lat: -37.774785, lng: 145.137978 },
      { lat: -37.819616, lng: 144.968119 },
      { lat: -38.330766, lng: 144.695692 },
      { lat: -39.927193, lng: 175.053218 },
      { lat: -41.330162, lng: 174.865694 },
      { lat: -42.734358, lng: 147.439506 },
      { lat: -42.734358, lng: 147.501315 },
      { lat: -42.735258, lng: 147.438000 },
      { lat: -43.999792, lng: 170.463352, boutique: true }
    ],
    visibleMarkers: [],
    noVisibleMarkers: false,
    markers: [],
    uluru: [{ lat: -25.363, lng: 131.044 }],
    infoWindow: "",
    currentZoom: 0,
    currentLocation: ""
  },
  watch: {
    locations: function(val) {
      this.deleteMarkers();
      this.createMarkers();
    }
  },
  methods: {
    addUluru: function() {
      for (var i = 0; i < this.uluru.length; i++) {
        this.locations.push(this.uluru[i]);
      }
    },
    createMarkers: function() {
      var self = this;
      this.markers = this.locations.map(function(location, i) {
        var infoWindowContent =
          "<h2> Marker n. " +
          i +
          "</h2>" +
          "<br />" +
          "<p>lat: " +
          location.lat +
          "<br />lng: " +
          location.lng +
          "</p>";
        var marker = new google.maps.Marker({
          position: location,
          name: "Marker n. " + i,
          boutique: location.boutique,
          info: infoWindowContent,
          id: i + 1
        });
        google.maps.event.addListener(marker, "click", function() {
          self.infoWindow.setContent(this.info);
          self.infoWindow.open(self.map, this);
        });
        return marker;
      });
      new MarkerClusterer(this.map, this.markers, {
        imagePath: "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m"
      });
    },
    deleteMarkers() {
      for (var i = 0; i < this.markers.length; i++) {
        this.markers[i].setMap(null);
      }
      this.markers = [];
    },
    getVisibleMarkers: function() {
      var self = this;
      google.maps.event.addListener(self.map, "idle", function() {
        self.noVisibleMarkers = false;
        
        // Read the bounds of the map being displayed.
        bounds = self.map.getBounds();

        // delete previously added items
        self.visibleMarkers = [];

        // Iterate through all of the markers that are displayed on the *entire* map.
        for (var i = 0; i < self.markers.length; i++) {
          currentMarker = self.markers[i];

          /* If the current marker is visible within the bounds of the current map,
           * let's add it as a list item to #nearby-results that's located above
           * this script.
           */
          if (bounds.contains(currentMarker.getPosition())) {
            /* Only add a list item if it doesn't already exist. This is so that				  				 
             * if the browser is resized or the tablet or phone is rotated, we don't
             * have multiple results.
             */

            self.visibleMarkers.push(currentMarker);
          }
        }
        console.log(self.visibleMarkers);
        if (self.visibleMarkers.length) {
          self.moveBoutiquesToTop();
        } else {
          self.noVisibleMarkers = true;
          self.getInvisibleMarkersInTresholdRadius();
          self.moveBoutiquesToTop();
        }
      });
      
      console.log(this.noVisibleMarkers);
    },
    getInvisibleMarkersInTresholdRadius: function() {
      // TODO: maybe find a less expensive way?
      var center = this.currentLocation.position ? this.currentLocation.position : this.map.center;
      for (var i = 0; i < this.markers.length; i++) { 
        var distance = google.maps.geometry.spherical.computeDistanceBetween(
          center,
          this.markers[i].position
        );
        if (distance < this.radiusTreshold) {
          this.visibleMarkers.push(this.markers[i]);
        }
      }
    },
    moveBoutiquesToTop: function() {
      var center = this.currentLocation.position ? this.currentLocation.position : this.map.center;
      for (var i = 0; i < this.visibleMarkers.length; i++) {
        var distance = google.maps.geometry.spherical.computeDistanceBetween(
          center,
          this.visibleMarkers[i].position
        );
        this.visibleMarkers[i].distanceFromCenter = distance;
        // if closer than 400 km AND is a boutique
        if (distance < this.radiusTreshold && this.visibleMarkers[i].boutique) {
          // move marker to the start of the array
          var a = this.visibleMarkers.splice(i, 1);
          this.visibleMarkers.unshift(a[0]);
        }
      }
    },
    initAutocomplete: function() {
      var self = this;
      var autocompleteInput = document.getElementById("autocompleteInput");
      var autocomplete = new google.maps.places.Autocomplete(autocompleteInput);
      autocomplete.addListener("place_changed", function() {
        var 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("No details available for input: '" + place.name + "'");
          return;
        } else {
          if (self.currentLocation) {
            self.currentLocation.setMap(null);
          }                 
          self.currentLocation = new google.maps.Marker({
            position: place.geometry.location,
            id: "currentLocation",
            icon: "https://mt.googleapis.com/vt/icon/name=icons/onion/SHARED-mymaps-pin-container_4x.png,icons/onion/1899-blank-shape_pin_4x.png&highlight=0288D1&scale=2.0",
            map: self.map
          });
          self.getVisibleMarkers();
        }
        // If the place has a geometry, then present it on a map.
        if (place.geometry.viewport) {
          self.map.fitBounds(place.geometry.viewport);
        } else {
          self.map.setCenter(place.geometry.location);
          self.map.setZoom(4); // Why 17? Because it looks good.
        }
      });
    },
    getCurrentZoom: function() {
      var self = this;
      google.maps.event.addListener(self.map, "idle", function() {
        self.currentZoom = self.map.zoom;
      });
    },
    centerMapToMarker: function(e) {
      var id = e.target.dataset.id;
      for (var i = 0; i < this.visibleMarkers.length; i++) {
        if (this.visibleMarkers[i].id == id) {
          var thisMarker = this.visibleMarkers[i];
          // open info window above marker
          // this.infoWindow.setContent(thisMarker.info);
          // this.infoWindow.open(this.map, thisMarker);
          // pan map to the marker

          this.map.panTo(thisMarker.getPosition());
          this.map.setZoom(17);
          return false;
        }
      }
    },
    centerMapToMarkerHover: function(i) {
      var id = i;
      for (var i = 0; i < this.visibleMarkers.length; i++) {
        if (this.visibleMarkers[i].id == id) {
          var thisMarker = this.visibleMarkers[i];
          // open info window above marker
          // this.infoWindow.setContent(thisMarker.info);
          // this.infoWindow.open(this.map, thisMarker);
          // pan map to the marker

          this.map.panTo(thisMarker.getPosition());
    
          return false;
        }
      }
    },
    mouselog: function(e, i) {
      console.log(e)
      if (e.type = "mouseover") {
        this.centerMapToMarkerHover(i);
      } 
      
    }
  },
  mounted: function() {
    this.map = new google.maps.Map(
      document.getElementById("map_canvas2"),
      this.options
    );
    this.createMarkers();
    this.getVisibleMarkers();
    this.infoWindow = new google.maps.InfoWindow({ content: "" });
    this.initAutocomplete();
    this.getCurrentZoom();
  }
});

              
            
!
999px

Console