Components
53
Accordion Items Article Selection Author Info Basic Carousel Basic Hero Basic Map Blog Pull Out Carousel Carousel Contact Content Accordion Content Carousel Content Image Cta Cta Bar Cta Blocks Cta Collage Event Content Events Grid Example Find Firm Firm Search Firms By Town Gated Content Download Guides Carousel Hero History Homepage Hero Image Content Cta Image List Content Industries Job Content Job Listings Local Firm Carousel Our Firms Pages Carousel Partners Partners Slider People Listing Post Carousel Post Feed Pullquote Section Wrap Service List Split Content Stats Tax Guides Team Grid Title Logos Two Column Video Video Carousel Video Old

Basic Map

Field
Field Type
Field Name
Instructions
Section Title
clone
block_basic_map_section_title
-- Format
select
format
-- Text
text
text
Content
wysiwyg
content
Map Location
google_map
map_location

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

.block-basic-map {
	position: relative;
	padding: rem-calc(40px) 0;

	@include bp($md) {
		padding: 0;
	}

	&__content-container {
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: rem-calc(40px) auto;

		@include bp($md, true) {
			padding-top: 1rem;
		}
	}

	&__map-container {
		height: 100%;
		min-height: 300px;

		@include bp($md) {
			min-height: 665px;
		}
	}
}
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);
						observer.unobserve(block);
					}
				});
			}, { threshold: [0.7] });

			io.observe(block);
		};

		this.blocks.forEach(lazyLoadMap);
	}

	initMap(block) {
		if (!window.mapboxgl) {
			console.error('Mapbox GL JS not loaded');
			return;
		}

		const mapContainer = block.querySelector('.block-basic-map__map-container');

		// Create a new token - https://account.mapbox.com/
		mapboxgl.accessToken = 'pk.eyJ1Ijoic3RyYXRlZ2lxIiwiYSI6ImNqc2trb252NzEyZjYzenBvYTRhbmdyNDEifQ.la_5DQo_qJaALM-bp_sc2w';

		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/strategiq/cm6qi73pg010a01r5g5551c8i',
			center: [lng, lat],
			zoom: zoom,
		});

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

// Wait for both DOM and deferred scripts to be ready
document.addEventListener('DOMContentLoaded', () => {
	new BasicMap();
});
{
    "$schema": "https://schemas.wp.org/trunk/block.json",
    "apiVersion": 2,
    "name": "strategiq/basic-map",
    "title": "Basic Map",
    "description": "Example block to be used as a template",
    "category": "strategiq",
    "icon": "strategiq",
    "acf": {
        "mode": "preview",
        "renderTemplate": "block-basic-map.php"
    },
    "supports": {
        "anchor": true,
        "align": false,
        "color": {
            "background": true,
            "text": false,
            "gradients": true
        },
        "spacing": {
            "padding": [
                "top",
                "bottom"
            ],
            "margin": [
                "top",
                "bottom"
            ]
        }
    },
    "example": {
        "attributes": {
            "mode": "preview",
            "data": {
                "heading_type": "h2",
                "heading_text": "Example - Basic Map",
                "content": "This is some example content to represent what the content will look like"
            }
        }
    },
    "style": ["file:../../assets/css/basic-map/block-basic-map.css", "mapbox-styles"],
    "viewScript": ["mapbox-scripts", "basic-map"]
}
This component is not currently used on any pages.
There are is no readme file with this component.