'Satellite', 'fr' => 'Satellite', 'de' => 'Satellit', 'it' => 'Satellitare', 'es' => 'Satélite', 'zh' => '卫星', 'hi' => 'उपग्रह', 'ar' => 'قمر صناعي', 'ja' => '衛星', 'ko' => '위성', 'ru' => 'Спутник' ); // Return translation or fallback to English return $translations[$lang] ?? 'Satellite'; } /** * Handles the shortcode functionality * * @param array $atts Shortcode attributes * @return string Empty string (output is handled via JavaScript) */ public function aotm_shortcode_handler($atts) { // Default shortcode attributes $default_atts = array( 'map-id' => 'map-0', 'satellite' => 'off', 'satellite-button'=> 'on', 'cluster' => 'off', 'cluster-color' => '#ff5b00', 'zoom-level' => '', 'zoom-cluster' => '12', 'labels' => 'off', 'roads' => 'off', 'grayscale' => '0' ); // Merge user attributes with defaults $atts = shortcode_atts($default_atts, $atts, 'aotm-advanced-osm-map'); // Ensure grayscale value is between 0 and 1 $grayscale = max(0, min(1, (float)$atts['grayscale'])); // Prepare settings array for JavaScript $settings = array( 'mapId' => sanitize_text_field($atts['map-id']), 'satelliteLayer' => $atts['satellite'] === 'on' ? 'on' : 'off', 'satelliteButton' => $atts['satellite-button'] === 'off' ? 'off' : 'on', 'markerCluster' => $atts['cluster'] === 'on' ? 'on' : 'off', 'clusterColor' => sanitize_hex_color($atts['cluster-color']), 'zoomLevel' => $atts['zoom-level'] !== '' ? intval($atts['zoom-level']) : null, 'zoomCluster' => intval($atts['zoom-cluster']), 'mapLabels' => $atts['labels'] === 'on' ? 'on' : 'off', 'mapRoads' => $atts['roads'] === 'on' ? 'on' : 'off', 'grayscale' => $grayscale, 'satelliteLabel' => $this->aotm_get_satellite_label_translation() ); // Pass settings to JavaScript with proper escaping wp_add_inline_script( 'aotm-public', 'var aotmSettings_' . esc_js(str_replace('-', '_', $settings['mapId'])) . ' = ' . wp_json_encode($settings) . ';' ); return ''; // Shortcode doesn't output HTML directly } /** * Enqueues all necessary scripts and styles */ public function aotm_enqueue_assets() { // Don't load assets in admin area if (is_admin()) return; // Plugin's custom CSS wp_enqueue_style( 'aotm-public', esc_url(plugin_dir_url(__FILE__) . 'assets/css/public.css'), array(), filemtime(plugin_dir_path(__FILE__) . 'assets/css/public.css') ); // Plugin's main JavaScript wp_enqueue_script( 'aotm-public', esc_url(plugin_dir_url(__FILE__) . 'assets/js/public.js'), array('jquery'), // Depends on jQuery filemtime(plugin_dir_path(__FILE__) . 'assets/js/public.js'), true // Load in footer ); // Register marker clustering library if needed if (!wp_script_is('aotm-leaflet-markercluster', 'registered')) { wp_register_script( 'aotm-leaflet-markercluster', esc_url(plugin_dir_url(__FILE__) . 'leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js'), array('leaflet'), // Depends on Leaflet '1.4.1', true ); wp_register_style( 'aotm-leaflet-markercluster', esc_url(plugin_dir_url(__FILE__) . 'leaflet.markercluster@1.4.1/dist/MarkerCluster.css'), array(), '1.4.1' ); wp_register_style( 'aotm-leaflet-markercluster-default', esc_url(plugin_dir_url(__FILE__) . 'leaflet.markercluster@1.4.1/dist/MarkerCluster.Default.css'), array(), '1.4.1' ); } // Always load Leaflet (required for maps) wp_enqueue_script('leaflet'); wp_enqueue_style('leaflet'); } } new AOTM_Advanced_OSM_Toolset_Maps();