Gists

6 months ago
<?php

// Add to your (child) theme's functions.php
// Note that this is untested, and may have side effects!

add_filter( 'facetwp_map_marker_args', function( $args, $post_id ) {
    if ( ! isset( FWP()->map_locations ) ) {
        FWP()->map_locations = [];
    }

    // generate the hash for checking duplicates
    $hash = $args['position']['lat'] . ':' . $args['position']['lng'];

    // skip if this exact location has already been used
    if ( isset( FWP()->map_locations[ $hash ] ) ) {
        return false;
    }

    FWP()->map_locations[ $hash ] = true;
    return $args;
}, 10, 2 );
4 months ago
<?php

// Add to your (child) theme's functions.php
// Prevent marker clustering from a specific zoom level and up
// https://facetwp.com/help-center/facets/facet-types/map/#set-the-maximum-zoom-level-for-a-cluster-to-appear

add_filter( 'facetwp_map_init_args', function( $settings ) {
    if ( isset( $settings['config']['cluster'] ) ) {
        $settings['config']['cluster']['maxZoom'] = 10; // default: 15. Level must be between 1 and 20.
    }
    return $settings;
});
3 months ago
<?php

// Add to your (child) theme's functions.php
// For more examples and explanation, see: 
// https://facetwp.com/help-center/facets/facet-types/map/#set-custom-marker-cluster-images

add_filter( 'facetwp_map_init_args', function( $settings ) {

  $clustericonsizes = array( 53, 56, 66, 78, 90 );  // specify icon image sizes. These are the default values.
  for ( $i = 1; $i <= 5; $i ++ ) {
    $settings['config']['cluster']['styles'][] = [
      'url'       => FACETWP_MAP_URL . '/assets/img/m' . $i . '.png', // directory, required. This is the default directory.
      'width'     => $clustericonsizes[ $i - 1 ], // required
      'height'    => $clustericonsizes[ $i - 1 ], // required
      'textColor' => '#ffffff', // white, optional
      'textSize'  => 16 // 16px, optional
    ];
  }

  return $settings;
} );
2 years ago
add_action( 'wp_head', function() {
    ?>
    <script>
    (function($) {
        $(function() {
            if ( 'undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
                FWP.hooks.addFilter('facetwp_map/fit_bounds', function( fit_bounds ) {
                    if ( FWP.loaded ) {
                        return fit_bounds;
                    } else {
                        return false;
                    }
                });
            }
        });
    })(jQuery);
    </script>
    <?php
}, 100);
4 months ago
<?php

// Add to your (child) theme's functions.php

// To be able to set a custom default center (lat / lng) and/or zoom level in the Map facet's settings, the Google maps fitBounds function needs to be turne off.
// See: https://facetwp.com/help-center/facets/facet-types/map/#set-a-custom-zoom-level-or-location-center

// There are 2 options (add only one to your site):

// 1. Only on initial page load

add_action( 'wp_head', function() {
  ?>
    <script>
      document.addEventListener('DOMContentLoaded', function() {
        if ('undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
          FWP.hooks.addFilter('facetwp_map/fit_bounds', function(fit_bounds) {
            return FWP.loaded; // force the custom lat/lng/zoom only on initial page load
          });
        }
      });
    </script>
  <?php
}, 100 );


// 2. On every page load and facet refresh:

add_action( 'wp_head', function() {
  ?>
    <script>
      document.addEventListener('facetwp-refresh', function() {
        if ('undefined' !== typeof FWP && 'undefined' !== typeof FWP.hooks) {
          FWP.hooks.addFilter('facetwp_map/fit_bounds', function(fit_bounds) {
            return false; // force the custom lat/lng/zoom on every refresh
          });
        }
      });
    </script>
  <?php
}, 100 );
2 years ago
<?php

/**
 * This assumes a "gmaps" folder within your theme
 * Within that folder, add m1.png, m2.png, m3.png, m4.png, m5.png
 */
add_filter( 'facetwp_map_init_args', function( $settings ) {
    $settings['imagePath'] = get_bloginfo( 'stylesheet_directory' ) . '/gmaps/m';
    return $settings;
});
2 years ago
<?php
/** hook to add JS on opening map markers **/
add_action( 'wp_footer', function() { ?>
    <script>
    (function($) {
        if ('object' !== typeof FWP) {
                return;
        }
        
        $(function() {
            FWP.hooks.addAction('facetwp_map/marker/click', function( marker ) {
                // do stuff here
            });
        });
    })(jQuery)
    </script>
<?php }, 100 );
3 years ago
<?php

// add this to your child themes functions.php file

add_filter( 'facetwp_map_init_args', function ( $args ) {
	$args['init']['scrollwheel'] = true;
	return $args;
} );
3 years ago
<?php

add_filter( 'facetwp_map_init_args', function( $settings ) {
    $styles = '[{"featureType":"water","elementType":"geometry","stylers":[{"color":"#193341"}]},{"featureType":"landscape","elementType":"geometry","stylers":[{"color":"#2c5a71"}]},{"featureType":"road","elementType":"geometry","stylers":[{"color":"#29768a"},{"lightness":-37}]},{"featureType":"poi","elementType":"geometry","stylers":[{"color":"#406d80"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"color":"#406d80"}]},{"elementType":"labels.text.stroke","stylers":[{"visibility":"on"},{"color":"#3e606f"},{"weight":2},{"gamma":0.84}]},{"elementType":"labels.text.fill","stylers":[{"color":"#ffffff"}]},{"featureType":"administrative","elementType":"geometry","stylers":[{"weight":0.6},{"color":"#1a3541"}]},{"elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"poi.park","elementType":"geometry","stylers":[{"color":"#2c5a71"}]}]';
    $settings['init']['styles'] = json_decode( $styles );
    return $settings;
});
3 years ago
<?php
/**
 * redirect to permalink on click of info marker instead of opening info window
 * Use the_permalink as the only content of your map facet marker content setting
 * https://d.pr/i/TTb4XW
 */
add_action( 'wp_footer', function() { ?>
    <style>
    .gm-style .gm-style-iw-a {display: none;}
    </style>
    <script>
    (function($) {
        if ('object' !== typeof FWP) {
                return;
        }
        $(function() {
            FWP.hooks.addAction('facetwp_map/marker/click', function( marker ) {
                window.location.href = marker.content;
            });
        });
    })(jQuery)
    </script>
<?php }, 100 );