balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

osm-frontend.js (1224B)


      1 jQuery( function( $ ) {
      2 	'use strict';
      3 
      4 	/**
      5 	 * Display Open Street Map
      6 	 */
      7 	function displayMap() {
      8 		var osmTileLayer = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
      9 			attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
     10 		} );
     11 		var options = $( this ).data( 'osm_options' ),
     12 			mapOptions = options.js_options,
     13 			center = L.latLng( options.latitude, options.longitude ),
     14 			map;
     15 
     16 			mapOptions.center = center;
     17 
     18 			// Typcast zoom to a number
     19 			mapOptions.zoom *= 1;
     20 
     21 			map = L.map( this, mapOptions );
     22 			map.addLayer( osmTileLayer );
     23 
     24 		// Set marker
     25 		if ( options.marker ) {
     26 			var markerOptions = {};
     27 
     28 			// Set marker title
     29 			if ( options.marker_title ) {
     30 				markerOptions.title = options.marker_title;
     31 			}
     32 
     33 			// Set marker icon
     34 			if ( options.marker_icon ) {
     35 				markerOptions.icon = L.icon( {
     36 					iconUrl: options.marker_icon
     37 				} );
     38 			}
     39 
     40 			var marker = L.marker( center, markerOptions ).addTo( map )
     41 		}
     42 
     43 		// Set info window
     44 		if ( options.info_window ) {
     45 			marker.bindPopup( options.info_window ).openPopup();
     46 		}
     47 	}
     48 
     49 	// Loop through all map instances and display them
     50 	$( '.rwmb-osm-canvas' ).each( displayMap );
     51 } );