| 1 |
<?php |
| 2 |
/** |
| 3 |
* The template for Element Listing Map. |
| 4 |
* This is the template that elementor element map |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
?> |
| 13 |
|
| 14 |
<?php |
| 15 |
if(empty($lng) || empty($lat)) { |
| 16 |
?> |
| 17 |
<div class=""> |
| 18 |
<p class="wdk_alert wdk_alert-danger"><?php echo esc_html__('Missing address', 'wpdirectorykit');?></p> |
| 19 |
</div> |
| 20 |
<?php |
| 21 |
return false; |
| 22 |
} |
| 23 |
?> |
| 24 |
|
| 25 |
<div class="wdk-element" id="wdk_el_<?php echo esc_html($id_element);?>"> |
| 26 |
<div class="wdk-map infobox-basic"> |
| 27 |
<div id="wdk_map_results_<?php echo esc_html($id_element);?>" style="height:<?php echo esc_attr($settings['conf_custom_map_height']['size']);?>px" ></div> |
| 28 |
|
| 29 |
<?php if(wmvc_show_data('enable_router_suggest',$settings) =='yes'): ?> |
| 30 |
<form class="route_suggestion" action=""> |
| 31 |
<input class="input_text" type="hidden" name="address" value="<?php echo esc_attr(wdk_field_value('address', $wdk_listing_id));?>" /> |
| 32 |
<input class="input_text" type="hidden" name="gps" value="<?php echo esc_attr($lat.','.$lng);?>" /> |
| 33 |
<div class="wdk-field-group"> |
| 34 |
<input class="input_text" type="text" placeholder="<?php echo esc_html__(wmvc_show_data('text_suggestion_route_placeholder', $settings), 'wpdirectorykit');?>" name="route_from" /> |
| 35 |
</div> |
| 36 |
<div class="wdk-field-group"> |
| 37 |
<button type="submit" class="wdk-btn"><?php echo esc_html__(wmvc_show_data('text_suggestion_route', $settings), 'wpdirectorykit');?></button> |
| 38 |
</div> |
| 39 |
</form> |
| 40 |
<?php endif;?> |
| 41 |
</div> |
| 42 |
</div> |
| 43 |
<?php |
| 44 |
$zoom_index = $settings['conf_custom_map_zoom_index']['size']; |
| 45 |
?> |
| 46 |
|
| 47 |
<?php |
| 48 |
$WMVC = &wdk_get_instance(); |
| 49 |
$WMVC->model('category_m'); |
| 50 |
if (!$is_edit_mode) |
| 51 |
ob_start(); |
| 52 |
?> |
| 53 |
<script> |
| 54 |
var wdk_map_<?php echo esc_html($id_element);?> =''; |
| 55 |
var wdk_markers_<?php echo esc_html($id_element);?> = []; |
| 56 |
var wdk_clusters_<?php echo esc_html($id_element);?> =''; |
| 57 |
var wdk_jpopup_customOptions = |
| 58 |
{ |
| 59 |
'maxWidth': 'initial', |
| 60 |
'width': 'initial', |
| 61 |
'className' : 'popupCustom' |
| 62 |
}; |
| 63 |
jQuery(document).ready(function($) { |
| 64 |
if(wdk_clusters_<?php echo esc_html($id_element);?>=='') |
| 65 |
wdk_clusters_<?php echo esc_html($id_element);?> = L.markerClusterGroup({spiderfyOnMaxZoom: true, showCoverageOnHover: false, zoomToBoundsOnClick: true}); |
| 66 |
wdk_map_<?php echo esc_html($id_element);?> = L.map('wdk_map_results_<?php echo esc_html($id_element);?>', { |
| 67 |
center: ["<?php echo esc_js($lat);?>","<?php echo esc_js($lng);?>"], |
| 68 |
zoom: "<?php echo esc_js($zoom_index);?>", |
| 69 |
scrollWheelZoom: false, |
| 70 |
<?php if($settings['conf_custom_dragging'] == 'yes'):?> |
| 71 |
dragging: true, |
| 72 |
<?php else:?> |
| 73 |
dragging: false, |
| 74 |
<?php endif;?> |
| 75 |
tap: !L.Browser.mobile, |
| 76 |
fullscreenControl: true, |
| 77 |
fullscreenControlOptions: { |
| 78 |
position: 'topleft' |
| 79 |
} |
| 80 |
}); |
| 81 |
|
| 82 |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { |
| 83 |
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' |
| 84 |
}).addTo(wdk_map_<?php echo esc_html($id_element);?>); |
| 85 |
|
| 86 |
<?php if(!empty($settings['conf_custom_map_style']) && $settings['conf_custom_map_style'] =='custom' && !empty($settings['conf_custom_map_style_self'])):?> |
| 87 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style_self']);?>').addTo(wdk_map_<?php echo esc_html($id_element);?>); |
| 88 |
<?php elseif(!empty($settings['conf_custom_map_style']) && $settings['conf_custom_map_style'] !='custom'):?> |
| 89 |
<?php if($settings['conf_custom_map_style']=='google_map'):?> |
| 90 |
<?php |
| 91 |
wp_enqueue_script('google-map-api', 'https://maps.googleapis.com/maps/api/js?key='.wmvc_show_data('google_map_key', $settings, '')); |
| 92 |
?> |
| 93 |
var roadMutant = L.gridLayer |
| 94 |
.googleMutant({ |
| 95 |
type: "roadmap", |
| 96 |
}); |
| 97 |
|
| 98 |
var satMutant = L.gridLayer.googleMutant({ |
| 99 |
type: "satellite", |
| 100 |
}); |
| 101 |
|
| 102 |
var terrainMutant = L.gridLayer.googleMutant({ |
| 103 |
type: "terrain", |
| 104 |
}); |
| 105 |
|
| 106 |
var hybridMutant = L.gridLayer.googleMutant({ |
| 107 |
type: "hybrid", |
| 108 |
}); |
| 109 |
|
| 110 |
var styleMutant = L.gridLayer.googleMutant({ |
| 111 |
styles: [ |
| 112 |
{ elementType: "labels", stylers: [{ visibility: "off" }] }, |
| 113 |
{ featureType: "water", stylers: [{ color: "#444444" }] }, |
| 114 |
{ featureType: "landscape", stylers: [{ color: "#eeeeee" }] }, |
| 115 |
{ featureType: "road", stylers: [{ visibility: "off" }] }, |
| 116 |
{ featureType: "poi", stylers: [{ visibility: "off" }] }, |
| 117 |
{ featureType: "transit", stylers: [{ visibility: "off" }] }, |
| 118 |
{ featureType: "administrative", stylers: [{ visibility: "off" }] }, |
| 119 |
{ |
| 120 |
featureType: "administrative.locality", |
| 121 |
stylers: [{ visibility: "off" }], |
| 122 |
}, |
| 123 |
], |
| 124 |
maxZoom: 24, |
| 125 |
type: "roadmap", |
| 126 |
}); |
| 127 |
|
| 128 |
var trafficMutant = L.gridLayer.googleMutant({ |
| 129 |
type: "roadmap", |
| 130 |
}); |
| 131 |
trafficMutant.addGoogleLayer("TrafficLayer"); |
| 132 |
|
| 133 |
var transitMutant = L.gridLayer.googleMutant({ |
| 134 |
type: "roadmap", |
| 135 |
}); |
| 136 |
|
| 137 |
var satelliteMutant = L.gridLayer.googleMutant({ |
| 138 |
type: "satellite", |
| 139 |
}); |
| 140 |
transitMutant.addGoogleLayer("TransitLayer"); |
| 141 |
|
| 142 |
var google_map_style = roadMutant; |
| 143 |
<?php switch (wmvc_show_data('google_map_default_type', $settings, 'roadMutant')){ |
| 144 |
case 'roadmap': |
| 145 |
echo 'google_map_style=roadMutant'; |
| 146 |
break; |
| 147 |
case 'aerial': |
| 148 |
echo 'google_map_style=satMutant'; |
| 149 |
break; |
| 150 |
case 'terrain': |
| 151 |
echo 'google_map_style=terrainMutant'; |
| 152 |
break; |
| 153 |
case 'hybrid': |
| 154 |
echo 'google_map_style=hybridMutant'; |
| 155 |
break; |
| 156 |
case 'satellite': |
| 157 |
echo 'google_map_style=satelliteMutant'; |
| 158 |
break; |
| 159 |
case 'styles': |
| 160 |
echo 'google_map_style=styleMutant'; |
| 161 |
break; |
| 162 |
case 'traffic': |
| 163 |
echo 'google_map_style=trafficMutant'; |
| 164 |
break; |
| 165 |
case 'transit': |
| 166 |
echo 'google_map_style=transitMutant'; |
| 167 |
break; |
| 168 |
} |
| 169 |
?> |
| 170 |
|
| 171 |
google_map_style.addTo(wdk_map_<?php echo esc_html($id_element);?>); |
| 172 |
L.control.layers( |
| 173 |
{ |
| 174 |
Roadmap: roadMutant, |
| 175 |
Aerial: satMutant, |
| 176 |
Terrain: terrainMutant, |
| 177 |
Hybrid: hybridMutant, |
| 178 |
Satellite: satelliteMutant, |
| 179 |
Traffic: trafficMutant, |
| 180 |
Transit: transitMutant, |
| 181 |
} |
| 182 |
).addTo(wdk_map_<?php echo esc_html($id_element);?>); |
| 183 |
|
| 184 |
<?php elseif(in_array($settings['conf_custom_map_style'], array( |
| 185 |
'https://{s}.tile.thunderforest.com/mobile-atlas/{z}/{x}/{y}.png', |
| 186 |
'https://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png', |
| 187 |
'https://{s}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png', |
| 188 |
'https://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png', |
| 189 |
'https://{s}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png', |
| 190 |
'https://{s}.tile.thunderforest.com/pioneer/{z}/{x}/{y}.png', |
| 191 |
'https://{s}.tile.thunderforest.com/neighbourhood/{z}/{x}/{y}.png', |
| 192 |
))):?> |
| 193 |
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); |
| 194 |
<?php elseif(in_array($settings['conf_custom_map_style'], array( |
| 195 |
'https://{s}.tile.jawg.io/jawg-terrain/{z}/{x}/{y}{r}.png', |
| 196 |
'https://{s}.tile.jawg.io/jawg-streets/{z}/{x}/{y}{r}.png', |
| 197 |
'https://{s}.tile.jawg.io/jawg-dark/{z}/{x}/{y}{r}.png', |
| 198 |
'https://{s}.tile.jawg.io/jawg-light/{z}/{x}/{y}{r}.png', |
| 199 |
))):?> |
| 200 |
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); |
| 201 |
<?php else:?> |
| 202 |
var positron = L.tileLayer('<?php echo esc_js($settings['conf_custom_map_style']);?>').addTo(wdk_map_<?php echo esc_html($id_element);?>); |
| 203 |
<?php endif;?> |
| 204 |
<?php endif;?> |
| 205 |
|
| 206 |
<?php if(is_numeric($lng)):?> |
| 207 |
<?php |
| 208 |
$font_class = "fa fa-home"; |
| 209 |
$font_icon = $this->generate_icon($settings['conf_custom_map_pin_icon']); |
| 210 |
$pin_icon = $settings['conf_custom_map_pin']['url']; |
| 211 |
|
| 212 |
if(!empty(wdk_field_value('category_id', $wdk_listing_id))){ |
| 213 |
$category = $WMVC->category_m->get_data(wdk_field_value('category_id', $wdk_listing_id)); |
| 214 |
if(wmvc_show_data('marker_image_id', $category, false, TRUE, TRUE)){ |
| 215 |
$pin_icon = wdk_image_src($category, 'full', NULL,'marker_image_id'); |
| 216 |
} else if(!empty(wmvc_show_data('font_icon_code', $category))) { |
| 217 |
$font_class = wmvc_show_data('font_icon_code', $category); |
| 218 |
} |
| 219 |
} else { |
| 220 |
$font_class = ""; |
| 221 |
} |
| 222 |
|
| 223 |
$wdk_popup_content = '<div class="infobox map-box wdk-infobox-basic">' |
| 224 |
.'<h3 class="title">'.esc_html(wdk_field_value('post_title', $wdk_listing_id)).'</h3>' |
| 225 |
.'<p>'.esc_html(wdk_field_value('address', $wdk_listing_id)).'</p>' |
| 226 |
.'</div>'; |
| 227 |
|
| 228 |
if($settings['puopup_custom_content'] == 'yes') { |
| 229 |
$title_field_id = substr($settings['title_field_id'], strpos($settings['title_field_id'],'__')+2); |
| 230 |
$content_field_id = substr($settings['content_field_id'], strpos($settings['content_field_id'],'__')+2); |
| 231 |
|
| 232 |
$wdk_popup_content = '<div class="infobox map-box wdk-infobox-basic">' |
| 233 |
.'<h3 class="title">'.esc_html(wdk_field_value($title_field_id, $wdk_listing_id)).'</h3>' |
| 234 |
.'<p>'.esc_html(wdk_field_value($content_field_id, $wdk_listing_id)).'</p>' |
| 235 |
.'</div>'; |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
$wdk_popup_content = str_replace("'", "\'", $wdk_popup_content); |
| 241 |
$wdk_popup_content = str_replace("\n", "", $wdk_popup_content); |
| 242 |
$wdk_popup_content = str_replace("\r", "", $wdk_popup_content); |
| 243 |
?> |
| 244 |
let marker; |
| 245 |
<?php if($pin_icon):?> |
| 246 |
var image = '<?php echo esc_html($pin_icon);?>'; var innerMarker = '<div class="wdk_marker-container wdk_marker-container-image category_id_<?php echo esc_js(wdk_field_value('category_id', $wdk_listing_id));?>""><img src='+image+'></img></div>'; |
| 247 |
<?php elseif($font_icon && empty($font_class)):?> |
| 248 |
var innerMarker = '<div class="wdk_marker-container category_id_<?php echo esc_js(wdk_field_value('category_id', $wdk_listing_id));?>""><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>'; |
| 249 |
<?php else:?> |
| 250 |
var innerMarker = '<div class="wdk_marker-container category_id_<?php echo esc_js(wdk_field_value('category_id', $wdk_listing_id));?>""><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>'; |
| 251 |
<?php endif;?> |
| 252 |
|
| 253 |
<?php if($settings['conf_custom_popup_enable'] == 'yes'):?> |
| 254 |
marker = wdk_generate_marker_basic_popup('<?php echo esc_html($lat);?>','<?php echo esc_html($lng);?>',innerMarker,'<?php echo $wdk_popup_content;?>', wdk_jpopup_customOptions); |
| 255 |
<?php else:?> |
| 256 |
marker = wdk_generate_marker_nopopup('<?php echo esc_html($lat);?>','<?php echo esc_html($lng);?>',innerMarker); |
| 257 |
<?php endif;?> |
| 258 |
|
| 259 |
wdk_markers_<?php echo esc_html($id_element);?>.push(marker); |
| 260 |
wdk_clusters_<?php echo esc_html($id_element);?>.addLayer(marker); |
| 261 |
wdk_map_<?php echo esc_html($id_element);?>.addLayer(wdk_clusters_<?php echo esc_html($id_element);?>); |
| 262 |
<?php endif;?> |
| 263 |
/* set center */ |
| 264 |
}) |
| 265 |
</script> |
| 266 |
|
| 267 |
<?php |
| 268 |
if (!$is_edit_mode) { |
| 269 |
$js_content = ob_get_clean(); |
| 270 |
$js_content = str_replace(array('</script>','<script>'),'',$js_content ); |
| 271 |
wp_add_inline_script( 'wdk-elementor-main', $js_content ); |
| 272 |
} |
| 273 |
?> |
| 274 |
|
| 275 |
|