added leaflet map functions to be used in theme

This commit is contained in:
jorge 2024-03-28 22:09:20 +01:00
parent 5bb4472ce2
commit 630b2da38b
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,68 @@
<?php
/**
*
* functions to displaying the map with all members
* depens on plugins: LeafletMaps, ACF fields
*
*
* @link https://xarxaprod.cat
* @since 1.0.0
* @package xarxaprod-wp-plugin
* @subpackage xarxaprod-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*
*/
// Detect plugin. For use on Front End only.
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// check for plugin using plugin name
if ( ! is_plugin_active( 'leaflet-map/leaflet-map.php' ) ) {
echo '<p class="warning">The plugin <a hfref="https://wordpress.org/plugins/leaflet-map/">LeafletMap</a> is needed to show this map</p>';
} else {
if (! function_exists( 'xarxaprod_show_leaflet_map' )) {
function xarxaprod_show_leaflet_map() {
// show the map
echo do_shortcode( '[leaflet-map fitbounds lat="41.3922" lng="2.1755" height="100%" width="100%" tileurl=https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png scrollwheel detect-retina]');
}
};
if ( ! is_plugin_active( 'acf-openstreetmap-field/index.php' ) ) {
echo '<p class="warning">The plugin <a hfref="https://wordpress.org/plugins/acf-openstreetmap-field/">ACF OpenStreetMap Field</a> is needed to show the points in the map</p>';
} else {
if (! function_exists( 'xarxaprod_show_leaflet_associat_blob' )) {
function xarxaprod_show_leaflet_associat_blob() {
// get the field values
// https://www.advancedcustomfields.com/resources/get_field/
// var_dump get_field('');
$args = get_field('xxp_associat_osm_map',false, false);
if ( count( $args['markers'] ) ) {
foreach ( $args['markers'] as $marker ) {
// define the fields for the blob
if ( get_field('xxp_associat_citymap') ){
// if city for map written use it
$associat_address = get_field('xxp_associat_citymap');
} else {
// else use the ACF OpenStreetMap nominatim value
$associat_address = $marker['label'];
};
$associat_xxp_weblink = '<a href="'. get_the_permalink() . '">' . get_the_title() . '</a>';
$associat_own_weblink = '<a href="' . get_field('xxp_associat_web') . '" class="">' . get_field('xxp_associat_web') . '</a>';
$associat_email = '<a href="mailto:' . get_field('xxp_associat_mail') . '" class="">' . get_field('xxp_associat_mail') . '</a>';
$associat_lat = $marker['lat'];
$associat_lng = $marker['lng'];
$associat_blobcolor = get_field('xxp_associat_colormap');
echo do_shortcode( '
[leaflet-marker svg background="#555" color="#555" iconSize="17,19" iconClass="dashicons dashicons-marker" opacity="0.6" lat=' . $associat_lat . ' lng=' . $associat_lng . ']'
. '<p>' . $associat_address . '</p>'
. '<h5><b>' . $associat_xxp_weblink . '</b></h5>'
. '<p>' . $associat_own_weblink . '</p>'
. '<p>' . $associat_email . '</p>'
. '[/leaflet-marker]'
); // end shortcode each marker
}; // end each marker
}; // end count all markers
};
}; //end function xarxaprod_show_leaflet_associat_blob
};//end ACF OpenStreetMap active
};

View File

@ -84,3 +84,6 @@ include( XARXAPROD_WPPLUGIN_PATH . 'includes/custom-field-associats-filter-funct
// plugin js scripts // plugin js scripts
include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php'); include( XARXAPROD_WPPLUGIN_PATH . 'includes/register-plugin-scripts.php');
// include leaflet map shortcodes
include( XARXAPROD_WPPLUGIN_PATH . 'includes/xarxaprod-leafletmap.php');