| 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 |
|
| 14 |
<div class="wdk-element" id="wdk_el_<?php echo esc_html($id_element);?>"> |
| 15 |
<div class="wdk-map" class="wdk_map_results"> |
| 16 |
<?php if($settings['conf_custom_dragging_mobile'] == 'yes'):?> <div class="map-hint"><?php echo esc_html__( 'Require 2 finger for map movement', 'wpdirectorykit' );?></div><?php endif;?> |
| 17 |
<div id="wdk_map_results_<?php echo esc_html($id_element);?>" style="height:<?php echo esc_attr($settings['conf_custom_map_height']['size']);?>px" |
| 18 |
data-el_id="<?php echo esc_attr($this->get_id());?>" |
| 19 |
data-el_type="<?php echo esc_attr($this->get_name());?>" |
| 20 |
<?php |
| 21 |
$post_id = get_the_ID(); |
| 22 |
$post_object_id = get_queried_object_id(); |
| 23 |
if($post_object_id) |
| 24 |
$post_id = $post_object_id; |
| 25 |
|
| 26 |
global $wdk_listing_page_id; |
| 27 |
if(!empty($wdk_listing_page_id)) |
| 28 |
$post_id = $wdk_listing_page_id; |
| 29 |
?> |
| 30 |
data-el_page_id="<?php echo esc_attr($post_id);?>" |
| 31 |
|
| 32 |
class="wdk_map_results <?php echo wmvc_show_data('styles_thmbn_des_type',$settings, '');?> |
| 33 |
<?php if |
| 34 |
( |
| 35 |
wdk_get_option('wdk_experimental_features') && wdk_get_option('wdk_experimental_ajax_results') && |
| 36 |
isset($settings['is_ajax_enable']) && $settings['is_ajax_enable'] == 'yes' |
| 37 |
):?> |
| 38 |
ajax_results_enabled |
| 39 |
<?php endif;?> |
| 40 |
" > |
| 41 |
</div> |
| 42 |
</div> |
| 43 |
</div> |
| 44 |
<?php |
| 45 |
$zoom_index = $settings['conf_custom_map_zoom_index']['size']; |
| 46 |
?> |
| 47 |
<?php |
| 48 |
if($lat == 0) |
| 49 |
{ |
| 50 |
$lat = wmvc_show_data('conf_custom_map_center_gps_lat', $settings); |
| 51 |
$lng = wmvc_show_data('conf_custom_map_center_gps_lng', $settings); |
| 52 |
} |
| 53 |
?> |
| 54 |
<?php |
| 55 |
$WMVC = &wdk_get_instance(); |
| 56 |
$WMVC->model('category_m'); |
| 57 |
if (!$is_edit_mode) |
| 58 |
ob_start(); |
| 59 |
?> |
| 60 |
<script> |
| 61 |
var wdk_map =''; |
| 62 |
var wdk_markers = []; |
| 63 |
var wdk_clusters =''; |
| 64 |
var wdk_jpopup_customOptions = |
| 65 |
{ |
| 66 |
'maxWidth': 'initial', |
| 67 |
'width': 'initial', |
| 68 |
'className' : 'popupCustom' |
| 69 |
}; |
| 70 |
jQuery(document).ready(function($) { |
| 71 |
if(wdk_clusters=='') |
| 72 |
wdk_clusters = L.markerClusterGroup({spiderfyOnMaxZoom: true, showCoverageOnHover: false, zoomToBoundsOnClick: true}); |
| 73 |
wdk_map = L.map('wdk_map_results_<?php echo esc_html($id_element);?>', { |
| 74 |
center: ["<?php echo esc_js($lat);?>","<?php echo esc_js($lng);?>"], |
| 75 |
zoom: "<?php echo esc_js($zoom_index);?>", |
| 76 |
scrollWheelZoom: false, |
| 77 |
dragging: ((!L.Browser.mobile) ? <?php if($settings['conf_custom_dragging'] == 'yes'):?> true <?php else:?> else <?php endif;?> : <?php if($settings['conf_custom_dragging_mobile'] == 'yes'):?> true <?php else:?> false <?php endif;?>), |
| 78 |
tap: !L.Browser.mobile, |
| 79 |
fullscreenControl: true, |
| 80 |
fullscreenControlOptions: { |
| 81 |
position: 'topleft' |
| 82 |
}, |
| 83 |
}); |
| 84 |
|
| 85 |
|
| 86 |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
| 87 |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
| 88 |
}).addTo(wdk_map); |
| 89 |
|
| 90 |
let drawMap = wdk_map_draw(wdk_map); |
| 91 |
|
| 92 |
// define rectangle geographical bounds |
| 93 |
<?php if(isset($_GET['rectangle_ne']) && isset($_GET['rectangle_sw'])) :?> |
| 94 |
<?php if(wdk_is_gps($_GET['rectangle_ne']) && wdk_is_gps($_GET['rectangle_sw'])) :?> |
| 95 |
var bounds = [[<?php echo isset($_GET['rectangle_ne']) ? esc_attr(sanitize_text_field($_GET['rectangle_ne'])) : '';?>], [<?php echo isset($_GET['rectangle_sw']) ? esc_attr(sanitize_text_field($_GET['rectangle_sw'])) : '';?>]]; |
| 96 |
drawMap.setRectangle(L.rectangle(bounds, {color: "#ff7800", weight: 1})); |
| 97 |
<?php endif;?> |
| 98 |
<?php endif;?> |
| 99 |
|
| 100 |
<?php if(!empty($settings['conf_custom_map_style']) && $settings['conf_custom_map_style'] =='custom' && !empty($settings['conf_custom_map_style_self'])):?> |
| 101 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style_self']);?>').addTo(wdk_map); |
| 102 |
<?php elseif(!empty($settings['conf_custom_map_style']) && $settings['conf_custom_map_style'] !='custom'):?> |
| 103 |
<?php if($settings['conf_custom_map_style']=='google_map'):?> |
| 104 |
<?php |
| 105 |
wp_enqueue_script('google-map-api', 'https://maps.googleapis.com/maps/api/js?key='.wmvc_show_data('google_map_key', $settings, '')); |
| 106 |
?> |
| 107 |
var roadMutant = L.gridLayer |
| 108 |
.googleMutant({ |
| 109 |
type: "roadmap", |
| 110 |
}); |
| 111 |
|
| 112 |
var satMutant = L.gridLayer.googleMutant({ |
| 113 |
type: "satellite", |
| 114 |
}); |
| 115 |
|
| 116 |
var terrainMutant = L.gridLayer.googleMutant({ |
| 117 |
type: "terrain", |
| 118 |
}); |
| 119 |
|
| 120 |
var hybridMutant = L.gridLayer.googleMutant({ |
| 121 |
type: "hybrid", |
| 122 |
}); |
| 123 |
|
| 124 |
var styleMutant = L.gridLayer.googleMutant({ |
| 125 |
styles: [ |
| 126 |
{ elementType: "labels", stylers: [{ visibility: "off" }] }, |
| 127 |
{ featureType: "water", stylers: [{ color: "#444444" }] }, |
| 128 |
{ featureType: "landscape", stylers: [{ color: "#eeeeee" }] }, |
| 129 |
{ featureType: "road", stylers: [{ visibility: "off" }] }, |
| 130 |
{ featureType: "poi", stylers: [{ visibility: "off" }] }, |
| 131 |
{ featureType: "transit", stylers: [{ visibility: "off" }] }, |
| 132 |
{ featureType: "administrative", stylers: [{ visibility: "off" }] }, |
| 133 |
{ |
| 134 |
featureType: "administrative.locality", |
| 135 |
stylers: [{ visibility: "off" }], |
| 136 |
}, |
| 137 |
], |
| 138 |
maxZoom: 24, |
| 139 |
type: "roadmap", |
| 140 |
}); |
| 141 |
|
| 142 |
var trafficMutant = L.gridLayer.googleMutant({ |
| 143 |
type: "roadmap", |
| 144 |
}); |
| 145 |
trafficMutant.addGoogleLayer("TrafficLayer"); |
| 146 |
|
| 147 |
var transitMutant = L.gridLayer.googleMutant({ |
| 148 |
type: "roadmap", |
| 149 |
}); |
| 150 |
|
| 151 |
var satelliteMutant = L.gridLayer.googleMutant({ |
| 152 |
type: "satellite", |
| 153 |
}); |
| 154 |
transitMutant.addGoogleLayer("TransitLayer"); |
| 155 |
|
| 156 |
var google_map_style = roadMutant; |
| 157 |
<?php switch (wmvc_show_data('google_map_default_type', $settings, 'roadMutant')){ |
| 158 |
case 'roadmap': |
| 159 |
echo 'google_map_style=roadMutant'; |
| 160 |
break; |
| 161 |
case 'aerial': |
| 162 |
echo 'google_map_style=satMutant'; |
| 163 |
break; |
| 164 |
case 'terrain': |
| 165 |
echo 'google_map_style=terrainMutant'; |
| 166 |
break; |
| 167 |
case 'hybrid': |
| 168 |
echo 'google_map_style=hybridMutant'; |
| 169 |
break; |
| 170 |
case 'satellite': |
| 171 |
echo 'google_map_style=satelliteMutant'; |
| 172 |
break; |
| 173 |
case 'styles': |
| 174 |
echo 'google_map_style=styleMutant'; |
| 175 |
break; |
| 176 |
case 'traffic': |
| 177 |
echo 'google_map_style=trafficMutant'; |
| 178 |
break; |
| 179 |
case 'transit': |
| 180 |
echo 'google_map_style=transitMutant'; |
| 181 |
break; |
| 182 |
} |
| 183 |
?> |
| 184 |
|
| 185 |
google_map_style.addTo(wdk_map); |
| 186 |
L.control.layers( |
| 187 |
{ |
| 188 |
Roadmap: roadMutant, |
| 189 |
Aerial: satMutant, |
| 190 |
Terrain: terrainMutant, |
| 191 |
Hybrid: hybridMutant, |
| 192 |
Satellite: satelliteMutant, |
| 193 |
Traffic: trafficMutant, |
| 194 |
Transit: transitMutant, |
| 195 |
} |
| 196 |
).addTo(wdk_map); |
| 197 |
|
| 198 |
<?php elseif(in_array($settings['conf_custom_map_style'], array( |
| 199 |
'https://{s}.tile.thunderforest.com/mobile-atlas/{z}/{x}/{y}.png', |
| 200 |
'https://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png', |
| 201 |
'https://{s}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png', |
| 202 |
'https://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png', |
| 203 |
'https://{s}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png', |
| 204 |
'https://{s}.tile.thunderforest.com/pioneer/{z}/{x}/{y}.png', |
| 205 |
'https://{s}.tile.thunderforest.com/neighbourhood/{z}/{x}/{y}.png', |
| 206 |
))):?> |
| 207 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style']);?><?php echo (wmvc_show_data('thunderforest_map_key', $settings, false)) ? '?apikey='.esc_js(wmvc_show_data('thunderforest_map_key', $settings)) : '';?>').addTo(wdk_map); |
| 208 |
<?php elseif(in_array($settings['conf_custom_map_style'], array( |
| 209 |
'https://{s}.tile.jawg.io/jawg-terrain/{z}/{x}/{y}{r}.png', |
| 210 |
'https://{s}.tile.jawg.io/jawg-streets/{z}/{x}/{y}{r}.png', |
| 211 |
'https://{s}.tile.jawg.io/jawg-dark/{z}/{x}/{y}{r}.png', |
| 212 |
'https://{s}.tile.jawg.io/jawg-light/{z}/{x}/{y}{r}.png', |
| 213 |
))):?> |
| 214 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style']);?><?php echo (wmvc_show_data('jawg_map_key', $settings, false)) ? '?access-token='.esc_js(wmvc_show_data('jawg_map_key', $settings)) : '';?>').addTo(wdk_map); |
| 215 |
<?php else:?> |
| 216 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style']);?>').addTo(wdk_map); |
| 217 |
<?php endif;?> |
| 218 |
<?php endif;?> |
| 219 |
|
| 220 |
var auto_marker_size = false; |
| 221 |
<?php foreach($results as $key=>$listing): ?> |
| 222 |
<?php if(!is_numeric(wmvc_show_data('lng', $listing)))continue;?> |
| 223 |
<?php |
| 224 |
$pin_icon = ""; |
| 225 |
$font_class = ""; |
| 226 |
$font_icon = $this->generate_icon($settings['conf_custom_map_pin_icon']); |
| 227 |
$pin_icon = $settings['conf_custom_map_pin']['url']; |
| 228 |
|
| 229 |
if(!empty(wmvc_show_data('category_id', $listing))){ |
| 230 |
$category = $WMVC->category_m->get_data(wmvc_show_data('category_id', $listing)); |
| 231 |
if(wmvc_show_data('marker_image_id', $category, false, TRUE, TRUE)){ |
| 232 |
$pin_icon = wdk_image_src($category, 'full', NULL,'marker_image_id'); |
| 233 |
} else if(!empty(wmvc_show_data('font_icon_code', $category))) { |
| 234 |
$font_class = wmvc_show_data('font_icon_code', $category); |
| 235 |
} |
| 236 |
} else { |
| 237 |
$font_class = ""; |
| 238 |
} |
| 239 |
|
| 240 |
$listing_lat = $listing_lng = NULL; |
| 241 |
$listing_lat = wmvc_show_data('lat', $listing); |
| 242 |
$listing_lng = wmvc_show_data('lng', $listing); |
| 243 |
|
| 244 |
if(wmvc_show_data('conf_hide_real_location', $settings) == 'yes') { |
| 245 |
$gps = wdk_get_near_location($listing_lat, $listing_lng); |
| 246 |
//$listing_lat = (wmvc_show_data('lat', $gps)); |
| 247 |
//$listing_lng = (wmvc_show_data('lng', $gps)); |
| 248 |
|
| 249 |
$listing_lat = wdk_move_gps($listing_lat); |
| 250 |
$listing_lng = wdk_move_gps($listing_lng); |
| 251 |
} |
| 252 |
|
| 253 |
?> |
| 254 |
<?php if(!empty($settings['custom_marker_fields']) && substr($this->data['settings']['custom_marker_fields'], strpos($this->data['settings']['custom_marker_fields'],'__')+2) == 'first_image'):?> |
| 255 |
auto_marker_size = true; |
| 256 |
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>'; |
| 257 |
|
| 258 |
<?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)):?> |
| 259 |
<?php |
| 260 |
$field_id = substr($this->data['settings']['custom_marker_fields'], strpos($this->data['settings']['custom_marker_fields'],'__')+2); |
| 261 |
|
| 262 |
$field_value = ''; |
| 263 |
$field_value .= apply_filters( 'wpdirectorykit/listing/field/prefix', wdk_field_option ($field_id, 'prefix'), $field_id); |
| 264 |
|
| 265 |
/* if price field use like 1l */ |
| 266 |
if(wdk_field_option($field_id, 'is_price_format')) { |
| 267 |
|
| 268 |
$value = wdk_field_value($field_id, $listing); |
| 269 |
if($value>=1000) { |
| 270 |
$value = apply_filters( 'wpdirectorykit/listing/field/value', number_format_i18n(wdk_filter_decimal($value/1000)), $field_id).'k'; |
| 271 |
} else { |
| 272 |
$value = apply_filters( 'wpdirectorykit/listing/field/value', wdk_field_value_on_type($field_id, $listing), $field_id); |
| 273 |
} |
| 274 |
|
| 275 |
$field_value = $value; |
| 276 |
|
| 277 |
} else { |
| 278 |
$field_value .= apply_filters( 'wpdirectorykit/listing/field/value', wdk_field_value_on_type($field_id, $listing), $field_id); |
| 279 |
} |
| 280 |
|
| 281 |
$field_value .= apply_filters( 'wpdirectorykit/listing/field/suffix',wdk_field_option ($field_id, 'suffix'), $field_id); |
| 282 |
?> |
| 283 |
auto_marker_size = true; |
| 284 |
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>'; |
| 285 |
<?php elseif($pin_icon):?> |
| 286 |
var image = '<?php echo esc_html($pin_icon);?>'; var innerMarker = '<div class="wdk_marker-container wdk_marker-container-image"><img src='+image+'></img></div>'; |
| 287 |
<?php elseif($font_icon && empty($font_class)):?> |
| 288 |
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>'; |
| 289 |
<?php else:?> |
| 290 |
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>'; |
| 291 |
<?php endif;?> |
| 292 |
|
| 293 |
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($listing_lat);?>','<?php echo esc_html($listing_lng);?>',innerMarker, wdk_jpopup_customOptions, auto_marker_size |
| 294 |
, <?php if(wmvc_show_data('disable_cluster', $settings) == 'yes'):?> false <?php endif;?>)); |
| 295 |
<?php endforeach; ?> |
| 296 |
wdk_map.addLayer(wdk_clusters); |
| 297 |
/* set center */ |
| 298 |
if(wdk_markers.length){ |
| 299 |
var limits_center = []; |
| 300 |
for (var i in wdk_markers) { |
| 301 |
var latLngs = [ wdk_markers[i].getLatLng() ]; |
| 302 |
limits_center.push(latLngs) |
| 303 |
}; |
| 304 |
var bounds = L.latLngBounds(limits_center); |
| 305 |
<?php if(wdk_get_option('wdk_fixed_map_results_position') && wdk_get_option('wdk_default_lat') && wdk_get_option('wdk_default_lng')): ?> |
| 306 |
wdk_map.setView(["<?php echo esc_js(wdk_get_option('wdk_default_lat'));?>","<?php echo esc_js(wdk_get_option('wdk_default_lng'));?>"]); |
| 307 |
<?php elseif($settings['enable_custom_gps_center'] == 'yes'): ?> |
| 308 |
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']);?>"]); |
| 309 |
<?php else: ?> |
| 310 |
wdk_map.fitBounds(bounds); |
| 311 |
<?php endif; ?> |
| 312 |
} |
| 313 |
}) |
| 314 |
</script> |
| 315 |
<?php |
| 316 |
|
| 317 |
if (!$is_edit_mode) { |
| 318 |
$js_content = ob_get_clean(); |
| 319 |
$js_content = str_replace(array('</script>','<script>'),'',$js_content ); |
| 320 |
wp_add_inline_script( 'wdk-elementor-main', $js_content ); |
| 321 |
} |
| 322 |
?> |
| 323 |
|
| 324 |
|