(function( $ ) { 'use strict'; var popup; var map; function initializeMap() { map = new maplibregl.Map({ container: 'map', style: { 'version': 8, "glyphs": "https://fonts.openmaptiles.org/{fontstack}/{range}.pbf", 'sources': { 'raster-tiles': { 'type': 'raster', 'tiles': [ 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png' ], 'tileSize': 256, 'attribution': '© OpenStreetMap contributors' } }, 'layers': [ { 'id': 'simple-tiles', 'type': 'raster', 'source': 'raster-tiles', 'minzoom': 0, 'maxzoom': 22 } ] }, center: [0, 0], zoom: 2 }); setPopup() setEventListeners() map.on('load', () => { map.resize(); }) } function setPopup() { if(popup) { popup.remove(); } var css = getCSS(); var html = getHTML(); var layout = getLayout(); var style = ` .mapboxgl-popup .mapboxgl-popup-content, .maplibregl-popup .maplibregl-popup-content { padding: 0px; background: none; border: none; border-radius: none; box-shadow: none; } #mapster-popup.map-popup-background { background : ${css.background}; text-align : ${css.align}; border-radius: 3px; box-shadow: 0 1px 2px rgb(0 0 0 / 10%); } #mapster-popup .map-popup-header { background : ${css.header}; padding: 10px; } #mapster-popup .map-popup-header h2 { all : revert; color : ${css.header_text}; font-weight: bold; margin: 0; padding: 0; } #mapster-popup .map-popup-image { background-image : url(https://via.placeholder.com/150x50); background-position : center center; background-size: cover; height : ${css.image_height}px; width: 100%; } #mapster-popup .map-popup-body { margin-top: -1px; background : ${css.body}; padding: 10px; color : ${css.body_text}; } #mapster-popup .map-popup-body p { padding: 0px; margin: 0px; } #mapster-popup .map-popup-footer { margin-top: -1px; background : ${css.footer}; padding: 10px; } #mapster-popup .map-popup-footer .map-popup-footer-button { all : revert; background : ${css.button}; border-color: ${css.button}; color : ${css.button_text}; padding: 5px; text-decoration: none; text-shadow: none; } #mapster-popup .map-popup-footer .map-popup-footer-button:hover { cursor: pointer; filter: brightness(1.15); } .mapboxgl-popup.mapboxgl-popup-anchor-top .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip, .mapboxgl-popup.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-top-left .maplibregl-popup-tip, .mapboxgl-popup.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-top-right .maplibregl-popup-tip { border-bottom-color : ${css.pointer}; display : ${layout.enable_pointer ? 'block' : 'none'}; } .mapboxgl-popup.mapboxgl-popup-anchor-right .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color : ${css.pointer}; display : ${layout.enable_pointer ? 'block' : 'none'}; } .mapboxgl-popup.mapboxgl-popup-anchor-left .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color : ${css.pointer}; display : ${layout.enable_pointer ? 'block' : 'none'}; } .mapboxgl-popup.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip, .mapboxgl-popup.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-bottom-left .maplibregl-popup-tip, .mapboxgl-popup.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip, .maplibregl-popup.maplibregl-popup-anchor-bottom-right .maplibregl-popup-tip { border-top-color : ${css.pointer}; display : ${layout.enable_pointer ? 'block' : 'none'}; } `; setCustomCSS(style); var defaultValues = getDefaultValues(); var content = getContent(); popup = new maplibregl.Popup({ closeButton : defaultValues.close_button, maxWidth : defaultValues.max_width, closeOnClick : defaultValues.close_on_click, closeOnMove : defaultValues.close_on_map_move, focusAfterOpen : false }) .setLngLat(map.getCenter()) .setHTML(` ${layout.use_custom_css ? `` : ''} ${layout.use_custom_html ? replaceHTMLValues(html.html_editor, content) : `
${content.content_preview}