(function($){
"use strict";
window.realhomes_update_open_street_map=function(propertiesMapData){
if(typeof propertiesMapData!=="undefined"){
const $mapHead=$('#map-head');
let mapZoomLevel=parseInt(propertiesMapOptions.zoom, 10);
let hasCustomZoom = ! Number.isNaN(mapZoomLevel);
$mapHead.empty();
$mapHead.append('<div id="listing-map"></div>');
if(0 < propertiesMapData.length){
var tileLayer=L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution:'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
var mapBounds=[];
for(var i=0; i < propertiesMapData.length; i++){
if(propertiesMapData[i].lat&&propertiesMapData[i].lng){
mapBounds.push([propertiesMapData[i].lat, propertiesMapData[i].lng]);
}}
let priceTagClasses=$('#map-head').hasClass('dual-price') ? 'dual-price':'';
var mapCenter=L.latLng(27.664827, -81.515755);
if(1==mapBounds.length){
mapCenter=L.latLng(mapBounds[0]);
}
var mapDragging=(L.Browser.mobile) ? false:true;
var mapOptions={
dragging:mapDragging,
center:mapCenter,
zoom:hasCustomZoom ? mapZoomLevel:(( 1===mapBounds.length) ? 15:undefined),
zoomControl:false,
tap:false,
layers:[tileLayer]
};
var propertiesMap=L.map('listing-map', mapOptions);
L.control.zoom({
position:'bottomleft'
}).addTo(propertiesMap);
propertiesMap.scrollWheelZoom.disable();
if(1 < mapBounds.length){
if(hasCustomZoom){
propertiesMap.setView(L.latLngBounds(mapBounds).getCenter(),
mapZoomLevel
);
}else{
propertiesMap.fitBounds(mapBounds);
}}
if(1 < propertiesMapData.length){
var markers=L.markerClusterGroup({
chunkedLoading:true,
spiderfyOnMaxZoom:true,
animate:false
});
}
for(var i=0; i < propertiesMapData.length; i++){
if(propertiesMapData[i].lat&&propertiesMapData[i].lng){
var propertyMapData=propertiesMapData[i];
var markerLatLng=L.latLng(propertyMapData.lat, propertyMapData.lng);
var markerOptions={
id:propertyMapData.id,
riseOnHover:true
};
if(propertyMapData.title){
markerOptions.title=propertyMapData.title;
}
if('pin'===propertiesMapOptions.marker_type&&propertyMapData.icon){
var iconOptions={
iconUrl:propertyMapData.icon,
iconSize:[42, 57],
iconAnchor:[20, 57],
popupAnchor:[1, -57]
};
if(propertyMapData.retinaIcon){
iconOptions.iconRetinaUrl=propertyMapData.retinaIcon;
}
markerOptions.icon=L.icon(iconOptions);
var propertyMarker=L.marker(markerLatLng, markerOptions);
}else{
var propertyMarker=new L.CircleMarker(markerLatLng, {
fillColor:propertiesMapOptions.marker_color,
color:propertiesMapOptions.marker_color,
weight:2,
fillOpacity:0.6,
opacity:0.6,
radius:25
});
}
var popupContent="",
popupContentWrapper=document.createElement("div");
popupContentWrapper.className='osm-popup-content';
if(propertyMapData.thumb){
popupContent +='<a class="osm-popup-thumb-link" href="' + propertyMapData.url + '"><img class="osm-popup-thumb" src="' + propertyMapData.thumb + '" alt="' + propertyMapData.title + '"/></a>';
}
if(rhMapsData.isUltra){
popupContent +='<div class="osm-detail-wrapper">';
if(propertyMapData.title){
popupContent +='<h5 class="osm-popup-title"><a class="osm-popup-link" href="' + propertyMapData.url + '">' + propertyMapData.title + '</a></h5>';
}
popupContent +='<div>';
if(propertyMapData.propertyType){
popupContent +='<span class="type">' + propertyMapData.propertyType + '</span>';
}
if(propertyMapData.price){
popupContent +='<p><span class="osm-popup-price ' + priceTagClasses + '">' + propertyMapData.price + '</span></p>';
}
popupContent +='</div>';
popupContent +='</div>';
}else{
if(propertyMapData.title){
popupContent +='<h5 class="osm-popup-title"><a class="osm-popup-link" href="' + propertyMapData.url + '">' + propertyMapData.title + '</a></h5>';
}
if(propertyMapData.price){
popupContent +='<p><span class="osm-popup-price ' + priceTagClasses + '">' + propertyMapData.price + '</span></p>';
}}
popupContentWrapper.innerHTML=popupContent;
propertyMarker.popupContents=popupContentWrapper;
propertyMarker.id=propertyMapData.id;
propertyMarker.bindPopup(popupContentWrapper);
if(1 < propertiesMapData.length){
markers.addLayer(propertyMarker);
}else{
propertyMarker.addTo(propertiesMap);
}}
}
if(1 < propertiesMapData.length){
propertiesMap.addLayer(markers);
}
propertiesMap.on('popupopen', function(e){
var px=propertiesMap.project(e.target._popup._latlng);
px.y -=e.target._popup._container.clientHeight / 2;
propertiesMap.panTo(propertiesMap.unproject(px), { animate:true });
});
function is_marker_in_cluster(marker, cluster){
var length=cluster.length;
for(var i=0; i < length; i++){
if(cluster[i].id==marker){
return true;
}}
return false;
}
function osm_open_popup(markerid){
propertiesMap.eachLayer(function(layer){
if(typeof layer._childCount!=="undefined"){
var markersincluster=layer.getAllChildMarkers();
if(is_marker_in_cluster(markerid, markersincluster) ){
layer.spiderfy();
markersincluster.forEach(function(property_marker){
if(property_marker.id==markerid){
property_marker.openPopup();
}});
}}else{
if(layer.id==markerid){
layer.openPopup();
}}
});
}
function osm_close_popup(markerid){
propertiesMap.eachLayer(function(layer){
if(typeof layer._childCount!=="undefined"){
var markersincluster=layer.getAllChildMarkers();
if(is_marker_in_cluster(markerid, markersincluster) ){
layer.unspiderfy();
markersincluster.forEach(function(property_marker){
if(property_marker.id==markerid){
layer.closePopup();
}});
}}else{
if(layer.id==markerid){
layer.closePopup();
propertiesMap.closePopup();
}}
});
}
window.realhomesInfoboxPopupTrigger=function (){
$('.rh_popup_info_map').each(function(i){
var property_ID=$(this).attr('data-rh-id').replace(/[^\d.]/g, '');
$(this)
.on('mouseenter', function (){
osm_open_popup(property_ID);
})
.on('mouseleave', function (){
osm_close_popup(property_ID);
});
});
return false;
};
var RHisMobile=/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true:false;
if(! RHisMobile){
realhomesInfoboxPopupTrigger();
}}else{
var fallbackLayer=L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution:'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
});
var fallback_lat,
fallback_lng;
if(undefined!==propertiesMapOptions.fallback_location&&propertiesMapOptions.fallback_location.lat&&propertiesMapOptions.fallback_location.lng){
fallback_lat=propertiesMapOptions.fallback_location.lat;
fallback_lng=propertiesMapOptions.fallback_location.lng;
}else{
fallback_lat='27.664827';
fallback_lng='-81.515755';
}
var fallbackMapOptions={
center:[fallback_lat, fallback_lng],
zoom:12
};
var fallbackMap=L.map('listing-map', fallbackMapOptions);
fallbackMap.addLayer(fallbackLayer);
if(rhMapsData.isClassic){
fallbackMap.scrollWheelZoom.disable();
}}
}
$(".leaflet-control-zoom").parent(".leaflet-bottom").addClass("rh_leaflet_controls_zoom");
}
if(typeof propertiesMapData!=="undefined"){
realhomes_update_open_street_map(propertiesMapData);
}})(jQuery);