Signin  Pricing  Examples  Support

Libraries > maps.js

maps.js - Search Live Website Code
It's like doing CTRL+F on millions of websites' source code



NerdyData is a search engine for source code. Search the source code of 200 million websites.


JAVASCRIPT FILE http://familybank.co.ke/wp-content/themes/familybank/js/maps.js

Function Explorer









Libraries on familybank.co.ke


jquery.mousewheel.js

jquery.sticky.js

jquery.webticker.min.js

main.js

maps.js

markerclusterer_compiled.js

modernizr.custom.44979.js

perfect-scrollbar.js

swipe.js



Explore More


99446.js

99528.js

ie8compat.1c77a29028ed.js

main.629b99e3c531.js

maps.js
				
var geocoder,
    map,
    latlong,
    markerCluster,
    markers = [],
    image_dir_url = document.body.getAttribute('data-template-url') + '/images/';

// load the maps script
// specify a callback initialize() in the url 
function loadScript() {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyABDtmTfMBisFzZ2ajsUlRgDHi95680Xjw&sensor=false&callback=initialize';
  document.body.appendChild(script);
}
window.onload = loadScript;



//will be called after the maps script loads
function initialize(){
  geocoder = new google.maps.Geocoder();
  map = new google.maps.Map(document.getElementById("map-canvas"));

  //set options
  //styles borrowed from: http://snazzymaps.com/style/15/subtle-grayscale
  map.setOptions({
    styles : [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}]
  });
  // use geolocation web api to get users 
  // current location
  /**/
  if (navigator.geolocation) {
    document.getElementById('my-location').style.display = 'block'; //show my location button for browsers that support geolocation
    geolocate();
  }
  // if no latlong defined yet, that means either we 
  // were denied access to fetch location or we are on an
  // older browser that doesn't support geoloc api
  /*  */
  if( typeof(latlong) === 'undefined') {
    //fetch the address for Nairobi and center map
    geocoder.geocode({ 
      'address': 'Nairobi, Kenya'
    },function(results, status) {
        map.setCenter(results[0].geometry.location);
    });

  }
  /*
 geocoder.geocode({ 
      'address': 'Nairobi, Kenya'
    },function(results, status) {
        map.setCenter(results[0].geometry.location);
    });*/
  map.setZoom(10);

/**/

  //add branch markers to the map
  addMarkers(
    JSON.parse(document.getElementById("branch_json").innerHTML),
    'marker-icon-blue.png',
    true
  );

  // add atm markers to the map
  addMarkers(
    JSON.parse(document.getElementById("atms_json").innerHTML),
    'marker-icon-green.png',
    false
  );

  // add agent markers to the map
  addMarkers(
    JSON.parse(document.getElementById("agents_json").innerHTML),
    'marker-icon-dot.png',
    false
  );
}

// geolocate current user
// and add a marker to the map
function geolocate(){
  navigator.geolocation.getCurrentPosition(function(position){

    latlong = {
      lat: position.coords.latitude,
      lng: position.coords.longitude
    };

    map.setCenter(latlong);
    map.setZoom(13);

    //add a marker to this point
    marker = new google.maps.Marker({
      map: map,
      position: latlong
    });
    
  });



}

function movetoAddress( $address ) {
  geocoder.geocode( { 'address': $address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
      map.setZoom(13);
      
    } else {
      // alert("Geocode was not successful for the following reason: " + status);
    }
  });
}


/**
 * Adds markers to the map
 * 
 * @param object  locations
 * @param {[type]} icon      [description]
 * @param {[type]} action    [description]
 */
function addMarkers(locations,icon,isvisible){
  var infowindow = new google.maps.InfoWindow();
  var marker,i;

  for (i = 0; i < locations.length; i++) {

    marker = new google.maps.Marker({
      position: new google.maps.LatLng(locations[i].latitude, locations[i].longitude),
      icon: image_dir_url + icon,
      map: map
    });
    marker.setVisible(isvisible);

    google.maps.event.addListener(marker, 'click', (function(marker, i) {
      return function(){
        var _content = '';
        if( marker.icon == image_dir_url+ 'marker-icon-blue.png' ) {
          _content = '<b>'+locations[i].title+'</b> <br/> <b>Working Hours:</b> <br />'+locations[i].operating_hours+' <br /> <b>Contact:</b> <br />'+locations[i].phone+' <br />'+locations[i].address2+' <br/>'+locations[i].address1 + '<br/>'+ locations[i].town
        }

        if( marker.icon == image_dir_url+ 'marker-icon-green.png' ) {
          _content = '<b>'+locations[i].title+'</b>  <br/>'+locations[i].physical_location+' <br/>'+locations[i].postal_address +' <br/>'+locations[i].town
        }

        if( marker.icon == image_dir_url+ 'marker-icon-dot.png' ) {
          _content = '<b>'+locations[i].title+'</b> <br/> '+locations[i].location
        }

        infowindow.setContent(_content);
        infowindow.open(map, marker);
      }
    })(marker, i));
      
    // markerCluster.addMarker(marker); //add markers to cluster
    markers.push(marker); //add all markers to this array
  }


}

function toggleMarkers(icon, visible) {
  for (i = 0; i < markers.length; i++) {
    if(markers[i].icon === image_dir_url + icon){
      markers[i].setVisible(visible);
    }
  }
}


//end: remove markers action

//start: remove cluster action
function removeClusters(markerCluster) {
  markerCluster.clearMarkers();
}
//end: remove cluster action


(function($){

  //start: load branches actions  
   $('#branches').change(function() {
      if( $(this).is(':checked') ){
        toggleMarkers('marker-icon-blue.png', true);
      }else{
        //hide markers here
        toggleMarkers('marker-icon-blue.png', false);
      }
   });
   //end: load branches actions
    
   //start: load atms actions
   $('#atms').change(function() {
      if( $(this).is(':checked') ){
          toggleMarkers('marker-icon-green.png', true);
      }else{
        //hide markers here
        toggleMarkers('marker-icon-green.png', false);
      }
   });
    //end: load atms actions
    
   //start: load agents actions
   $('#agents').change(function() {
      if( $(this).is(':checked') ){
          toggleMarkers('marker-icon-dot.png', true);
      }else{
        //hide markers here
        toggleMarkers('marker-icon-dot.png', false);
      }
   });
    //end: load agents actions
  
  // when a county is selected
  $('#county').on('change', function(){
    if( $.trim($(this).val()).length > 0){
      // move map to this
      movetoAddress( $(this).val() + ',Kenya');
    }
    return false;
  });

  $('.btn-my-current-location').on('click', function(){
    geolocate();
    return false;
  });

})(jQuery);


A B C D E F G H I J K L M N O P Q R S T U V W X Y Z