Advertisement
feminista2

JS for map listings

Apr 24th, 2020
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. ( function( document, Locations, L ) {
  2.     // Set map center = first restaurant location.
  3.     var center = L.latLng( Locations[0].latitude, Locations[0].longitude );
  4.  
  5.     // Map options.
  6.     // var options = {
  7.         // center: center,
  8.         // zoom: 13
  9.     // };
  10.  
  11.  
  12.     //Initiate Map
  13.     var map = L.map('map' ,{
  14.         zoomAnimation: false
  15.     });
  16.  
  17.     // Set tile layer for Open Street Map.
  18.     var tileLayer = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  19.             attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
  20.         } );
  21.     map.addLayer( tileLayer );
  22.  
  23.     //Make map fit the whole world
  24.     map.fitWorld().zoomIn();
  25.  
  26.  
  27.  
  28.     // Show marker for each location.
  29.     Locations.forEach( function( location ) {
  30.         // Marker options.
  31.         var options = {
  32.             title: location.title,
  33.             icon: L.icon( {
  34.                 iconUrl: location.icon,
  35.                 iconSize: [35,35],
  36.                 iconAnchor: [17,35]
  37.             } )
  38.         };
  39.         var center = L.latLng( location.latitude, location.longitude )
  40.         var marker = L.marker( center, options ).addTo( map );
  41.  
  42.  
  43.         // Show name of the action when click on the icon.
  44.         marker.bindPopup( '<b>' + location.title + '</b><br>' + location.description + '<br>' + "<a href='" + location.link + "'>Read more</a>" ).openPopup();
  45.     } );
  46.  
  47.  
  48.     //Have all popups closed
  49.     map.closePopup();
  50.  
  51. } )( document, Locations, L );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement