implode(',', $options['post_types'] ?? []), 'taxonomies' => implode(',', $options['filter_taxonomies'] ?? []), 'height' => '600px', 'lat' => $options['default_lat'] ?? '40.4168', 'lng' => $options['default_lng'] ?? '-3.7038', 'zoom' => $options['default_zoom'] ?? 12, 'filters' => 'true', 'detail' => $options['detail_display'] ?? 'sidebar', 'cluster' => $options['cluster_enabled'] ?? true, 'sidebar_position' => $options['sidebar_position'] ?? 'right', 'legend' => isset($options['show_legend']) ? ($options['show_legend'] ? 'true' : 'false') : 'false', 'show_detail_btn' => isset($options['show_detail_button']) ? ($options['show_detail_button'] ? 'true' : 'false') : 'true', 'detail_btn_text' => $options['detail_button_text'] ?? __('Ver detalle', 'fp-geo-content'), 'class' => '', ], $atts, 'fp-geo-map'); // Parsear valores $post_types = array_filter(array_map('trim', explode(',', $atts['post_types']))); $taxonomies = array_filter(array_map('trim', explode(',', $atts['taxonomies']))); $show_filters = filter_var($atts['filters'], FILTER_VALIDATE_BOOLEAN); $use_cluster = filter_var($atts['cluster'], FILTER_VALIDATE_BOOLEAN); $show_legend = filter_var($atts['legend'], FILTER_VALIDATE_BOOLEAN); $show_detail_btn = filter_var($atts['show_detail_btn'], FILTER_VALIDATE_BOOLEAN); $sidebar_position = $atts['sidebar_position']; if (empty($post_types)) { return '
' . __('No se han configurado tipos de contenido para el mapa.', 'fp-geo-content') . '
'; } // Incrementar contador de instancias self::$instance_count++; $map_id = 'fp-geo-map-' . self::$instance_count; // Cargar assets wp_enqueue_style('fp-geo-content'); wp_enqueue_script('fp-geo-content'); // Obtener marcadores $markers = FP_Geo_Data_Provider::get_markers([ 'post_types' => $post_types, ]); // Obtener términos para filtros $filter_terms = []; if ($show_filters && !empty($taxonomies)) { $filter_terms = FP_Geo_Data_Provider::get_filter_terms($post_types, $taxonomies); } // Obtener configuración de tiles $tile_provider = $options['tile_provider'] ?? 'carto_light'; $tile_providers = FP_Geo_Settings::get_tile_providers(); $tile_config = $tile_providers[$tile_provider] ?? $tile_providers['carto_light']; // Obtener icono personalizado si existe $marker_icon_id = $options['marker_icon'] ?? 0; $marker_icon_url = $marker_icon_id ? wp_get_attachment_image_url($marker_icon_id, 'full') : ''; // Obtener etiquetas de los post types $post_type_labels = []; foreach ($post_types as $pt) { $pt_obj = get_post_type_object($pt); if ($pt_obj) { $post_type_labels[$pt] = [ 'singular' => $pt_obj->labels->singular_name, 'plural' => $pt_obj->labels->name, ]; } } // Obtener datos de leyenda si está habilitada $legend_data = []; $legend_taxonomy = $options['legend_taxonomy'] ?? ''; if ($show_legend && !empty($legend_taxonomy) && isset($filter_terms[$legend_taxonomy])) { // Verificar si hay marcadores piloto (es_piloto está en los posts, no en los términos) $has_pilot_markers = false; foreach ($markers as $marker) { if (isset($marker['es_piloto']) && $marker['es_piloto']) { $has_pilot_markers = true; break; } } $legend_data = [ 'taxonomy' => $legend_taxonomy, 'label' => $filter_terms[$legend_taxonomy]['label'], 'items' => $filter_terms[$legend_taxonomy]['terms'], 'has_pilots' => $has_pilot_markers, ]; } // Configuración del mapa $map_config = [ 'mapId' => $map_id, 'center' => [(float) $atts['lat'], (float) $atts['lng']], 'zoom' => (int) $atts['zoom'], 'minZoom' => (int) ($options['min_zoom'] ?? 5), 'maxZoom' => (int) ($options['max_zoom'] ?? 18), 'markers' => $markers, 'filters' => $filter_terms, 'filterCombine' => $options['filter_combine'] ?? 'OR', 'detailDisplay' => $atts['detail'], 'clusterEnabled' => $use_cluster, 'tileUrl' => $tile_config['url'], 'tileAttribution' => $tile_config['attribution'], 'tileSubdomains' => $tile_config['subdomains'], 'defaultIcon' => FP_GEO_PLUGIN_URL . 'assets/img/marker-icon.png', 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('fp_geo_nonce'), 'postTypes' => $post_types, 'postTypeLabels' => $post_type_labels, // Nuevas opciones de marcadores 'markerIcon' => $marker_icon_url, 'markerDefaultColor' => $options['marker_default_color'] ?? '#F97316', 'useCategoryColors' => isset($options['use_category_colors']) && $options['use_category_colors'], 'legendTaxonomy' => $legend_taxonomy, // Nuevas opciones de scroll 'scrollWheelZoom' => $options['scroll_wheel_zoom'] ?? 'ctrl', // Nuevas opciones de display 'sidebarPosition' => $sidebar_position, 'showLegend' => $show_legend, 'legendData' => $legend_data, 'showDetailButton' => $show_detail_btn, 'detailButtonText' => $atts['detail_btn_text'], 'i18n' => [ 'loading' => __('Cargando...', 'fp-geo-content'), 'noResults' => __('No se encontraron resultados', 'fp-geo-content'), 'viewMore' => $atts['detail_btn_text'], 'close' => __('Cerrar', 'fp-geo-content'), 'clearFilters' => __('Limpiar filtros', 'fp-geo-content'), 'scrollZoomHint' => __('Usa Ctrl + scroll para hacer zoom', 'fp-geo-content'), ], ]; // Pasar configuración al JS wp_localize_script('fp-geo-content', 'fpGeoConfig_' . self::$instance_count, $map_config); ob_start(); $wrapper_classes = [ 'fp-geo-wrapper', 'fp-geo-detail-' . esc_attr($atts['detail']), 'fp-geo-sidebar-' . esc_attr($sidebar_position), esc_attr($atts['class']), ]; ?>