PageSourceSearch

https://essft.com/wp-content/plugins/geodirectory/assets/aui/js/map.js?ver=2.8.180

js essft.com collected 2026-10-03 00:49:02 UTC 69,446 bytes, 1,749 lines download raw bytes

1window.gdJSMap = true;
2var is_zooming = false;
3var zoom_listener = '';
4var gd_current_query = '';
5var gd_map_first_load = true;
6var gd_fullscreen_parent = '';
7var gd_toggle_bsui = true;
8
9function initMap(map_options) {
10    // Set if the bsui class on html should be toggled
11    if (jQuery('html').hasClass('bsui')) {
12        gd_toggle_bsui = false;
13    }
14
15    if (window.gdMaps == 'osm') {
16        initMapOSM(map_options);
17        return;
18    }
19    // alert(map_options)
20    map_options = eval(map_options);
21    map_options.zoom = parseInt(map_options.zoom);
22    var options = map_options;
23    var pscaleFactor;
24    var pstartmin;
25    var ajax_url = options.ajax_url;
26    var token = options.token;
27    var search_string = options.token;
28    var mm = 0; // marker array
29    var maptype = options.maptype;
30    var zoom = options.zoom;
31    var latitude = options.latitude;
32    var longitude = options.longitude;
33    var maxZoom = options.maxZoom;
34    var etype = options.etype;
35    var autozoom = options.autozoom;
36    var scrollwheel = options.scrollwheel;
37    var fullscreenControl = options.fullscreenControl;
38    var streetview = options.streetViewControl;
39    var bubble_size = options.bubble_size;
40    var map_canvas = options.map_canvas;
41    var enable_map_direction = options.enable_map_direction;
42    var enable_cat_filters = options.enable_cat_filters;
43    var marker_cluster = options.marker_cluster;
44    options.token = '68f48005e256696074e1da9bf9f67f06';
45    options.navigationControlOptions = {
46        position: 'TOP_LEFT',
47        style: 'ZOOM_PAN'
48    };
49
50    // Create map
51    jQuery("#" + map_canvas).goMap(options);
52    // set max zoom
53    var styles = [{
54        featureType: "poi.business",
55        elementType: "labels",
56        stylers: [{
57            visibility: "off"
58        }]
59    }];
60    if (!(typeof geodir_custom_map_style === 'undefined'))
61        styles = geodir_custom_map_style;
62    /* custom google map style */
63    if (typeof options.mapStyles != 'undefined') {
64        try {
65            var mapStyles = JSON.parse(options.mapStyles);
66            if (typeof mapStyles == 'object' && mapStyles) {
67                styles = mapStyles;
68            }
69        } catch (err) {
70            console.log(err.message);
71        }
72    }
73    /* custom google map style */
74    jQuery.goMap.map.setOptions({
75        styles: styles
76    });
77
78    google.maps.event.addListenerOnce(jQuery.goMap.map, 'idle', function() {
79        jQuery("#" + map_canvas).goMap();
80        for (var i in google.maps.MapTypeId) {
81            jQuery.goMap.map.mapTypes[google.maps.MapTypeId[i]].maxZoom = options.maxZoom;
82        }
83    });
84    google.maps.event.addListener(jQuery.goMap.map, 'idle', function() {
85        //jQuery("#" + map_canvas).goMap();
86        //jQuery.goMap.map.removeListener('bounds_changed');
87        if (eval(map_canvas).marker_cluster_server) {
88            if (gd_map_first_load) {
89                gd_map_first_load = false;
90                eval(map_canvas).enable_marker_cluster_no_reposition = true;
91            } // first load do nothing
92            else {
93                if (is_zooming) {} else {
94                    is_zooming = true;
95                    build_map_ajax_search_param(map_canvas, false, false, true);
96                    is_zooming = false;
97                }
98            }
99        }
100    });
101    var maxMap = document.getElementById(map_canvas + '_triggermap');
102    if (!jQuery(maxMap).hasClass('gd-triggered-map')) { // skip multiple click listener after reload map via ajax
103        jQuery(maxMap).addClass('gd-triggered-map');
104        maxMap.addEventListener('click', gdMaxMap);
105    }
106
107    function gdMaxMap() {
108
109        if (jQuery('body').hasClass('body_fullscreen')) {
110            jQuery('#catcher_' + map_canvas + '').removeClass('position-fixed');
111            jQuery(window).scroll();
112            jQuery('#placeholder_' + map_canvas).after(jQuery(gd_fullscreen_parent));
113            jQuery('#placeholder_' + map_canvas).remove();
114        } else {
115            jQuery('#catcher_' + map_canvas + '').addClass('position-fixed');
116            jQuery(window).scroll();
117            gd_fullscreen_parent = jQuery('#' + map_canvas).parents(".stick_trigger_container"); //.parent();
118            jQuery(gd_fullscreen_parent).before('<div id="placeholder_' + map_canvas + '"></div>');
119            jQuery(gd_fullscreen_parent).prependTo("body");
120        }
121
122        // new
123        if (gd_toggle_bsui) {
124            jQuery('html').toggleClass('bsui');
125        }
126        jQuery('html').attr('style', function(index, attr) {
127            return attr == 'margin-top:0 !important;' ? '' : 'margin-top:0 !important;';
128        });
129        jQuery('body').toggleClass('body_fullscreen overflow-hidden');
130        jQuery('#' + map_canvas + ', #sticky_map_' + map_canvas + ',#' + map_canvas + '_wrapper').toggleClass('vw-100 vh-100');
131        jQuery('#' + map_canvas + '_triggermap i, .geodir-map-directions-wrap, #wpadminbar').toggleClass('d-none');
132
133        window.setTimeout(function() {
134            var center = jQuery.goMap.map.getCenter();
135            jQuery("#" + map_canvas).goMap();
136            google.maps.event.trigger(jQuery.goMap.map, 'resize');
137            jQuery.goMap.map.setCenter(center);
138            setGeodirMapSize(true);
139        }, 100);
140    }
141
142    // Overlapping Marker Spiderfier
143    window.oms = jQuery.goMap.oms;
144}
145
146function geodir_build_static_map(map_canvas) {
147    var width, height, width_raw, height_raw, wrapWi, wrapHe, maptype;
148
149    if (window.gdMaps != 'google') {
150        build_map_ajax_search_param(map_canvas, false);
151        return;
152    }
153    options = eval(map_canvas);
154
155    // Width
156    width_raw = options.width ? options.width : 0;
157    wrapWi = jQuery("#" + map_canvas).width();
158
159    if (wrapWi < 10) {
160        wrapWi = jQuery("#" + map_canvas).closest('.geodir-map-wrap').width();
161    }
162    if (width_raw.indexOf('%') !== -1) {
163        width = parseInt(parseInt(width_raw) * wrapWi / 100);
164    } else {
165        width = parseInt(width_raw.replace(/\D/g, ''));
166    }
167    if (width < 10) {
168        width = parseInt(wrapWi);
169    }
170
171    // Height
172    height_raw = options.height ? options.height : 0;
173    wrapHe = jQuery("#" + map_canvas).height();
174    if (wrapHe < 10) {
175        wrapHe = jQuery("#" + map_canvas).closest('.geodir-map-wrap').height();
176    }
177    if (height_raw.indexOf('%') !== -1) {
178        height = parseInt(parseInt(height_raw) * wrapHe / 100);
179    } else {
180        height = parseInt(height_raw.replace(/\D/g, ''));
181    }
182    if (height < 10) {
183        height = parseInt(wrapHe);
184    }
185
186    maptype = options.maptype ? (options.maptype).toLowerCase() : 'roadmap';
187
188    var img_url = "https://maps.googleapis.com/maps/api/staticmap?" + "size=" + width + "x" + height + "&maptype=" + maptype + "&language=" + geodir_params.mapLanguage + "&zoom=" + options.zoom + "&center=" + options.latitude + "," + options.longitude + "&markers=icon:" + options.icon_url + "|" + options.latitude + "," + options.longitude + "&key=" + geodir_params.google_api_key;
189
190    var img = "<img class='geodir-static-map-image' src='" + img_url + "' onclick='build_map_ajax_search_param(\"" + map_canvas + "\",false);' />";
191
192    jQuery("#" + map_canvas).html(img);
193    jQuery("." + map_canvas + "_TopLeft").hide();
194    jQuery('#' + map_canvas + '_loading_div').hide();
195}
196
197function geodir_no_map_api(map_canvas) {
198    jQuery('#' + map_canvas + '_loading_div').hide();
199    jQuery('#' + map_canvas + '_map_notloaded').show();
200    jQuery('#sticky_map_' + map_canvas).find('.map-category-listing-main').hide();
201    jQuery('#sticky_map_' + map_canvas).find('#' + map_canvas + '_posttype_menu').hide();
202    jQuery('#sticky_map_' + map_canvas).find('.' + map_canvas + '_TopLeft').hide();
203    jQuery('#sticky_map_' + map_canvas).find('.' + map_canvas + '_TopRight').hide();
204}
205
206function build_map_ajax_search_param(map_canvas, reload_cat_list, catObj, hide_loading) {
207    if (!window.gdMaps) {
208        geodir_no_map_api(map_canvas);
209        return false;
210    }
211    var $container, options, map_type, post_type, query_string = '',
212        search, custom_loop;
213
214    $container = jQuery('#sticky_map_' + map_canvas).closest('.stick_trigger_container');
215    options = eval(map_canvas);
216    map_type = options.map_type;
217    post_type = options.post_type;
218    post_type_filter = jQuery('#' + map_canvas + '_posttype').val();
219    if (post_type_filter) {
220        post_type = post_type_filter;
221    }
222
223    jQuery("." + map_canvas + "_TopLeft").show(); // static maps hide this so we show it when loading
224
225    // post type
226    query_string += 'post_type=' + post_type;
227    query_string += '&_wpnonce=' + options._wpnonce;
228
229    if (options.map_page) {
230        query_string += '&_mp=' + options.map_page;
231    }
232
233    if (options.all_posts) {
234        query_string += '&_ap=1';
235    }
236
237    // locations
238    if (options.country) {
239        query_string += "&country=" + options.country;
240    }
241    if (options.region) {
242        query_string += "&region=" + options.region;
243    }
244    if (options.city) {
245        query_string += "&city=" + options.city;
246    }
247    if (options.neighbourhood) {
248        query_string += "&neighbourhood=" + options.neighbourhood;
249    }
250    if (options.lat) {
251        query_string += "&lat=" + options.lat;
252    }
253    if (options.lon) {
254        query_string += "&lon=" + options.lon;
255    }
256    if (options.dist) {
257        query_string += "&dist=" + options.dist;
258    }
259
260    if (reload_cat_list) {
261        return geodir_map_post_type_terms(options, post_type, query_string);
262    }
263
264    // MC
265    var map_info = '';
266    if (jQuery.goMap.map && options.marker_cluster_server) { // map loaded so we know the bounds
267        bounds = jQuery.goMap.map.getBounds();
268        gd_zl = jQuery.goMap.map.getZoom();
269
270        if (bounds) {
271            if (window.gdMaps == 'osm') {
272                gd_lat_ne = bounds.getNorthEast().lat;
273                gd_lon_ne = bounds.getNorthEast().lng;
274                gd_lat_sw = bounds.getSouthWest().lat;
275                gd_lon_sw = bounds.getSouthWest().lng;
276            } else {
277                gd_lat_ne = bounds.getNorthEast().lat();
278                gd_lon_ne = bounds.getNorthEast().lng();
279                gd_lat_sw = bounds.getSouthWest().lat();
280                gd_lon_sw = bounds.getSouthWest().lng();
281            }
282            map_info = "&zl=" + gd_zl + "&lat_ne=" + gd_lat_ne + "&lon_ne=" + gd_lon_ne + "&lat_sw=" + gd_lat_sw + "&lon_sw=" + gd_lon_sw;
283        }
284
285    } else if (options.marker_cluster_server && !options.autozoom) { // map not loaded and auto zoom not set
286        gd_zl = options.zoom;
287        gd_map_h = jQuery('#' + map_canvas).height();
288        gd_map_w = jQuery('#' + map_canvas).width();
289        map_info = "&zl=" + gd_zl + "&gd_map_h=" + gd_map_h + "&gd_map_w=" + gd_map_w;
290    } else if (options.marker_cluster_server && options.autozoom) { // map not loaded and auto zoom set
291        gd_zl = options.zoom;
292        gd_map_h = jQuery('#' + map_canvas).height();
293        gd_map_w = jQuery('#' + map_canvas).width();
294        map_info = "&zl=" + gd_zl + "&gd_map_h=" + gd_map_h + "&gd_map_w=" + gd_map_w;
295    }
296
297    query_string += map_info;
298    // /MC
299
300    search = jQuery('#' + map_canvas + '_search_string').val();
301    if (!search && options.searchKeyword) {
302        search = options.searchKeyword;
303    }
304
305    // Terms
306    var terms_filters = false;
307
308    jQuery('[name="' + map_canvas + '_cat[]"]:checked').each(function() {
309        terms_filters = true;
310        if (jQuery(this).val()) {
311            query_string += '&term[]=' + jQuery(this).val();
312        }
313    });
314
315    // Terms
316    terms = options.terms;
317    if (!terms_filters && terms) {
318        if (typeof terms == 'object' || typeof terms == 'array') {} else {
319            terms = terms.split(',');
320        }
321        if (terms.length > 0) {
322            query_string += '&term[]=' + terms.join("&term[]=");
323        }
324    }
325
326    // Tags
327    var tags = options.tags;
328    if (tags) {
329        if (typeof tags == 'object' || typeof tags == 'array') {} else {
330            tags = tags.split(',');
331        }
332        if (tags.length > 0) {
333            custom_loop = tags[0] && tags[0].indexOf(".") === 0 || tags[0].indexOf("#") === 0 ? tags[0] : false; // css class or id.
334            if (custom_loop && jQuery(custom_loop + ' .geodir-category-list-view').length) {
335                // custom loop from listings widget on non gd pages.
336                var loopIds = jQuery(custom_loop + ' .geodir-category-list-view')
337                    .find(".geodir-post.type-" + post_type) //Find the spans
338                    .map(function() {
339                        return jQuery(this).data("post-id")
340                    }) //Project Ids
341                    .get(); //ToArray
342
343                if ((typeof loopIds == 'object' || typeof loopIds == 'array') && loopIds.length > 0) {
344                    query_string += '&post[]=' + loopIds.join("&post[]=");
345                } else {
346                    query_string += '&post[]=-1';
347                }
348            } else if (custom_loop && jQuery(custom_loop + ' .elementor-posts').length) {
349                // Elementor posts loop.
350                var loopIds = jQuery(custom_loop + ' .elementor-posts').find(".elementor-post.type-" + post_type)
351                    .map(function() {
352                        return jQuery(this).attr('id').match(/post-\d+/)[0].replace("post-","");
353                    }).get();
354
355                if ((typeof loopIds == 'object' || typeof loopIds == 'array') && loopIds.length > 0) {
356                    query_string += '&post[]=' + loopIds.join("&post[]=");
357                } else {
358                    query_string += '&post[]=-1';
359                }
360            } else {
361                query_string += '&tag[]=' + tags.join("&tag[]=");
362            }
363        }
364    }
365
366    // Posts
367    posts = options.posts;
368    if (posts) {
369        // archive pages
370        if (posts == 'geodir-loop-container') {
371            var idarray = jQuery(".geodir-loop-container")
372                .find(".geodir-post") //Find the spans
373                .map(function() {
374                    return jQuery(this).data("post-id")
375                }) //Project Ids
376                .get(); //ToArray
377
378            // check if elementor loop
379            if (!idarray.length && jQuery('.elementor-posts-container').length) {
380                $containerClass = jQuery('.geodir-loop-container').length ? jQuery(".geodir-loop-container") : (jQuery('.elementor-widget-archive-posts .elementor-posts-container:visible').length ? jQuery('.elementor-widget-archive-posts .elementor-posts-container:visible') : jQuery('.elementor-posts-container'));
381                idarray = $containerClass
382                    .find(".elementor-post ") //Find the spans
383                    .map(function() {
384                        return jQuery(this).attr('class').match(/post-\d+/)[0].replace("post-", "");
385                    }) //Project Ids
386                    .get(); //ToArray
387            }
388
389            if (idarray.length) {
390                posts = idarray;
391            } else {
392                posts = '-1';
393            }
394        }
395
396        if (typeof posts == 'object' || typeof posts == 'array') {} else {
397            posts = posts.split(',');
398        }
399        if (posts.length > 0) {
400            query_string += '&post[]=' + posts.join("&post[]=");
401        }
402    }
403
404    search = search ? search.trim() : '';
405    if (search && search != options.inputText) {
406        query_string += '&search=' + search;
407    }
408
409    if (options.customQueryArgs) {
410        query_string += options.customQueryArgs;
411    }
412
413    map_ajax_search(map_canvas, query_string, '', hide_loading);
414}
415
416function geodir_show_sub_cat_collapse_button() {
417
418    setTimeout(function() {
419        jQuery('ul.main_list li').each(function(i) {
420            var sub_cat_list = jQuery(this).find('ul.sub_list');
421            if (!(typeof sub_cat_list.attr('class') === 'undefined')) {
422
423                // insert
424                jQuery(sub_cat_list).parent('li').find('> .custom-checkbox label, > .form-check label').after('<span class="gd-map-cat-toggle ml-2 ms-2 c-pointer"><i class="fas fa-caret-down" aria-hidden="true" style="display:none"></i></span>');
425
426                if (sub_cat_list.is(':visible')) {
427                    jQuery(this).find('i,svg').removeClass('fa-caret-down');
428                    jQuery(this).find('i,svg').addClass('fa-caret-up');
429                } else {
430                    jQuery(this).find('i,svg').removeClass('fa-caret-up');
431                    jQuery(this).find('i,svg').addClass('fa-caret-down');
432                }
433                jQuery(this).find('i,svg').show();
434                /**/
435            } else {
436                jQuery(this).find('i,svg').hide();
437                /**/
438            }
439        });
440        geodir_activate_collapse_pan();
441    }, 100);
442}
443
444function geodir_activate_collapse_pan() {
445    jQuery('ul.main_list').find('.gd-map-cat-toggle').off('click').on("click",function() {
446        jQuery(this)
447            .parent()
448            .parent('li')
449            .find('ul.sub_list')
450            .toggle(200,
451                function() {
452                    if (jQuery(this).is(':visible')) {
453                        jQuery(this).parent('li').find('i,svg').removeClass('fa-caret-down');
454                        jQuery(this).parent('li').find('i,svg').addClass('fa-caret-up');
455                    } else {
456                        jQuery(this).parent('li').find('i,svg').removeClass('fa-caret-up');
457                        jQuery(this).parent('li').find('i,svg').addClass('fa-caret-down');
458                    }
459                });
460    });
461}
462
463function map_ajax_search(map_canvas_var, query_string, marker_jason, hide_loading, keep_markers) {
464    if (!window.gdMaps) {
465        jQuery('#' + map_canvas_var + '_loading_div').hide();
466        jQuery('#' + map_canvas_var + '_map_notloaded').show();
467        jQuery('#sticky_map_' + map_canvas_var).find('.map-category-listing-main').hide();
468        jQuery('#sticky_map_' + map_canvas_var).find('#' + map_canvas_var + '_posttype_menu').hide();
469        jQuery('#sticky_map_' + map_canvas_var).find('.' + map_canvas_var + '_TopLeft').hide();
470        jQuery('#sticky_map_' + map_canvas_var).find('.' + map_canvas_var + '_TopRight').hide();
471        return false;
472    }
473
474    if (hide_loading) {} //dont reposition after load
475    else {
476        jQuery('#' + map_canvas_var + '_loading_div').show();
477    }
478    if (marker_jason != '') {
479        parse_marker_jason(marker_jason, map_canvas_var, keep_markers);
480        //document.getElementById( map_canvas+'_loading_div').style.display="none";
481        jQuery('#' + map_canvas_var + '_loading_div').hide();
482        return;
483    }
484    var query_url = eval(map_canvas_var).map_markers_ajax_url;
485    if (query_string) {
486        u = query_url.indexOf('?') === -1 ? '?' : '&';
487        query_url += u + query_string;
488    }
489    if (gd_current_query == map_canvas_var + '-' + query_url) {
490        jQuery('#' + map_canvas_var + '_loading_div').hide();
491    } //dont run again
492    else {
493        gd_current_query = map_canvas_var + '-' + query_url;
494        jQuery.ajax({
495            type: "GET",
496            url: query_url,
497            dataType: "json",
498            success: function(data) {
499                jQuery('#' + map_canvas_var + '_loading_div').hide();
500                parse_marker_jason(data, map_canvas_var, keep_markers);
501            },
502            error: function(xhr, textStatus, errorThrown) {
503                console.log(errorThrown);
504            }
505        });
506    }
507    return;
508} // End  map_ajax_search
509
510// read the data, create markers
511var bounds = '';
512
513function parse_marker_jason(json, map_canvas_var, keep_markers) {
514    if (window.gdMaps == 'osm') {
515        parse_marker_jason_osm(json, map_canvas_var, keep_markers);
516        return;
517    }
518    var options = eval(map_canvas_var);
519    if (jQuery('#' + map_canvas_var).val() == '') { // if map not loaded then load it
520        initMap(map_canvas_var);
521    }
522    jQuery("#" + map_canvas_var).goMap();
523    // get the bounds of the map
524    bounds = new google.maps.LatLngBounds();
525    if (options.marker_cluster) {
526        if (typeof remove_cluster_markers == 'function') {
527            remove_cluster_markers(map_canvas_var)
528        }
529    }
530	var markerReposition = options.enable_marker_cluster_no_reposition;
531	var animation = geodir_params.gMarkerAnimation ? geodir_params.gMarkerAnimation : null;
532	if (animation === true) {
533		animation = google.maps.Animation.DROP;
534	}
535	if (keep_markers) {
536		gd_map_first_load = true;
537		markerReposition = false;
538		if (typeof keepBounds != 'undefined' && keepBounds) {
539			bounds = keepBounds;
540		}
541	} else {
542		// clear old markers
543		jQuery.goMap.clearMarkers();
544		keepBounds = '';
545	}
546
547	// Don't reposition
548	if (geodir_params.gMarkerReposition) {
549		markerReposition = true;
550	}
551
552    // if no markers found, display home_map_nofound div with no search criteria met message
553    if (json.total && parseInt(json.total) > 0) {
554        document.getElementById(map_canvas_var + '_map_nofound').style.display = 'none';
555        var mapcenter = new google.maps.LatLng(options.latitude, options.longitude);
556        list_markers(json, map_canvas_var, animation);
557        var center = bounds.getCenter();
558        if (options.autozoom && parseInt(json.total) > 1) {
559            if (markerReposition) {} //don't reposition after load
560            else {
561                jQuery.goMap.map.fitBounds(bounds);
562            }
563        } else {
564            if (markerReposition) {} //dont reposition after load
565            else {
566                if (options.autozoom && parseInt(json.total) == 1) {
567                    jQuery.goMap.map.setZoom(13);
568                }
569                jQuery.goMap.map.setCenter(center);
570            }
571        }
572        if (jQuery.goMap.map.getZoom() > parseInt(options.maxZoom)) {
573            jQuery.goMap.map.setZoom(parseInt(options.maxZoom));
574        }
575		if (!(typeof keepBounds != 'undefined' && keepBounds)) {
576			keepBounds = bounds;
577		}
578    } else {
579        document.getElementById(map_canvas_var + '_map_nofound').style.display = 'flex';
580        var nLat = options.nomap_lat ? options.nomap_lat : (options.default_lat ? options.default_lat : '39.952484');
581        var nLng = options.nomap_lng ? options.nomap_lng : (options.default_lng ? options.default_lng : '-75.163786');
582        var nZoom = parseInt(options.nomap_zoom) > 0 ? parseInt(options.nomap_zoom) : (parseInt(options.zoom) > 0 ? parseInt(options.zoom) : 11);
583        var mapcenter = new google.maps.LatLng(nLat, nLng);
584        list_markers(json, map_canvas_var);
585        if (markerReposition) {} //dont reposition after load
586        else {
587            jQuery.goMap.map.setCenter(mapcenter);
588            jQuery.goMap.map.setZoom(nZoom);
589        }
590    }
591    if (options.marker_cluster) {
592        if (typeof create_marker_cluster == 'function') {
593            create_marker_cluster(map_canvas_var)
594        }
595    }
596
597    // Add near me marker.
598    geodir_map_show_near_me(options);
599
600    jQuery('#' + map_canvas_var + '_loading_div').hide();
601    jQuery("body").trigger("map_show", map_canvas_var);
602}
603
604function list_markers(json, map_canvas_var, animation) {
605    var map_options = eval(map_canvas_var);
606    var total = parseInt(json.total);
607    if (total > 0 && json.items) {
608        var baseurl, content_url, icons, icon, icon_url;
609        baseurl = json.baseurl;
610        content_url = json.content_url;
611        icons = json.icons;
612        for (var i = 0; i < total; i++) {
613            marker = json.items[i];
614            if (marker['i'] && icons && icons[marker['i']]['i']) {
615                icon = icons[marker['i']];
616                if (icon['i']) {
617                    icon_url = icon['i'];
618                    if (!(icon_url.indexOf("http://") === 0 || icon_url.indexOf("https://") === 0)) {
619                        icon_url = icon_url.indexOf("plugins/") === 0 || icon_url.indexOf("plugins/") > 0 ? content_url + icon_url : baseurl + '/' + icon_url
620                    }
621                    marker['icon'] = icon_url;
622                    marker['w'] = icon['w'];
623                    marker['h'] = icon['h'];
624                    if ( icon['a'] ) {
625                        marker['alt'] = icon['a'];
626                    }
627                }
628            }
629            if (marker && !marker.animation && animation) {
630                marker['animation'] = animation;
631            }
632            if (map_options.map_type == 'post' && i == 0) {
633                jQuery('#' + map_canvas_var).data('lat', marker.lt);
634                jQuery('#' + map_canvas_var).data('lng', marker.ln);
635            }
636            var marker = create_marker(marker, map_canvas_var);
637        }
638        if (window.gdMaps == 'osm') {
639            jQuery.goMap.map.addLayer(jQuery.goMap.gdlayers);
640            try {
641                if (jQuery.goMap.gdUmarker) {
642                    bounds.extend(jQuery.goMap.gdUmarker.getLatLng());
643                }
644            } catch (e) {}
645        }
646    }
647}
648
649function geodir_htmlEscape(str) {
650    return String(str)
651        .replace(/&prime;/g, "'")
652        .replace(/&frasl;/g, '/')
653        .replace(/&ndash;/g, '-')
654        .replace(/&ldquo;/g, '"')
655        .replace(/&gt;/g, '>')
656        .replace(/&quot;/g, '"')
657        .replace(/&apos;/g, "'")
658        .replace(/&amp;quot;/g, '"')
659        .replace(/&amp;apos;/g, "'");
660}
661
662// create the marker and set up the event window
663function create_marker(item, map_canvas) {
664    if (window.gdMaps == 'osm') {
665        return create_marker_osm(item, map_canvas);
666    }
667    var map_options = eval(map_canvas);
668    jQuery("#" + map_canvas).goMap();
669    gd_infowindow = (typeof google !== 'undefined' && typeof google.maps !== 'undefined') ? new google.maps.InfoWindow({
670        maxWidth: 200
671    }) : null;
672    if (item.lt && item.ln) {
673        var marker_id, title, icon, cs, isSvg, resize = false;
674        marker_id = item['m'];
675        title = geodir_htmlEscape(item['t']);
676        cs = item['cs'];
677        icon = item['icon'] ? item['icon'] : geodir_params.default_marker_icon;
678        iconW = item['w'] ? parseFloat(item['w']) : 0;
679        iconH = item['h'] ? parseFloat(item['h']) : 0;
680        iconMW = geodir_params.marker_max_width ? parseFloat(geodir_params.marker_max_width) : 0;
681        iconMH = geodir_params.marker_max_height ? parseFloat(geodir_params.marker_max_height) : 0;
682        isSvg = icon && icon.substr((icon.lastIndexOf('.')+1)).toLowerCase() == 'svg' ? true : false;
683        /* Some svg files has dimensions with different unit */
684        if (geodir_params.resize_marker && ( iconW < iconMW || iconH < iconMH ) && isSvg) {
685            iconW = iconW * 10;
686            iconH = iconH * 10;
687        }
688        if (geodir_params.resize_marker && iconW > 5 && iconH > 5 && ((iconMW > 5 && iconW > iconMW) || (iconMH > 5 && iconH > iconMH))) {
689            resizeW = iconW;
690            resizeH = iconH;
691
692            if (iconMH > 5 && resizeH > iconMH) {
693                _resizeH = iconMH;
694                _resizeW = Math.round(((_resizeH * resizeW) / resizeH) * 10) / 10;
695
696                resizeW = _resizeW;
697                resizeH = _resizeH;
698                resize = true;
699            }
700
701            if (iconMW > 5 && resizeW > iconMW) {
702                _resizeW = iconMW;
703                _resizeH = Math.round(((_resizeW * resizeH) / resizeW) * 10) / 10;
704
705                resizeW = _resizeW;
706                resizeH = _resizeH;
707                resize = true;
708            }
709            if (resize && resizeW > 5 && resizeH > 5) {
710                icon = {
711                    url: icon,
712                    scaledSize: new google.maps.Size(resizeW, resizeH),
713                    origin: new google.maps.Point(0, 0),
714                    anchor: new google.maps.Point((Math.round(resizeW / 2)), resizeH)
715                };
716            }
717        }
718        if (isSvg && !resize && iconW > 5 && iconH > 5) {
719            icon = {
720                url: icon,
721                scaledSize: new google.maps.Size(iconW, iconH),
722                origin: new google.maps.Point(0, 0),
723                anchor: new google.maps.Point((Math.round(iconW / 2)), iconH)
724            };
725        }
726        var latlng = new google.maps.LatLng(item.lt, item.ln);
727        var marker = jQuery.goMap.createMarker({
728            id: marker_id,
729            title: title,
730            position: latlng,
731            visible: true,
732            clickable: true,
733            icon: icon,
734            label: cs,
735            zIndex: (item.zIndex ? item.zIndex : 0),
736            zIndexOrg: (item.zIndexOrg ? item.zIndexOrg : 0),
737            animation: (item.animation ? item.animation : null)
738        });
739        bounds.extend(latlng);
740        // Adding a click event to the marker
741        google.maps.event.addListener(marker, 'spider_click', function() { // 'click' => normal, 'spider_click' => Overlapping Marker Spiderfier
742            var marker_url = map_options.map_marker_ajax_url;
743            is_zooming = true;
744            jQuery("#" + map_canvas).goMap();
745            var preview_query_str = '';
746            if (item.post_preview) {
747                preview_query_str = '&post_preview=' + item.post_preview;
748            }
749            marker_url = marker_url + '' + item.m;
750            post_data = marker_url.indexOf('?') === -1 ? '?' : '&';
751            post_data += '_wpnonce=' + map_options._wpnonce;
752            if (map_options.bubble_size) {
753                post_data += '&small=1';
754            }
755            if (map_options.map_marker_url_params) {
756                post_data += map_options.map_marker_url_params;
757            }
758            post_data += '&_gdmap=google';
759            var loading = '<div id="map_loading" class="p-2 text-center"><i class="fas fa-spinner fa-spin" aria-hidden="true"></i></div>';
760            gd_infowindow.open(jQuery.goMap.map, marker);
761            gd_infowindow.setContent(loading);
762            jQuery.ajax({
763                type: "GET",
764                url: marker_url + post_data,
765                cache: false,
766                dataType: "json",
767                error: function(xhr, error) {
768                    alert(error);
769                },
770                success: function(response) {
771                    jQuery("#" + map_canvas).goMap();
772                    html = typeof response == 'object' && response.html ? geodir_htmlEscape(response.html) : '';
773                    gd_infowindow.setContent(html);
774                    gd_infowindow.open(jQuery.goMap.map, marker);
775                    setTimeout(function() {
776                        jQuery(document.body).trigger('geodir_map_infowindow_open', [{
777                            map: 'google',
778                            canvas: map_canvas,
779                            content: html
780                        }]);
781                    }, 100);
782                    // give the map 1 second to reposition before allowing it to reload
783                    setTimeout(function() {
784                        is_zooming = false;
785                    }, 1000);
786                }
787            });
788            return;
789        });
790        // Overlapping Marker Spiderfier
791        jQuery.goMap.oms.addMarker(marker);
792        // Adding a visible_changed event to the marker
793        google.maps.event.addListener(marker, 'visible_changed', function() {
794            gd_infowindow.close(jQuery.goMap.map, marker);
795        });
796        return true;
797    } else {
798        //no lat & long, return no marker
799        return false;
800    }
801}
802
803function geodir_fix_marker_pos(map_canvas_var) {
804    // Reference to the DIV that wraps the bottom of infowindow
805    if (window.gdMaps == 'osm') {
806        var iwOuter = jQuery('#' + map_canvas_var + ' .leaflet-popup-content-wrapper');
807    } else {
808        var iwOuter = jQuery('#' + map_canvas_var + ' .gm-style-iw');
809    }
810
811    var iwBackground = iwOuter.parent();
812    org_height = iwBackground.height();
813    if (window.gdMaps == 'osm') {
814        var mainH = jQuery('#' + map_canvas_var).height();
815        org_height = mainH < org_height ? mainH : org_height;
816        org_height -= (org_height * 0.10);
817    }
818    //jQuery('#' + map_canvas_var + ' .geodir-bubble_desc').attr('style', 'height:' + org_height + 'px !important');
819}
820
821function openMarker(map_canvas, id) {
822    if (!window.gdMaps) {
823        return;
824    }
825
826    jQuery("#" + map_canvas).goMap();
827
828    if (jQuery('.stickymap').legnth) {} else {
829        mTag = false;
830        if (jQuery(".geodir-sidebar-wrap .stick_trigger_container").offset()) {
831            mTag = jQuery(".geodir-sidebar-wrap .stick_trigger_container").offset().top;
832        } else if (jQuery(".stick_trigger_container").offset()) {
833            mTag = jQuery(".stick_trigger_container").offset().top;
834        }
835        if (mTag) {
836            jQuery('html,body').animate({
837                scrollTop: mTag
838            }, 'slow');
839        }
840    }
841    try {
842        if (window.gdMaps == 'google') {
843            google.maps.event.trigger(jQuery.goMap.mapId.data(id), 'spider_click');
844        } else if (window.gdMaps == 'osm') {
845            jQuery.goMap.gdlayers.eachLayer(function(marker) {
846                if (id && marker.options.id == id) {
847                    marker.fireEvent('spider_click');
848                }
849            });
850        }
851    } catch (e) {
852        console.log(e.message);
853    }
854}
855
856function animate_marker(map_canvas, id) {
857    jQuery("#" + map_canvas).goMap();
858    try {
859        if (window.gdMaps == 'google') {
860            if (jQuery.goMap.mapId.data(id) != null) {
861                var anim = geodir_params.markerAnimation;
862                if (anim == 'drop' || anim == 'DROP') {
863                    _anim = google.maps.Animation.DROP;
864                } else if (anim == 'null' || anim == 'none' || anim == null || anim == '') {
865                    _anim = null;
866                } else {
867                    _anim = google.maps.Animation.BOUNCE;
868                }
869                jQuery.goMap.mapId.data(id).setAnimation(_anim);
870            }
871        } else if (window.gdMaps == 'osm') {
872            jQuery.goMap.gdlayers.eachLayer(function(marker) {
873                if (id && marker.options.id == id) {
874                    if (!jQuery(marker._icon).hasClass('gd-osm-marker-bounce')) {
875                        jQuery(marker._icon).addClass('gd-osm-marker-bounce');
876                    }
877                }
878            });
879        }
880    } catch (e) {
881        console.log(e.message);
882    }
883}
884
885function stop_marker_animation(map_canvas, id) {
886    jQuery("#" + map_canvas).goMap();
887    try {
888        if (window.gdMaps == 'google') {
889            if (jQuery.goMap.mapId.data(id) != null) {
890                jQuery.goMap.mapId.data(id).setAnimation(null);
891            }
892        } else if (window.gdMaps == 'osm') {
893            jQuery.goMap.gdlayers.eachLayer(function(marker) {
894                if (id && marker.options.id == id) {
895                    jQuery(marker._icon).removeClass('gd-osm-marker-bounce');
896                }
897            });
898        }
899    } catch (e) {
900        console.log(e.message);
901    }
902}
903
904function geodir_map_sticky(map_options) {
905    if (!window.gdMaps) {
906        return;
907    }
908    var cstatus = '';
909    var optionsname = map_options;
910    map_options = eval(map_options);
911
912    // set if the map should be hidden by default
913    if (geodir_is_localstorage()) {
914        cstatus = localStorage.getItem("gd_sticky_map");
915        if (cstatus == 'shide') {
916            jQuery('body').addClass('stickymap_hide');
917        }
918    }
919
920    if (map_options.sticky && jQuery(window).width() > 1250) {
921        jQuery.fn.scrollBottom = function() {
922            return this.scrollTop() + this.height();
923        };
924        var content = jQuery(".geodir-sidebar-wrap").scrollBottom();
925        var stickymap = jQuery("#sticky_map_" + optionsname + "").scrollBottom();
926        var catcher = jQuery('#catcher_' + optionsname + '');
927        var sticky = jQuery('#sticky_map_' + optionsname + '');
928        var map_parent = sticky.parent();
929        var sticky_show_hide_trigger = sticky.closest('.stick_trigger_container').find('.trigger_sticky');
930        var mapheight = jQuery("#sticky_map_" + optionsname + "").height();
931        var widthpx = sticky.width();
932        var widthmap = map_options.width;
933
934        if (widthmap.indexOf('%') != -1) {
935            jQuery('.main_map_wrapper', sticky).width('100%');
936            jQuery('.geodir_marker_cluster', sticky).width('100%');
937        }
938
939        jQuery(window).scroll(function() {
940            jQuery("#" + optionsname + "").goMap(map_options);
941
942            // get the bounds of the map
943            if (window.gdMaps == 'osm') {
944                bounds = new L.LatLngBounds([]);
945            } else {
946                bounds = new google.maps.LatLngBounds();
947            }
948
949            var wheight = jQuery(window).height();
950            var wScrTop = jQuery(window).scrollTop();
951            var maxScr = 0;
952            if (jQuery('.geodir-category-list-view').length) {
953                maxScr = parseFloat(jQuery('.geodir-category-list-view:last').offset().top) + parseFloat(jQuery('.geodir-category-list-view:last').innerHeight()) - 50;
954            }
955            if (jQuery('.elementor-posts').length) {
956                var _maxScr = parseFloat(jQuery('.elementor-posts:last').offset().top) + parseFloat(jQuery('.elementor-posts:last').innerHeight()) - 50;
957                if (_maxScr > maxScr) {
958                    maxScr = _maxScr;
959                }
960            }
961            if (maxScr < catcher.offset().top) {
962                maxScr = 0;
963            }
964            var noSticky = maxScr > 0 && wScrTop > maxScr && wScrTop > catcher.offset().top ? true : false;
965
966            if (wScrTop >= catcher.offset().top && !noSticky) {
967                if (!sticky.hasClass('stickymap')) {
968                    sticky.addClass('stickymap');
969                    /// sticky.hide();
970                    sticky.appendTo('body');
971                    sticky.removeClass('position-relative').addClass('position-fixed');
972                    sticky.css({
973                        'position': 'fixed',
974                        'right': '0',
975                        'border': '1px solid red'
976                    });
977                    sticky.css({
978                        'top': '25%',
979                        'width': (widthpx + 2)
980                    });
981                    catcher.css({
982                        'height': mapheight
983                    });
984
985                    if (geodir_is_localstorage()) {
986                        cstatus = localStorage.getItem("gd_sticky_map");
987                    }
988                    window.dispatchEvent(new Event('resize')); // OSM does not work with the jQuery trigger so we do it old skool.
989                }
990                sticky_show_hide_trigger.removeClass('position-relative').addClass('position-fixed');
991                sticky_show_hide_trigger.css({
992                    'top': '25%',
993                    'position': 'fixed',
994                    'right': '0'
995                });
996                sticky_show_hide_trigger.show();
997            }
998
999            if (wScrTop < catcher.offset().top || noSticky) {
1000                if (sticky.hasClass('stickymap')) {
1001                    sticky.appendTo(map_parent);
1002                    sticky.hide();
1003                    sticky.removeClass('stickymap');
1004                    sticky.removeClass('position-fixed').addClass('position-relative');
1005                    sticky.css({
1006                        'position': 'relative',
1007                        'border': 'none',
1008                        'top': '0',
1009                        'width': widthmap
1010                    });
1011                    sticky.fadeIn('slow');
1012                    catcher.css({
1013                        'height': '0'
1014                    });
1015                    sticky_show_hide_trigger.removeClass('triggeroff_sticky');
1016                    sticky_show_hide_trigger.addClass('triggeron_sticky');
1017                    sticky_show_hide_trigger.removeClass('position-fixed').addClass('position-relative');
1018                    window.dispatchEvent(new Event('resize')); // OSM does not work with the jQuery trigger so we do it old skool.
1019                }
1020                sticky_show_hide_trigger.hide();
1021            }
1022        });
1023        jQuery(window).on("resize",function() {
1024            jQuery(window).scroll();
1025        });
1026
1027    } // sticky if end
1028}
1029var rendererOptions = {
1030    draggable: true
1031};
1032var directionsDisplay = (typeof google !== 'undefined' && typeof google.maps !== 'undefined' && typeof google.maps.DirectionsRenderer !== 'undefined') ? new google.maps.DirectionsRenderer(rendererOptions) : {};
1033var directionsService = (typeof google !== 'undefined' && typeof google.maps !== 'undefined' && typeof google.maps.DirectionsService !== 'undefined') ? new google.maps.DirectionsService() : {};
1034var renderedDirections = [];
1035
1036function geodirFindRoute(map_canvas) {
1037    var map_options, destLat, destLng, $wrap;
1038    initMap(map_canvas);
1039    map_options = eval(map_canvas);
1040    destLat = jQuery('#' + map_canvas).data('lat');
1041    destLng = jQuery('#' + map_canvas).data('lng');
1042    $wrap = jQuery('#' + map_canvas).closest('.geodir-map-wrap');
1043    if (window.gdMaps == 'osm') {
1044        try {
1045            var control = L.Routing.control({
1046                waypoints: [
1047                    L.latLng(destLat, destLng)
1048                ],
1049                routeWhileDragging: true,
1050                geocoder: L.Control.Geocoder.nominatim(),
1051                language: geodir_params.osmRouteLanguage,
1052                units: geodir_params.osmRouteUnits,
1053                waypointNameFallback: function(latLng) {
1054                    function zeroPad(n) {
1055                        n = Math.round(n);
1056                        return n < 10 ? '0' + n : n;
1057                    }
1058
1059                    function hexagecimal(p, pos, neg) {
1060                        var n = Math.abs(p),
1061                            degs = Math.floor(n),
1062                            mins = (n - degs) * 60,
1063                            secs = (mins - Math.floor(mins)) * 60,
1064                            frac = Math.round((secs - Math.floor(secs)) * 100);
1065                        return (n >= 0 ? pos : neg) + degs + '°' + zeroPad(mins) + '\'' + zeroPad(secs) + '.' + zeroPad(frac) + '"';
1066                    }
1067
1068                    return hexagecimal(latLng.lat, 'N', 'S') + ' ' + hexagecimal(latLng.lng, 'E', 'W');
1069                }
1070            });
1071            var cExists = typeof jQuery.goMap.map._container != 'undefined' && jQuery('.leaflet-control.leaflet-routing-container', jQuery.goMap.map._container).length ? true : false;
1072            if (!cExists) {
1073                control.addTo(jQuery.goMap.map);
1074            }
1075
1076            L.Routing.errorControl(control).addTo(jQuery.goMap.map);
1077
1078            var $routing = jQuery('#' + map_canvas + ' .leaflet-routing-geocoders .leaflet-routing-search-info');
1079            if (!$routing.find('#' + map_canvas + '_mylocation').length) {
1080                $routing.append('<span title="' + geodir_params.geoMyLocation + '" onclick="gdMyGeoDirection(' + map_canvas + ');" id="' + map_canvas + '_mylocation" class="gd-map-mylocation c-pointer ml-1 ms-1"><i class="fas fa-crosshairs" aria-hidden="true"></i></span>');
1081            }
1082        } catch (e) {
1083            console.log(e.message);
1084        }
1085    } else if (window.gdMaps == 'google') {
1086        // Direction map
1087        var rendererOptions = {
1088            draggable: true
1089        };
1090        if (renderedDirections.length) {
1091            for(var i in renderedDirections) {
1092                renderedDirections[i].setMap(null);
1093            }
1094        }
1095        var directionsDisplay = (typeof google !== 'undefined' && typeof google.maps !== 'undefined') ? new google.maps.DirectionsRenderer(rendererOptions) : {};
1096        var directionsService = (typeof google !== 'undefined' && typeof google.maps !== 'undefined') ? new google.maps.DirectionsService() : {};
1097        directionsDisplay.setMap(jQuery.goMap.map);
1098        directionsDisplay.setPanel(document.getElementById(map_canvas + "_directionsPanel"));
1099        renderedDirections.push(directionsDisplay);
1100        google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
1101            geodirComputeTotalDistance(directionsDisplay.directions, map_canvas);
1102        });
1103        jQuery('#directions-options', $wrap).show();
1104        var from_address = document.getElementById(map_canvas + '_fromAddress').value;
1105        var request = {
1106            origin: from_address,
1107            destination: destLat + ',' + destLng,
1108            travelMode: gdGetTravelMode($wrap),
1109            unitSystem: gdGetTravelUnits($wrap)
1110        };
1111        directionsService.route(request, function(response, status) {
1112            if (status == google.maps.DirectionsStatus.OK) {
1113                jQuery('#' + map_canvas + '_directionsPanel', $wrap).html('');
1114                directionsDisplay.setDirections(response);
1115            } else {
1116                alert(geodir_params.address_not_found_on_map_msg + from_address);
1117            }
1118        });
1119    }
1120}
1121
1122function gdGetTravelMode($wrap) {
1123    var mode = jQuery('#travel-mode', $wrap).val();
1124    if (mode == 'driving') {
1125        return google.maps.DirectionsTravelMode.DRIVING;
1126    } else if (mode == 'walking') {
1127        return google.maps.DirectionsTravelMode.WALKING;
1128    } else if (mode == 'bicycling') {
1129        return google.maps.DirectionsTravelMode.BICYCLING;
1130    } else if (mode == 'transit') {
1131        return google.maps.DirectionsTravelMode.TRANSIT;
1132    } else {
1133        return google.maps.DirectionsTravelMode.DRIVING;
1134    }
1135}
1136
1137function gdGetTravelUnits($wrap) {
1138    var mode = jQuery('#travel-units', $wrap).val();
1139    if (mode == 'kilometers') {
1140        return google.maps.DirectionsUnitSystem.METRIC;
1141    } else {
1142        return google.maps.DirectionsUnitSystem.IMPERIAL;
1143    }
1144}
1145
1146function geodirComputeTotalDistance(result, map_canvas) {
1147    var total = 0;
1148    var myroute = result.routes[0];
1149    for (i = 0; i < myroute.legs.length; i++) {
1150        total += myroute.legs[i].distance.value;
1151    }
1152    totalk = total / 1000
1153    totalk_round = Math.round(totalk * 100) / 100
1154    totalm = total / 1609.344
1155    totalm_round = Math.round(totalm * 100) / 100
1156    //document.getElementById(map_canvas+"_directionsPanel").innerHTML = "<p>Total Distance: <span id='totalk'>" + totalk_round + " km</span></p><p>Total Distance: <span id='totalm'>" + totalm_round + " miles</span></p>";
1157}
1158jQuery(function($) {
1159    setGeodirMapSize(false);
1160    $(window).on("resize",function() {
1161        setGeodirMapSize(true);
1162    });
1163})
1164
1165function setGeodirMapSize(resize) {
1166    var isAndroid = navigator.userAgent.toLowerCase().indexOf("android") > -1 ? true : false;
1167    var dW = parseInt(jQuery(window).width());
1168    var dH = parseInt(jQuery(window).height());
1169    if (GeodirIsiPhone() || (isAndroid && (((dW > dH && dW == 640 && dH == 360) || (dH > dW && dW == 360 && dH == 640)) || ((dW > dH && dW == 533 && dH == 320) || (dH > dW && dW == 320 && dH == 533)) || ((dW > dH && dW == 960 && dH == 540) || (dH > dW && dW == 540 && dH == 960))))) {
1170        jQuery(document).find('.geodir_map_container').each(function() {
1171            jQuery(this).addClass('geodir-map-iphone');
1172        });
1173    } else {
1174        jQuery(document).find('.geodir_map_container').each(function() {
1175            var $this = this;
1176            var gmcW = parseInt(jQuery($this).width());
1177            var gmcH = parseInt(jQuery($this).height());
1178            if (gmcW >= 400 && gmcH >= 350) {
1179                jQuery($this).removeClass('geodir-map-small').addClass('geodir-map-full');
1180            } else {
1181                jQuery($this).removeClass('geodir-map-full').addClass('geodir-map-small');
1182            }
1183        });
1184        if (resize) {
1185            jQuery(document).find('.geodir_map_container_fullscreen').each(function() {
1186                var $this = this;
1187                var gmcW = parseInt(jQuery(this).find('.gm-style').width());
1188                var gmcH = parseInt(jQuery(this).find('.gm-style').height());
1189                if (gmcW >= 400 && gmcH >= 370) {
1190                    jQuery($this).removeClass('geodir-map-small').addClass('geodir-map-full');
1191                } else {
1192                    jQuery($this).removeClass('geodir-map-full').addClass('geodir-map-small');
1193                }
1194            });
1195        }
1196    }
1197}
1198
1199function GeodirIsiPhone() {
1200    if ((navigator.userAgent.toLowerCase().indexOf("iphone") > -1) || (navigator.userAgent.toLowerCase().indexOf("ipod") > -1) || (navigator.userAgent.toLowerCase().indexOf("ipad") > -1)) {
1201        return true;
1202    } else {
1203        return false;
1204    }
1205}
1206
1207function initMapOSM(map_options) {
1208    map_options = eval(map_options);
1209    map_options.zoom = parseInt(map_options.zoom);
1210    var options = map_options;
1211    var pscaleFactor;
1212    var pstartmin;
1213    var ajax_url = options.ajax_url;
1214    var token = options.token;
1215    var search_string = options.token;
1216    var mm = 0; // marker array
1217    var maptype = options.maptype;
1218    var zoom = options.zoom;
1219    var latitude = options.latitude;
1220    var longitude = options.longitude;
1221    var maxZoom = options.maxZoom;
1222    var etype = options.etype;
1223    var autozoom = options.autozoom;
1224    var scrollwheel = options.scrollwheel;
1225    var fullscreenControl = options.fullscreenControl;
1226    var streetview = options.streetViewControl;
1227    var bubble_size = options.bubble_size;
1228    var map_canvas = options.map_canvas;
1229    var enable_map_direction = options.enable_map_direction;
1230    var enable_cat_filters = options.enable_cat_filters;
1231    var marker_cluster = options.marker_cluster;
1232    options.token = '68f48005e256696074e1da9bf9f67f06';
1233    options.navigationControlOptions = {
1234        position: 'topleft'
1235    };
1236
1237    // Create map
1238    jQuery("#" + map_canvas).goMap(options);
1239
1240    var styles = [{
1241        featureType: "poi.business",
1242        elementType: "labels",
1243        stylers: [{
1244            visibility: "off"
1245        }]
1246    }];
1247
1248    if (typeof geodir_custom_map_style !== 'undefined') {
1249        styles = geodir_custom_map_style;
1250    }
1251
1252    /* custom google map style */
1253    if (typeof options.mapStyles != 'undefined') {
1254        try {
1255            var mapStyles = JSON.parse(options.mapStyles);
1256            if (typeof mapStyles == 'object' && mapStyles) {
1257                styles = mapStyles;
1258            }
1259        } catch (err) {
1260            console.log(err.message);
1261        }
1262    }
1263
1264    /* custom google map style */ // TODO for styles
1265    //jQuery.goMap.map = L.Util.setOptions(jQuery.goMap.map, { styles: styles });
1266
1267    L.DomEvent.addListener(jQuery.goMap.map, 'moveend', function() {
1268        if (eval(map_canvas).marker_cluster_server) {
1269            if (gd_map_first_load) { // first load do nothing
1270                gd_map_first_load = false;
1271                eval(map_canvas).enable_marker_cluster_no_reposition = true;
1272            } else {
1273                if (is_zooming) {} else {
1274                    is_zooming = true;
1275                    build_map_ajax_search_param(map_canvas, false, false, true);
1276                    is_zooming = false;
1277                }
1278            }
1279        }
1280    });
1281
1282    // maxMap
1283    var btnCSS = jQuery("." + map_canvas + "_TopLeft").attr("style");
1284    jQuery("." + map_canvas + "_TopLeft").attr("style", "margin-top: 85px !important;" + btnCSS);
1285
1286    var maxMap = document.getElementById(map_canvas + '_triggermap');
1287
1288    if (!jQuery(maxMap).hasClass('gd-triggered-map')) { // skip multiple click listener after reload map via ajax
1289        jQuery(maxMap).addClass('gd-triggered-map');
1290        L.DomEvent.addListener(maxMap, 'click', gdMaxMapOSM);
1291    }
1292
1293    function gdMaxMapOSM() {
1294
1295        if (jQuery('body').hasClass('body_fullscreen')) {
1296            jQuery('#catcher_' + map_canvas + '').removeClass('position-fixed');
1297            jQuery(window).scroll();
1298            jQuery('#placeholder_' + map_canvas).after(jQuery(gd_fullscreen_parent));
1299            jQuery('#placeholder_' + map_canvas).remove();
1300        } else {
1301            jQuery('#catcher_' + map_canvas + '').addClass('position-fixed');
1302            jQuery(window).scroll();
1303            gd_fullscreen_parent = jQuery('#' + map_canvas).parents(".stick_trigger_container"); //.parent();
1304            jQuery(gd_fullscreen_parent).before('<div id="placeholder_' + map_canvas + '"></div>');
1305            jQuery(gd_fullscreen_parent).prependTo("body");
1306        }
1307
1308        // new
1309        if (gd_toggle_bsui) {
1310            jQuery('html').toggleClass('bsui');
1311        }
1312        jQuery('html').attr('style', function(index, attr) {
1313            return attr == 'margin-top:0 !important;' ? '' : 'margin-top:0 !important;';
1314        });
1315        jQuery('body').toggleClass('body_fullscreen overflow-hidden');
1316        jQuery('#' + map_canvas + ', #sticky_map_' + map_canvas + ',#' + map_canvas + '_wrapper,#' + map_canvas + '_loading_div,#' + map_canvas + '_map_nofound,#' + map_canvas + '_map_notloaded').toggleClass('vw-100 vh-100');
1317        jQuery('#' + map_canvas + '_triggermap i, .geodir-map-directions-wrap, #wpadminbar').toggleClass('d-none');
1318
1319        window.setTimeout(function() {
1320            setGeodirMapSize(true);
1321            jQuery.goMap.map._onResize();
1322            jQuery.goMap.map.invalidateSize();
1323            window.dispatchEvent(new Event('resize'));
1324        }, 100);
1325    }
1326
1327    // Overlapping Marker Spiderfier LeafLet
1328
1329    jQuery.goMap.oms.addListener('spiderfy', function(markers) {
1330        jQuery.goMap.map.closePopup();
1331    });
1332
1333    window.oms = jQuery.goMap.oms;
1334}
1335
1336function parse_marker_jason_osm(json, map_canvas_var, keep_markers) {
1337    var options = eval(map_canvas_var);
1338    if (jQuery('#' + map_canvas_var).val() == '') { // if map not loaded then load it
1339        initMapOSM(map_canvas_var);
1340    } else {
1341        jQuery("#" + map_canvas_var).goMap();
1342    }
1343    // get the bounds of the map
1344    bounds = new L.LatLngBounds([]);
1345	var markerReposition = options.enable_marker_cluster_no_reposition;
1346    if (keep_markers) {
1347		gd_map_first_load = true;
1348		markerReposition = false;
1349		if (typeof keepBounds != 'undefined' && keepBounds) {
1350			bounds = keepBounds;
1351		}
1352	} else {
1353		// clear old markers
1354		jQuery.goMap.clearMarkers();
1355		keepBounds = '';
1356	}
1357	// Don't reposition
1358	if (geodir_params.gMarkerReposition) {
1359		markerReposition = true;
1360	}
1361    // if no markers found, display home_map_nofound div with no search criteria met message
1362    if (json.total && parseInt(json.total) > 0) {
1363        document.getElementById(map_canvas_var + '_map_nofound').style.display = 'none';
1364        list_markers(json, map_canvas_var);
1365        var center = bounds.getCenter();
1366        if (options.autozoom && parseInt(json.total) > 1) {
1367            if (markerReposition) {
1368                //dont reposition after load
1369            } else {
1370                jQuery.goMap.map.fitBounds(bounds);
1371            }
1372        } else {
1373            if (markerReposition) {
1374                //dont reposition after load
1375            } else {
1376                setZoom = jQuery.goMap.map.getZoom();
1377                if (options.autozoom && parseInt(json.total) == 1) {
1378                    setZoom = 13;
1379                }
1380                jQuery.goMap.map.setView(center, setZoom);
1381            }
1382        }
1383        if (jQuery.goMap.map.getZoom() > parseInt(options.maxZoom)) {
1384            jQuery.goMap.map.setZoom(parseInt(options.maxZoom));
1385        }
1386		if (!(typeof keepBounds != 'undefined' && keepBounds)) {
1387			keepBounds = bounds;
1388		}
1389    } else {
1390        document.getElementById(map_canvas_var + '_map_nofound').style.display = 'flex';
1391        var nLat = options.nomap_lat ? options.nomap_lat : (options.default_lat ? options.default_lat : '39.952484');
1392        var nLng = options.nomap_lng ? options.nomap_lng : (options.default_lng ? options.default_lng : '-75.163786');
1393        var nZoom = parseInt(options.nomap_zoom) > 0 ? parseInt(options.nomap_zoom) : (parseInt(options.zoom) > 0 ? parseInt(options.zoom) : 11);
1394        var mapcenter = new L.latLng(nLat, nLng);
1395        list_markers(json, map_canvas_var);
1396        if (markerReposition) {} //dont reposition after load
1397        else {
1398            jQuery.goMap.map.setView(mapcenter, nZoom);
1399        }
1400    }
1401
1402    // Add near me marker.
1403    geodir_map_show_near_me_osm(options);
1404
1405    jQuery('#' + map_canvas_var + '_loading_div').hide();
1406    jQuery("body").trigger("map_show", map_canvas_var);
1407}
1408
1409function create_marker_osm(item, map_canvas) {
1410    var options = eval(map_canvas);
1411    jQuery("#" + map_canvas).goMap();
1412    if (item.lt && item.ln) {
1413        var marker_id, title, icon, iconW, iconH, cs;
1414        marker_id = item['m'];
1415        title = geodir_htmlEscape(item['t']);
1416        cs = item['cs'];
1417        icon = item['icon'] ? item['icon'] : geodir_params.default_marker_icon;
1418        iconW = item['w'] ? item['w'] : geodir_params.default_marker_w;
1419        iconH = item['h'] ? item['h'] : geodir_params.default_marker_h;
1420        iconMW = geodir_params.marker_max_width ? parseFloat(geodir_params.marker_max_width) : 0;
1421        iconMH = geodir_params.marker_max_height ? parseFloat(geodir_params.marker_max_height) : 0;
1422        /* Some svg files has dimensions with different unit */
1423        if (geodir_params.resize_marker && ( iconW < iconMW || iconH < iconMH ) && icon.substr((icon.lastIndexOf('.')+1)).toLowerCase() == 'svg') {
1424            iconW = iconW * 10;
1425            iconH = iconH * 10;
1426        }
1427        if (geodir_params.resize_marker && iconW > 5 && iconH > 5 && ((iconMW > 5 && iconW > iconMW) || (iconMH > 5 && iconH > iconMH))) {
1428            resizeW = iconW;
1429            resizeH = iconH;
1430            resize = false;
1431
1432            if (iconMH > 5 && resizeH > iconMH) {
1433                _resizeH = iconMH;
1434                _resizeW = Math.round(((_resizeH * resizeW) / resizeH) * 10) / 10;
1435
1436                resizeW = _resizeW;
1437                resizeH = _resizeH;
1438                resize = true;
1439            }
1440
1441            if (iconMW > 5 && resizeW > iconMW) {
1442                _resizeW = iconMW;
1443                _resizeH = Math.round(((_resizeW * resizeH) / resizeW) * 10) / 10;
1444
1445                resizeW = _resizeW;
1446                resizeH = _resizeH;
1447                resize = true;
1448            }
1449            if (resize && resizeW > 5 && resizeH > 5) {
1450                iconW = resizeW;
1451                iconH = resizeH;
1452            }
1453        }
1454        var coord = new L.latLng(item.lt, item.ln);
1455        var marker = jQuery.goMap.createMarker({
1456            id: marker_id,
1457            title: title,
1458            alt: item.alt ? geodir_htmlEscape(item.alt) : 'marker ' + marker_id,
1459            position: coord,
1460            visible: true,
1461            clickable: true,
1462            icon: icon,
1463            label: cs,
1464            w: iconW,
1465            h: iconH,
1466            clustered: (parseInt(options.marker_cluster) === 1) && typeof item.cs !== 'undefined' ? true : false,
1467            zIndex: (item.zIndex ? item.zIndex : 0),
1468            zIndexOrg: (item.zIndexOrg ? item.zIndexOrg : 0)
1469        });
1470        if ((parseInt(options.marker_cluster) === 1) && cs) {
1471            var labels = cs.split("_");
1472            bounds.extend(new L.latLng(labels[1], labels[2]));
1473            if (labels[1] != labels[3] && labels[2] != labels[4]) {
1474                bounds.extend(new L.latLng(labels[3], labels[4]));
1475            }
1476        } else {
1477            bounds.extend(coord);
1478        }
1479        // Adding a click event to the marker
1480        L.DomEvent.addListener(marker, 'click', function() {
1481            marker.fireEvent('spider_click');
1482        });
1483        L.DomEvent.addListener(marker, 'spider_click', function() {// 'click' => normal, 'spider_click' => Overlapping Marker Spiderfier
1484            var marker_url = options.map_marker_ajax_url;
1485            if (marker.options.clustered) {
1486                jQuery("#" + map_canvas).goMap();
1487                marker.closePopup().unbindPopup();
1488                var fitBounds = false;
1489                if (marker.options.label) {
1490                    var labels = marker.options.label.split("_");
1491                    var newBounds = new L.LatLngBounds([]);
1492                    var lat1 = labels[1];
1493                    var lng1 = labels[2];
1494                    var lat2 = labels[3];
1495                    var lng2 = labels[4];
1496                    newBounds.extend(new L.latLng(lat1, lng1));
1497                    if (lat1 == lat2 && lng1 == lng2) {
1498                        var lat2 = lat2 * 1.00000001;
1499                        var lng2 = lng2 * 1.00000001;
1500                    }
1501                    newBounds.extend(new L.latLng(lat2, lng2));
1502                    jQuery.goMap.map.fitBounds(newBounds);
1503                    bounds = newBounds;
1504                    if (jQuery.goMap.map.getZoom() > parseInt(options.maxZoom)) {
1505                        jQuery.goMap.map.setZoom(parseInt(options.maxZoom));
1506                    }
1507                } else {
1508                    zoom = parseInt(jQuery.goMap.map.getZoom()) + 1 > parseInt(options.maxZoom) && parseInt(options.maxZoom) > 0 ? parseInt(options.maxZoom) : parseInt(jQuery.goMap.map.getZoom()) + 1;
1509                    jQuery.goMap.map.setView(marker.getLatLng(), zoom);
1510                }
1511                return;
1512            } else {
1513                is_zooming = true;
1514                jQuery("#" + map_canvas).goMap();
1515            }
1516            marker_url = marker_url + '' + item.m;
1517            post_data = marker_url.indexOf('?') === -1 ? '?' : '&';
1518            post_data += '_wpnonce=' + options._wpnonce;
1519            if (options.bubble_size) {
1520                post_data += '&small=1';
1521            }
1522            if (options.map_marker_url_params) {
1523                post_data += options.map_marker_url_params;
1524            }
1525            post_data += '&_gdmap=osm';
1526            var loading = '<div id="map_loading" class="p-2 text-center"><i class="fas fa-spinner fa-spin" aria-hidden="true"></i></div>';
1527            var maxH = jQuery("#" + map_canvas).height();
1528            maxH -= (maxH * 0.10) + jQuery(marker._icon).outerHeight() + 20;
1529            marker.closePopup().unbindPopup().bindPopup(loading, {
1530                className: 'gd-osm-bubble',
1531                maxHeight: maxH
1532            }).openPopup();
1533            jQuery.ajax({
1534                type: "GET",
1535                url: marker_url + post_data,
1536                cache: false,
1537                dataType: "json",
1538                error: function(xhr, error) {
1539                    alert(error);
1540                },
1541                success: function(response) {
1542                    jQuery("#" + map_canvas).goMap();
1543                    html = typeof response == 'object' && response.html ? geodir_htmlEscape(response.html) : '';
1544                    marker.bindPopup(html);
1545                    setTimeout(function() {
1546                        jQuery(document.body).trigger('geodir_map_infowindow_open', [{
1547                            map: 'osm',
1548                            canvas: map_canvas,
1549                            content: html
1550                        }]);
1551                    }, 100);
1552                    // give the map 1 second to reposition before allowing it to reload
1553                    setTimeout(function() {
1554                        is_zooming = false;
1555                    }, 1000);
1556                }
1557            });
1558            return;
1559        });
1560        // Overlapping Marker Spiderfier LeafLet
1561        jQuery.goMap.oms.addMarker(marker);
1562        // Adding a visible_changed event to the marker
1563        L.DomEvent.addListener(marker, 'visible_changed', function() {
1564            marker.closePopup();
1565        });
1566        return true;
1567    } else {
1568        //no lat & long, return no marker
1569        return false;
1570    }
1571}
1572
1573function gdMyGeoDirection(map_canvas) {
1574    window.currentMapCanvas = map_canvas;
1575    gd_get_user_position(gdMyGeoPositionSuccess);
1576}
1577
1578function gdMyGeoPositionSuccess(myLat, myLng) {
1579    if (myLat && myLng) {
1580        var geoAddress = myLat + ', ' + myLng;
1581        if (window.gdMaps == 'google' || window.gdMaps == 'osm') {
1582            gdMyGeoGetDirections(geoAddress);
1583        }
1584    }
1585}
1586
1587function gdMyGeoGetDirections(address) {
1588    var map_canvas = window.currentMapCanvas;
1589    if (!address) {
1590        return false;
1591    }
1592    window.gdMyGeo = true;
1593    if (window.gdMaps == 'google') {
1594        jQuery('#' + map_canvas + '_fromAddress').val(address);
1595        geodirFindRoute(map_canvas);
1596    } else if (window.gdMaps == 'osm') {
1597        jQuery('.leaflet-routing-geocoders .leaflet-routing-geocoder:last input').val(address).focus();
1598        setTimeout(function() {
1599            jQuery('.leaflet-routing-geocoders .leaflet-routing-geocoder:last input').trigger({
1600                type: 'keypress',
1601                which: 13,
1602                keyCode: 13
1603            });
1604        }, 1000);
1605    }
1606}
1607
1608function geodir_map_directions_init(map_canvas) {
1609    if (window.gdMaps == 'google') {
1610        try {
1611            // Create the autocomplete object, restricting the search
1612            // to geographical location types.
1613            autocomplete = new google.maps.places.Autocomplete(
1614                /** @type {HTMLInputElement} */
1615                (document.getElementById(map_canvas + '_fromAddress')), {
1616                    types: ['geocode']
1617                });
1618            // When the user selects an address from the dropdown,
1619            // populate the address fields in the form.
1620            google.maps.event.addListener(autocomplete, 'place_changed', function() {
1621                geodirFindRoute(map_canvas);
1622            });
1623        } catch (e) {
1624            console.log(e.message);
1625        }
1626    } else {
1627        jQuery('#' + map_canvas + '_fromAddress, .geodir-map-directions-wrap').hide();
1628        jQuery('.gd-get-directions').hide();
1629        jQuery('.' + map_canvas + '_getdirection').hide();
1630
1631        if (window.gdMaps == 'osm') {
1632            window.setTimeout(function() {
1633                geodirFindRoute(map_canvas);
1634            }, 1000);
1635        }
1636    }
1637}
1638
1639function geodir_map_post_type_terms(options, post_type, query_string) {
1640    var terms_query_url, map_canvas, tick_terms;
1641    terms_query_url = options.map_terms_ajax_url;
1642    map_canvas = options.map_canvas;
1643
1644    jQuery('#' + map_canvas + '_posttype_menu li').removeClass('gd-map-search-pt');
1645    jQuery('#' + map_canvas + '_posttype_menu li#' + post_type).addClass('gd-map-search-pt');
1646
1647    query_string += "&output=terms";
1648    query_string += "&map_canvas=" + map_canvas;
1649    query_string += "&child_collapse=" + jQuery('#' + map_canvas + '_child_collapse').val();
1650
1651    terms = options.terms;
1652    if (terms) {
1653        query_string += "&terms=" + terms;
1654    }
1655    tick_terms = options.tick_terms;
1656    if (tick_terms) {
1657        query_string += "&tick_terms=" + tick_terms;
1658    }
1659
1660    u = terms_query_url.indexOf('?') === -1 ? '?' : '&';
1661    terms_query_url += u + query_string;
1662
1663    jQuery('#' + map_canvas + '_loading_div').show();
1664    jQuery.ajax({
1665        type: "GET",
1666        url: terms_query_url,
1667        dataType: "json",
1668        success: function(data) {
1669            jQuery('#' + map_canvas + '_loading_div').hide();
1670            if (data && data.terms_filter) {
1671                jQuery('#' + map_canvas + '_cat .geodir_toggle').html(data.terms_filter);
1672                geodir_show_sub_cat_collapse_button();
1673                build_map_ajax_search_param(map_canvas, false);
1674            }
1675            return false;
1676        },
1677        error: function(xhr, textStatus, errorThrown) {
1678            jQuery('#' + map_canvas + '_loading_div').hide();
1679            console.log(errorThrown);
1680        }
1681    });
1682    return false;
1683}
1684
1685/**
1686 * Show near me marker on Google map.
1687 */
1688function geodir_map_show_near_me(options) {
1689    var iMarker, oMarker, bDrag;
1690
1691    if (options.nearLat && options.nearLng && options.nearIcon) {
1692        bDrag = options.nearDraggable ? true : false;
1693
1694        iMarker = {
1695            url: options.nearIcon,
1696            size: null,
1697            origin: new google.maps.Point(0, 0),
1698            anchor: new google.maps.Point(8, 8),
1699            scaledSize: new google.maps.Size(17, 17)
1700        };
1701
1702        oMarker = jQuery.goMap.createMarker({
1703            optimized: true,
1704            flat: true,
1705            draggable: bDrag,
1706            id: 'nearme',
1707            title: options.nearTitle,
1708            position: new google.maps.LatLng(options.nearLat, options.nearLng),
1709            visible: true,
1710            clickable: false,
1711            icon: iMarker
1712        });
1713
1714        jQuery.goMap.gdUmarker = oMarker;
1715    }
1716}
1717
1718/**
1719 * Show near me marker on OpenstreetMap.
1720 */
1721function geodir_map_show_near_me_osm(options) {
1722    var oMarker, bDrag;
1723
1724    if (options.nearLat && options.nearLng && options.nearIcon && !jQuery.goMap.gdUmarker) {
1725        bDrag = options.nearDraggable ? true : false;
1726
1727        oMarker = jQuery.goMap.createMarker({
1728            optimized: false,
1729            flat: true,
1730            draggable: bDrag,
1731            id: 'mapme',
1732            title: options.nearTitle,
1733            position: new L.latLng(options.nearLat, options.nearLng),
1734            visible: true,
1735            clickable: false,
1736            addToMap: true,
1737            zIndex: 0
1738        });
1739
1740        oMarker.setIcon(L.divIcon({
1741            iconSize: [17, 17],
1742            iconAnchor: [8.5, 8.5],
1743            className: 'geodir-near-marker',
1744            html: '<div class="geodir-near-marker-wrap"><div class="geodir-near-marker-animate"></div><img class="geodir-near-marker-img" src="' + options.nearIcon + '" /></div>'
1745        }));
1746
1747        jQuery.goMap.gdUmarker = oMarker;
1748    }
1749}

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.