Components
54
Accordion Items Basic Hero Basic Map Benefits Card Grid Career Testimonials Case Study Carousel Case Study Content Two Column Contact Form Content Centred Content Image Content Three Columns Content Two Column Content Video Cookie Table Cta Blocks Example Faqs Featured Card Featured Latest Cards Footer Banner Glossary Items Hero Insights Hero Rounded Hero With Featured Insight Home Hero Icon Carousel Image Link Carousel Image Link Carousel 2×2 Image Link Grid Insight Content Job Listing Large Image Large Testimonial Leadership Grid Link Grid Locations Locations Archive Logo Scroller Page Heading People Carousel Related Services Resources Carousel Section Anchors Separator Service Hero Services List Services Tabs Tech Partners Testimonial Carousel Testimonial Single Use Case Component Values Scroller Video

Basic Map

Field
Field Type
Field Name
Instructions
Block Data
tab
Heading Type
select
heading_type
Heading Text
textarea
heading_text
Map Location
google_map
map_location
Content
wysiwyg
content
Block Meta
tab
ID
text
block_id
Block Classes
text
block_classes
Block Theme
select
block_theme
Background Colors
select
background_colors
Padding Top
select
padding_top
Padding Bottom
select
padding_bottom
Margin Top
select
margin_top
Margin Bottom
select
margin_bottom

				
@import "../../resources/scss/util/variables";
@import "../../resources/scss/util/mixins";

.block-basic-map {
	position: relative;

	&__content-container {
		display: flex;
		flex-direction: column;
		justify-content: center;

		@include bp($md, true) {
			padding-top: 1rem;
		}
	}
	
	&__map-container {
		aspect-ratio: 1/1;
	}
}
class BasicMap {
	/**
	 * Create and initialise objects of this class
	 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor
	 * @param {object} block
	 */
	constructor() {
		this.blocks = document.querySelectorAll('.block-basic-map');
		this.init();
	}

	/**
	 * Example function to run class logic
	 * Can access `this.block`
	 */
	init() {
        const lazyLoadMap = (block) => {
            const io = new IntersectionObserver( (entries, observer) => {
                entries.forEach(entry => {
                    if ( entry.isIntersecting ) {
                        this.initMap( block );
                    }
                })
            }, { threshold: [0.7] } );

            io.observe( block );
        }

        this.blocks.forEach(lazyLoadMap);
	}

    initMap( block ) {
        if ( ! mapboxgl ) {
            console.error( mapboxgl );
            return;
        }

        const mapContainer = block.querySelector( '.block-basic-map__map-container' );
        
        // Create a new token - https://account.mapbox.com/
        mapboxgl.accessToken = 'pk.eyJ1Ijoic3RyYXRlZ2lxIiwiYSI6ImNsM243b3J5ZzA1b2YzY2xnejVtM3RsZmsifQ.bxfwR1hd-vlBKVOJfRZ-3A';

        let lng  = parseFloat( mapContainer.getAttribute('data-lng') );
		let lat  = parseFloat( mapContainer.getAttribute('data-lat') );
		let zoom = parseFloat( mapContainer.getAttribute('data-zoom') );

		this.map = new mapboxgl.Map({
			container: mapContainer,
			style: 'mapbox://styles/mapbox/streets-v11',
			center: [lng, lat],
			zoom: zoom,
		});

		new mapboxgl.Marker({
			color: "#FF2C31",
		}).setLngLat( [lng, lat] )
		.addTo( this.map );

		// Add zoom and rotation controls to the map.
		this.map.addControl( new mapboxgl.NavigationControl() );
    }
}

new BasicMap();
This component is not currently used on any pages.
There are is no readme file with this component.