css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="map-canvas"></div>
            
          
!
            
              $sans-serif: "Montserrat", sans-serif;

html {
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: $sans-serif;
}

#map-canvas {
  height: 100%;
}

.controlUI {
  background: #fff;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.controlText {
  color: rgb(25, 25, 25);
  padding: 5px;
}

.elevation-title {
  padding: 2px 5px;
  display: block;
}

.elevation {
  display: block;
  padding: 2px 5px;
}

.label {
  padding: 2px 5px;
}

.elevation.purple,
.label.purple {
  background: #4f369c;
  color: #fff;
}

.elevation.red,
.label.red {
  background: #ec5d50;
  color: #fff;
}

.elevation.yellow,
.label.yellow {
  background: #ece452;
  color: #000;
}

.elevation.green,
.label.green {
  background: #00ee3f;
  color: #000;
}

.elevation.blue,
.label.blue {
  background: #5279ed;
  color: #fff;
}

.data-content {
  h3 {
    text-transform: uppercase;
    color: #000;
    border-bottom: 1px dashed #bbb;
    margin-bottom: 5px;
    padding-bottom: 5px;
    margin: 0;
    color: #555;
    display: block;
  }
  p {
    line-height: 20px;
    margin: 0;
    color: #555;
    display: block;
  }
}

.project-title {
  font-family: $sans-serif;
  font-size: 12px;
  color: #fff;
  a {
    text-decoration: none;
    color: #00aadc;
    &:hover {
      color: #78dcfa;
    }
  }
}

.controlUI2 {
  background: #000;
  opacity: 0.5;
  padding: 5px;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 20px;
}

            
          
!
            
              var elevationIndicatorHTML = '<span class="elevation-title">Elevation</span><span class="elevation purple">2000m and above</span><span class="elevation red">1000m - 1999m</span><span class="elevation yellow">500m - 999m</span><span class="elevation green">200m - 499m</span><span class="elevation blue">0 - 199m</span>';

var projectTitleHTML = '<div class="project-title">Elevation Peaks in Malaysia &middot; <a href="https://heiswayi.nrird.com/2018/elevation-peaks-in-malaysia">Learn More</a></div>';

function initialize() {
  var latitude = 4,
    longitude = 109.5,
    center = new google.maps.LatLng(latitude, longitude),
    mapOptions = {
      center: center,
      zoom: 6,
      mapTypeId: google.maps.MapTypeId.TERRAIN,
      scrollwheel: true,
      styles: [{"featureType":"all","elementType":"labels.text.fill","stylers":[{"saturation":36},{"color":"#000000"},{"lightness":40}]},{"featureType":"all","elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#000000"},{"lightness":16}]},{"featureType":"all","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":17},{"weight":1.2}]},{"featureType":"administrative.country","elementType":"geometry","stylers":[{"visibility":"off"}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":20}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":21}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"color":"#000000"},{"lightness":17}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"color":"#000000"},{"lightness":29},{"weight":0.2}]},{"featureType":"road.arterial","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":18}]},{"featureType":"road.local","elementType":"geometry","stylers":[{"color":"#000000"},{"lightness":16}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#313030"},{"lightness":19}]},{"featureType":"transit","elementType":"labels.text","stylers":[{"saturation":"-33"}]},{"featureType":"water","elementType":"geometry","stylers":[{"color":"#2b3032"},{"lightness":17}]}]
    };

  var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
  var bounds = new google.maps.LatLngBounds();
  setMarkers(center, map, bounds);

  var markerLegendsDiv = document.createElement('div');
  markerLegendsDiv.style.marginTop = '10px';
  markerLegendsDiv.style.marginRight = '10px';
  var control1 = new markerLegends(markerLegendsDiv, elevationIndicatorHTML);
  markerLegendsDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(markerLegendsDiv);

  var projectTitleDiv = document.createElement('div');
  projectTitleDiv.style.marginBottom = '10px';
  var control2 = new projectTitle(projectTitleDiv, projectTitleHTML);
  projectTitleDiv.index = 1;
  map.controls[google.maps.ControlPosition.BOTTOM_CENTER].push(projectTitleDiv);
}

