PageSourceSearch

https://hardenproperty.com/wp-content/themes/realhomes/common/js/properties-open-street-map.js?ver=4.3.9

js hardenproperty.com collected 2026-10-10 00:23:06 UTC 14,729 bytes, 340 lines download raw bytes

1/**
2 * Javascript to handle open street map for multiple properties
3 */
4( function ( $ ) {
5    "use strict";
6
7    window.realhomes_update_open_street_map = function ( propertiesMapData ) {
8        if ( typeof propertiesMapData !== "undefined" ) {
9
10            // Map container
11            const $mapHead = $( '#map-head' );
12
13            // Bail if map container does not exist on the page.
14            if ( ! $mapHead.length ) {
15                return;
16            }
17
18            let mapZoomLevel  = parseInt( propertiesMapOptions.zoom, 10 );
19            let hasCustomZoom = ! Number.isNaN( mapZoomLevel );
20
21            $mapHead.empty();
22            $mapHead.append( '<div id="listing-map"></div>' );
23
24            if ( 0 < propertiesMapData.length ) {
25
26                var tileLayer = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
27                    attribution : '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
28                } );
29
30                // Get map bounds
31                var mapBounds = [];
32                for ( var i = 0; i < propertiesMapData.length; i++ ) {
33                    if ( propertiesMapData[i].lat && propertiesMapData[i].lng ) {
34                        mapBounds.push( [propertiesMapData[i].lat, propertiesMapData[i].lng] );
35                    }
36                }
37
38                let priceTagClasses = $( '#map-head' ).hasClass( 'dual-price' ) ? 'dual-price' : '';
39
40                // Basic map
41                var mapCenter = L.latLng( 27.664827, -81.515755 );	// given coordinates not going to matter 99.9% of the time but still added just in case.
42                if ( 1 == mapBounds.length ) {
43                    mapCenter = L.latLng( mapBounds[0] );	// this is also not going to effect 99% of the the time but just in case of one property.
44                }
45                var mapDragging = ( L.Browser.mobile ) ? false : true; // disabling one finger dragging on mobile but zoom with two fingers will still be enabled.
46                var mapOptions  = {
47                    dragging    : mapDragging,
48                    center      : mapCenter,
49                    zoom        : hasCustomZoom ? mapZoomLevel : ( ( 1 === mapBounds.length ) ? 15 : undefined ),
50                    zoomControl : false,
51                    tap         : false,
52                    layers      : [tileLayer]
53                };
54
55                var propertiesMap = L.map( 'listing-map', mapOptions );
56
57                L.control.zoom( {
58                    position : 'bottomleft'
59                } ).addTo( propertiesMap );
60
61                propertiesMap.scrollWheelZoom.disable();
62
63                if ( 1 < mapBounds.length ) {
64
65                    if ( hasCustomZoom ) {
66                        propertiesMap.setView(
67                            L.latLngBounds( mapBounds ).getCenter(),
68                            mapZoomLevel
69                        );
70                    } else {
71                        propertiesMap.fitBounds( mapBounds );
72                    }
73                }
74
75
76                if ( 1 < propertiesMapData.length ) {
77                    var markers = L.markerClusterGroup( {
78                        chunkedLoading    : true,
79                        spiderfyOnMaxZoom : true,
80                        animate           : false
81                    } );
82                }
83
84                for ( var i = 0; i < propertiesMapData.length; i++ ) {
85
86                    if ( propertiesMapData[i].lat && propertiesMapData[i].lng ) {
87
88                        var propertyMapData = propertiesMapData[i];
89                        var markerLatLng    = L.latLng( propertyMapData.lat, propertyMapData.lng );
90                        var markerOptions   = {
91                            id          : propertyMapData.id,
92                            riseOnHover : true
93                        };
94
95                        // Marker icon
96                        if ( propertyMapData.title ) {
97                            markerOptions.title = propertyMapData.title;
98                        }
99
100                        // Map marker.
101                        if ( 'pin' === propertiesMapOptions.marker_type && propertyMapData.icon ) {
102                            var iconOptions = {
103                                iconUrl     : propertyMapData.icon,
104                                iconSize    : [42, 57],
105                                iconAnchor  : [20, 57],
106                                popupAnchor : [1, -57]
107                            };
108                            if ( propertyMapData.retinaIcon ) {
109                                iconOptions.iconRetinaUrl = propertyMapData.retinaIcon;
110                            }
111                            markerOptions.icon = L.icon( iconOptions );
112                            var propertyMarker = L.marker( markerLatLng, markerOptions );
113
114                        } else {
115                            var propertyMarker = new L.CircleMarker( markerLatLng, {
116                                fillColor   : propertiesMapOptions.marker_color,
117                                color       : propertiesMapOptions.marker_color,
118                                weight      : 2,
119                                fillOpacity : 0.6,
120                                opacity     : 0.6,
121                                radius      : 25
122                            } );
123                        }
124
125                        // Marker popup
126                        var popupContent        = "",
127                            popupContentWrapper = document.createElement( "div" );
128
129                        popupContentWrapper.className = 'osm-popup-content';
130
131                        if ( propertyMapData.thumb ) {
132                            popupContent += '<a class="osm-popup-thumb-link" href="' + propertyMapData.url + '"><img class="osm-popup-thumb" src="' + propertyMapData.thumb + '" alt="' + propertyMapData.title + '"/></a>';
133                        }
134
135                        if ( rhMapsData.isUltra ) {
136                            popupContent += '<div class="osm-detail-wrapper">';
137
138                            if ( propertyMapData.title ) {
139                                popupContent += '<h5 class="osm-popup-title"><a class="osm-popup-link" href="' + propertyMapData.url + '">' + propertyMapData.title + '</a></h5>';
140                            }
141
142                            popupContent += '<div>';
143
144                            if ( propertyMapData.propertyType ) {
145                                popupContent += '<span class="type">' + propertyMapData.propertyType + '</span>';
146                            }
147
148                            if ( propertyMapData.price ) {
149                                popupContent += '<p><span class="osm-popup-price ' + priceTagClasses + '">' + propertyMapData.price + '</span></p>';
150                            }
151
152                            popupContent += '</div>';
153                            popupContent += '</div>';
154
155                        } else {
156                            if ( propertyMapData.title ) {
157                                popupContent += '<h5 class="osm-popup-title"><a class="osm-popup-link" href="' + propertyMapData.url + '">' + propertyMapData.title + '</a></h5>';
158                            }
159
160                            if ( propertyMapData.price ) {
161                                popupContent += '<p><span class="osm-popup-price ' + priceTagClasses + '">' + propertyMapData.price + '</span></p>';
162                            }
163                        }
164
165                        popupContentWrapper.innerHTML = popupContent;
166
167                        propertyMarker.popupContents = popupContentWrapper;
168
169                        propertyMarker.id = propertyMapData.id;
170
171                        propertyMarker.bindPopup( popupContentWrapper );
172
173                        if ( 1 < propertiesMapData.length ) {
174                            markers.addLayer( propertyMarker );
175                        } else {
176                            propertyMarker.addTo( propertiesMap );
177                        }
178                    }
179                }
180
181                if ( 1 < propertiesMapData.length ) {
182                    propertiesMap.addLayer( markers );
183                }
184
185                /**
186                 * Pan the marker to center of the visible map on popupopen event
187                 */
188                propertiesMap.on( 'popupopen', function ( e ) {
189                    // find the pixel location on the map where the popup anchor is
190                    var px = propertiesMap.project( e.target._popup._latlng );
191                    // find the height of the popup container, divide by 2, subtract from the Y axis of marker location
192                    px.y -= e.target._popup._container.clientHeight / 2;
193                    // pan to new center
194                    propertiesMap.panTo( propertiesMap.unproject( px ), { animate : true } );
195                } );
196
197                /**
198                 * Function to find the marker in a cluster
199                 * @param {int} marker
200                 * @param {int} cluster
201                 * @returns
202                 */
203                function is_marker_in_cluster( marker, cluster ) {
204                    var length = cluster.length;
205
206                    for ( var i = 0; i < length; i++ ) {
207                        if ( cluster[i].id == marker ) {
208                            return true;
209                        }
210                    }
211
212                    return false;
213                }
214
215                /**
216                 * Open Popup function
217                 * @param {int} markerid
218                 */
219                function osm_open_popup( markerid ) {
220                    propertiesMap.eachLayer( function ( layer ) {
221
222                        // Checking if this layer is a cluster
223                        if ( typeof layer._childCount !== "undefined" ) {
224
225                            // Getting all markers in this cluster
226                            var markersincluster = layer.getAllChildMarkers();
227
228                            if ( is_marker_in_cluster( markerid, markersincluster ) ) {
229                                layer.spiderfy();
230
231                                markersincluster.forEach( function ( property_marker ) {
232                                    if ( property_marker.id == markerid ) {
233                                        property_marker.openPopup();
234                                    }
235                                } );
236                            }
237
238                        } else {
239                            if ( layer.id == markerid ) {
240                                layer.openPopup();
241                            }
242                        }
243                    } );
244                }
245
246                /**
247                 * Close Popup function
248                 * @param {int} markerid
249                 */
250                function osm_close_popup( markerid ) {
251                    propertiesMap.eachLayer( function ( layer ) {
252
253                        // Checking if this layer is a cluster
254                        if ( typeof layer._childCount !== "undefined" ) {
255
256                            // Getting all markers in this cluster
257                            var markersincluster = layer.getAllChildMarkers();
258
259                            if ( is_marker_in_cluster( markerid, markersincluster ) ) {
260                                layer.unspiderfy();
261
262                                markersincluster.forEach( function ( property_marker ) {
263                                    if ( property_marker.id == markerid ) {
264                                        layer.closePopup();
265                                    }
266                                } );
267                            }
268
269                        } else {
270                            if ( layer.id == markerid ) {
271                                layer.closePopup();
272                                propertiesMap.closePopup();
273                            }
274                        }
275                    } );
276                }
277
278                window.realhomesInfoboxPopupTrigger = function () {
279                    $( '.rh_popup_info_map' ).each( function ( i ) {
280                        // Getting the Property ID for mouse events
281                        var property_ID = $( this ).attr( 'data-rh-id' ).replace( /[^\d.]/g, '' );
282
283                        $( this )
284                        .on( 'mouseenter', function () {
285                            osm_open_popup( property_ID );
286                        } )
287                        .on( 'mouseleave', function () {
288                            osm_close_popup( property_ID );
289                        } );
290                    } );
291
292                    return false;
293                };
294
295                var RHisMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test( navigator.userAgent ) ? true : false;
296
297                if ( ! RHisMobile ) {
298                    realhomesInfoboxPopupTrigger();
299                }
300
301            } else {
302                // Fallback Map in Case of No Properties
303                var fallbackLayer = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
304                    attribution : '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
305                } );
306
307                var fallback_lat,
308                    fallback_lng;
309                if ( undefined !== propertiesMapOptions.fallback_location && propertiesMapOptions.fallback_location.lat && propertiesMapOptions.fallback_location.lng ) {
310                    fallback_lat = propertiesMapOptions.fallback_location.lat;
311                    fallback_lng = propertiesMapOptions.fallback_location.lng;
312                } else {
313                    // Default location of Florida in fallback map.
314                    fallback_lat = '27.664827';
315                    fallback_lng = '-81.515755';
316                }
317
318                var fallbackMapOptions = {
319                    center : [fallback_lat, fallback_lng],
320                    zoom   : 12
321                };
322
323                var fallbackMap = L.map( 'listing-map', fallbackMapOptions );
324                fallbackMap.addLayer( fallbackLayer );
325
326                if ( rhMapsData.isClassic ) {
327                    fallbackMap.scrollWheelZoom.disable();
328                }
329            }
330        }
331
332        // Add custom class to zoom control to apply z-index for modern variation
333        $( ".leaflet-control-zoom" ).parent( ".leaflet-bottom" ).addClass( "rh_leaflet_controls_zoom" );
334    }
335
336    if ( typeof propertiesMapData !== "undefined" ) {
337        realhomes_update_open_street_map( propertiesMapData );
338    }
339
340} )( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.