| 1 |
<?php |
| 2 |
/** |
| 3 |
* The template for Element Listings Results Map. |
| 4 |
* This is the template that elementor element map with markers of listings, show results |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
?> |
| 13 |
<div class="wdk-element" id="wdk_el_<?php echo esc_html($id_element);?>"> |
| 14 |
<div class="wdk-map" class="wdk_map_results"> |
| 15 |
<div id="wdk_map_results_<?php echo esc_html($id_element);?>" style="height:<?php echo esc_attr($settings['conf_custom_map_height']['size']);?>px" class="wdk_map_results <?php echo wmvc_show_data('styles_thmbn_des_type',$settings, '');?> " ></div> |
| 16 |
</div> |
| 17 |
</div> |
| 18 |
<?php |
| 19 |
$zoom_index = $settings['conf_custom_map_zoom_index']['size']; |
| 20 |
?> |
| 21 |
<?php |
| 22 |
if($lat == 0) |
| 23 |
{ |
| 24 |
$lat = wmvc_show_data('conf_custom_map_center_gps_lat', $settings); |
| 25 |
$lng = wmvc_show_data('conf_custom_map_center_gps_lng', $settings); |
| 26 |
} |
| 27 |
?> |
| 28 |
<?php |
| 29 |
$WMVC = &wdk_get_instance(); |
| 30 |
$WMVC->model('category_m'); |
| 31 |
if (!$is_edit_mode) |
| 32 |
ob_start(); |
| 33 |
?> |
| 34 |
<script> |
| 35 |
var wdk_map =''; |
| 36 |
var wdk_markers = []; |
| 37 |
var wdk_clusters =''; |
| 38 |
var wdk_jpopup_customOptions = |
| 39 |
{ |
| 40 |
'maxWidth': 'initial', |
| 41 |
'width': 'initial', |
| 42 |
'className' : 'popupCustom' |
| 43 |
}; |
| 44 |
jQuery(document).ready(function($) { |
| 45 |
if(wdk_clusters=='') |
| 46 |
wdk_clusters = L.markerClusterGroup({spiderfyOnMaxZoom: true, showCoverageOnHover: false, zoomToBoundsOnClick: true}); |
| 47 |
wdk_map = L.map('wdk_map_results_<?php echo esc_html($id_element);?>', { |
| 48 |
center: ["<?php echo esc_js($lat);?>","<?php echo esc_js($lng);?>"], |
| 49 |
zoom: "<?php echo esc_js($zoom_index);?>", |
| 50 |
scrollWheelZoom: false, |
| 51 |
<?php if($settings['conf_custom_dragging'] == 'yes'):?> |
| 52 |
dragging: true, |
| 53 |
<?php else:?> |
| 54 |
dragging: false, |
| 55 |
<?php endif;?> |
| 56 |
tap: !L.Browser.mobile, |
| 57 |
fullscreenControl: true, |
| 58 |
fullscreenControlOptions: { |
| 59 |
position: 'topleft' |
| 60 |
} |
| 61 |
}); |
| 62 |
|
| 63 |
|
| 64 |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
| 65 |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
| 66 |
}).addTo(wdk_map); |
| 67 |
|
| 68 |
<?php if(!empty($settings['conf_custom_map_style']) && $settings['conf_custom_map_style'] =='custom' && !empty($settings['conf_custom_map_style_self'])):?> |
| 69 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style_self']);?>').addTo(wdk_map); |
| 70 |
<?php elseif(!empty($settings['conf_custom_map_style']) && $settings['conf_custom_map_style'] !='custom'):?> |
| 71 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style']);?>').addTo(wdk_map); |
| 72 |
<?php endif;?> |
| 73 |
var auto_marker_size = false; |
| 74 |
<?php foreach($results as $key=>$listing): ?> |
| 75 |
<?php if(!is_numeric(wmvc_show_data('lng', $listing)))continue;?> |
| 76 |
<?php |
| 77 |
$pin_icon = ""; |
| 78 |
$font_class = ""; |
| 79 |
$font_class = ""; |
| 80 |
$font_icon = $this->generate_icon($settings['conf_custom_map_pin_icon']); |
| 81 |
$pin_icon = $settings['conf_custom_map_pin']['url']; |
| 82 |
|
| 83 |
if(!empty(wmvc_show_data('category_id', $listing))){ |
| 84 |
$category = $WMVC->category_m->get_data(wmvc_show_data('category_id', $listing)); |
| 85 |
if(wmvc_show_data('marker_image_id', $category, false, TRUE, TRUE)){ |
| 86 |
$pin_icon = wdk_image_src($category, 'full', NULL,'marker_image_id'); |
| 87 |
} else if(!empty(wmvc_show_data('font_icon_code', $category))) { |
| 88 |
$font_class = wmvc_show_data('font_icon_code', $category); |
| 89 |
} |
| 90 |
} else { |
| 91 |
$font_class = ""; |
| 92 |
$font_icon = ""; |
| 93 |
} |
| 94 |
?> |
| 95 |
<?php if(!empty($settings['custom_marker_fields']) && substr($this->data['settings']['custom_marker_fields'], strpos($this->data['settings']['custom_marker_fields'],'__')+2) == 'first_image'):?> |
| 96 |
auto_marker_size = true; |
| 97 |
var innerMarker = '<div class="wdk_marker-container wdk_marker_label wdk_marker_clear category_id_<?php echo esc_js(wmvc_show_data('category_id', $listing));?>"><img src="<?php echo esc_js(wdk_image_src($listing));?>"></img></div>'; |
| 98 |
|
| 99 |
<?php elseif(!empty($settings['custom_marker_fields']) && wdk_field_value (substr($this->data['settings']['custom_marker_fields'], strpos($this->data['settings']['custom_marker_fields'],'__')+2), $listing)):?> |
| 100 |
<?php |
| 101 |
$field_id = substr($this->data['settings']['custom_marker_fields'], strpos($this->data['settings']['custom_marker_fields'],'__')+2); |
| 102 |
|
| 103 |
$field_value = ''; |
| 104 |
$field_value .= apply_filters( 'wpdirectorykit/listing/field/prefix', wdk_field_option ($field_id, 'prefix'), $field_id); |
| 105 |
|
| 106 |
/* if price field use like 1l */ |
| 107 |
if(wdk_field_option($field_id, 'is_price_format')) { |
| 108 |
|
| 109 |
$value = wdk_field_value($field_id, $listing); |
| 110 |
if($value>=1000) { |
| 111 |
$value = apply_filters( 'wpdirectorykit/listing/field/value', number_format_i18n(wdk_filter_decimal($value/1000)), $field_id).'k'; |
| 112 |
} else { |
| 113 |
$value = apply_filters( 'wpdirectorykit/listing/field/value', wdk_field_value_on_type($field_id, $listing), $field_id); |
| 114 |
} |
| 115 |
|
| 116 |
$field_value = $value; |
| 117 |
|
| 118 |
} else { |
| 119 |
$field_value .= apply_filters( 'wpdirectorykit/listing/field/value', wdk_field_value_on_type($field_id, $listing), $field_id); |
| 120 |
} |
| 121 |
|
| 122 |
$field_value .= apply_filters( 'wpdirectorykit/listing/field/suffix',wdk_field_option ($field_id, 'suffix'), $field_id); |
| 123 |
?> |
| 124 |
auto_marker_size = true; |
| 125 |
var innerMarker = '<div class="wdk_marker-container wdk_marker_label category_id_<?php echo esc_js(wmvc_show_data('category_id', $listing));?>"><?php echo esc_js(strip_tags($field_value));?></div>'; |
| 126 |
<?php elseif($pin_icon):?> |
| 127 |
var image = '<?php echo esc_html($pin_icon);?>'; var innerMarker = '<div class="wdk_marker-container wdk_marker-container-image"><img src='+image+'></img></div>'; |
| 128 |
<?php elseif($font_icon && empty($font_class)):?> |
| 129 |
var innerMarker = '<div class="wdk_marker-container category_id_<?php echo esc_js(wmvc_show_data('category_id', $listing));?>"><div class="front wdk_face"><?php echo wdk_viewe($font_icon);?></div><div class="wdk_marker-card"><div class="wdk_marker-arrow"></div></div></div>'; |
| 130 |
<?php else:?> |
| 131 |
var innerMarker = '<div class="wdk_marker-container category_id_<?php echo esc_js(wmvc_show_data('category_id', $listing));?>"><div class="front wdk_face"><i class="<?php echo esc_html($font_class);?>"></i></div><div class="wdk_marker-card"><div class="wdk_marker-arrow"></div></div></div>'; |
| 132 |
<?php endif;?> |
| 133 |
wdk_markers.push(wdk_generate_marker_ajax_popup('<?php echo esc_url(admin_url('admin-ajax.php'));?>','<?php echo esc_html(wmvc_show_data('post_id', $listing));?>','<?php echo esc_html(wmvc_show_data('lat', $listing));?>','<?php echo esc_html(wmvc_show_data('lng', $listing));?>',innerMarker, wdk_jpopup_customOptions, auto_marker_size |
| 134 |
, <?php if(wmvc_show_data('disable_cluster', $settings) == 'yes'):?> false <?php endif;?>)); |
| 135 |
<?php endforeach; ?> |
| 136 |
wdk_map.addLayer(wdk_clusters); |
| 137 |
/* set center */ |
| 138 |
if(wdk_markers.length){ |
| 139 |
var limits_center = []; |
| 140 |
for (var i in wdk_markers) { |
| 141 |
var latLngs = [ wdk_markers[i].getLatLng() ]; |
| 142 |
limits_center.push(latLngs) |
| 143 |
}; |
| 144 |
var bounds = L.latLngBounds(limits_center); |
| 145 |
<?php if(wdk_get_option('wdk_fixed_map_results_position') && wdk_get_option('wdk_default_lat') && wdk_get_option('wdk_default_lng')): ?> |
| 146 |
wdk_map.setView(["<?php echo esc_js(wdk_get_option('wdk_default_lat'));?>","<?php echo esc_js(wdk_get_option('wdk_default_lng'));?>"]); |
| 147 |
<?php elseif($settings['enable_custom_gps_center'] == 'yes'): ?> |
| 148 |
wdk_map.setView(["<?php echo esc_js($settings['conf_custom_map_center_gps_lat']);?>","<?php echo esc_js($settings['conf_custom_map_center_gps_lng']);?>"]); |
| 149 |
<?php else: ?> |
| 150 |
wdk_map.fitBounds(bounds); |
| 151 |
<?php endif; ?> |
| 152 |
} |
| 153 |
}) |
| 154 |
</script> |
| 155 |
<?php |
| 156 |
|
| 157 |
if (!$is_edit_mode) { |
| 158 |
$js_content = ob_get_clean(); |
| 159 |
$js_content = str_replace(array('</script>','<script>'),'',$js_content ); |
| 160 |
wp_add_inline_script( 'wdk-elementor-main', $js_content ); |
| 161 |
} |
| 162 |
?> |
| 163 |
|
| 164 |
|