function setMarkers(center, map, bounds) {
  var json = (function() {
    var json = null;
    $.ajax({
      'async': false,
      'global': false,
      'url': "https://raw.githubusercontent.com/heiswayi/elevation-peaks/master/data.json",
      'dataType': "json",
      'success': function(data) {
        json = data;
      }
    });
    return json;
  })();

  //loop between each of the json elements
  for (var i = 0, length = json.length; i < length; i++) {
    var data = json[i],
      latLng = new google.maps.LatLng(data.lat, data.lng);


    var markerColor = getMarkerColor(parseInt(data.elevation));
    var marker = new google.maps.Marker({
      position: latLng,
      map: map,
      animation: google.maps.Animation.DROP,
      title: data.title,
      icon: markerColor
    });

    infoBox(map, marker, data);
    bounds.extend(latLng);
  }

  //map.setCenter(bounds.getCenter());
  map.fitBounds(bounds);
  //map.setZoom(map.getZoom()+2);
}

function infoBox(map, marker, data) {
  var infoWindow = new google.maps.InfoWindow();
  // Attaching a click event to the current marker
  google.maps.event.addListener(marker, "click", function(e) {
    infoWindow.setContent(data.remark);
    infoWindow.open(map, marker);
  });

  // Creating a closure to retain the correct data
  // Note how I pass the current data in the loop into the closure (marker, data)
  (function(marker, data) {
    // Attaching a click event to the current marker
    var content_html = '<div class="data-content"><h3>'+data.title+'</h3><p><strong>GPS Coordinate:</strong> '+data.lat+', '+data.lng+'</p><p><strong>Elevation:</strong> <span class="'+getColorClass(parseInt(data.elevation))+'">'+data.elevation+'m</span></p><p><strong>Remark:</strong> '+data.remark+'</p></div>';
    google.maps.event.addListener(marker, "click", function(e) {
      infoWindow.setContent(content_html);
      infoWindow.open(map, marker);
    });
  })(marker, data);
}

function getMarkerColor(value) {
  if (value >= 0 && value <= 199) return "https://maps.google.com/mapfiles/ms/icons/blue-dot.png";
  else if (value >= 200 && value <= 499) return "https://maps.google.com/mapfiles/ms/icons/green-dot.png";
  else if (value >= 500 && value <= 999) return "https://maps.google.com/mapfiles/ms/icons/yellow-dot.png";
  else if (value >= 1000 && value <= 1999) return "https://maps.google.com/mapfiles/ms/icons/red-dot.png";
  else if (value >= 2000) return "https://maps.google.com/mapfiles/ms/icons/purple-dot.png";
  else return "https://storage.googleapis.com/support-kms-prod/SNP_2752125_en_v0";
}

function getColorClass(value) {
  if (value >= 0 && value <= 199) return "label blue";
  else if (value >= 200 && value <= 499) return "label green";
  else if (value >= 500 && value <= 999) return "label yellow";
  else if (value >= 1000 && value <= 1999) return "label red";
  else if (value >= 2000) return "label purple";
  else return "no-color";
}

function markerLegends(controlDiv, html) {
  var controlUI = document.createElement('div');
  controlUI.className = 'controlUI';
  controlUI.title = 'Elevation Categories';
  controlDiv.appendChild(controlUI);

  var controlText = document.createElement('div');
  controlText.className = 'controlText';
  controlText.innerHTML = html;
  controlUI.appendChild(controlText);
}

function projectTitle(controlDiv, html) {
  var controlUI = document.createElement('div');
  controlUI.className = 'controlUI2';
  controlDiv.appendChild(controlUI);

  var controlText = document.createElement('div');
  controlText.className = 'controlText2';
  controlText.innerHTML = html;
  controlUI.appendChild(controlText);
}

google.maps.event.addDomListener(window, 'load', initialize);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console