*/ namespace RankMathPro\Local_Seo; use RankMath\Schema\DB; defined( 'ABSPATH' ) || exit; /** * Map class. */ class Map { /** * Shortcode Instance. * * @var Location_Shortcode */ public $shortcode; /** * Get Address Data. * * @param Location_Shortcode $shortcode Location_Shortcode Instance. * @param array $locations Locations data. * @return string */ public function get_data( $shortcode, $locations ) { $this->shortcode = $shortcode; $atts = $shortcode->atts; $options = [ 'map_style' => $atts['map_style'], 'allow_zoom' => $atts['allow_zoom'], 'zoom_level' => $atts['zoom_level'], 'allow_dragging' => $atts['allow_dragging'], 'show_clustering' => $atts['show_marker_clustering'], 'show_infowindow' => $atts['show_infowindow'], ]; $terms_data = []; foreach ( $locations as $location ) { $schema = DB::get_schemas( $location->ID ); if ( empty( $schema ) ) { continue; } $schema = current( $shortcode->replace_variables( $schema ) ); if ( empty( $schema['geo']['latitude'] ) || empty( $schema['geo']['longitude'] ) ) { continue; } $options['locations'][ $location->ID ] = [ 'content' => $this->get_infobox_content( $location->ID, $schema ), 'lat' => $schema['geo']['latitude'], 'lng' => $schema['geo']['longitude'], ]; if ( ! empty( $atts['show_category_filter'] ) && 'map' === $atts['type'] ) { $terms = get_the_terms( $location->ID, 'rank_math_location_category' ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { $terms_data = array_merge( $terms_data, $terms ); $options['locations'][ $location->ID ]['terms'] = wp_list_pluck( $terms, 'term_id' ); } } } if ( empty( $options['locations'] ) ) { return; } wp_enqueue_script( 'rank-math-local' ); $width = ! empty( $atts['map_width'] ) ? $atts['map_width'] : '100%'; $height = ! empty( $atts['map_height'] ) ? $atts['map_height'] : '500px'; $style = sprintf( 'style="width: %s; height: %s"', $width, $height ); ob_start(); ?>
' . $this->shortcode->address->get_data( $this->shortcode, $schema ) . '
'; } }