(function($) { "use strict"; var map, mapSidebar, markers, CustomHtmlIcon, group; var markerArray = []; $.extend($.apusThemeCore, { /** * Initialize scripts */ job_map_init: function() { var self = this; if ($('#jobs-google-maps').length) { L.Icon.Default.imagePath = 'wp-content/themes/hirestick/images/'; } setTimeout(function(){ self.mapInit(); }, 50); }, mapInit: function() { var self = this; var $window = $(window); if (!$('#jobs-google-maps').length) { return; } map = L.map('jobs-google-maps', { scrollWheelZoom: false }); markers = new L.MarkerClusterGroup({ showCoverageOnHover: false }); CustomHtmlIcon = L.HtmlIcon.extend({ options: { html: "
", iconSize: [30, 30], iconAnchor: [22, 30], popupAnchor: [0, -30] } }); $window.on('pxg:refreshmap', function() { map._onResize(); setTimeout(function() { if(markerArray.length > 0 ){ group = L.featureGroup(markerArray); map.fitBounds(group.getBounds()); } }, 100); }); $window.on('pxg:simplerefreshmap', function() { map._onResize(); }); if ( hirestick_job_map_opts.map_service == 'mapbox' ) { var tileLayer = L.tileLayer('https://api.mapbox.com/styles/v1/mapbox/'+hirestick_job_map_opts.mapbox_style+'/tiles/{z}/{x}/{y}?access_token='+ hirestick_job_map_opts.mapbox_token, { attribution: " © Mapbox © OpenStreetMap Improve this map", maxZoom: 18, }); } else if ( hirestick_job_map_opts.map_service == 'here' ) { var hereTileUrl = 'https://2.base.maps.ls.hereapi.com/maptile/2.1/maptile/newest/'+hirestick_job_map_opts.here_style+'/{z}/{x}/{y}/512/png8?apiKey='+ hirestick_job_map_opts.here_map_api_key +'&ppi=320'; var tileLayer = L.tileLayer(hereTileUrl, { attribution: " © Here © Improve this map", maxZoom: 18, }); } else { if ( hirestick_job_map_opts.custom_style != '' ) { try { var custom_style = $.parseJSON(hirestick_job_map_opts.custom_style); var tileLayer = L.gridLayer.googleMutant({ type: 'roadmap', styles: custom_style }); } catch(err) { var tileLayer = L.gridLayer.googleMutant({ type: 'roadmap' }); } } else { var tileLayer = L.gridLayer.googleMutant({ type: 'roadmap' }); } } map.addLayer(tileLayer); // check archive/single page if ( !$('#jobs-google-maps').is('.single-job-map') ) { self.updateMakerCards(); } else { var $item = $('.single-listing-wrapper'); if ( $item.data('latitude') !== "" && $item.data('latitude') !== "" ) { var zoom = (typeof MapWidgetZoom !== "undefined") ? MapWidgetZoom : 15; self.addMakerToMap($item); map.addLayer(markers); map.setView([$item.data('latitude'), $item.data('longitude')], zoom); $(window).on('update:map', function() { map.setView([$item.data('latitude'), $item.data('longitude')], zoom); }); } else { $('#jobs-google-maps').hide(); } } }, updateMakerCards: function() { var self = this; var $items = $('.main-items-wrapper .map-item'); if ($('#jobs-google-maps').length && typeof map !== "undefined") { if (!$items.length) { map.setView([hirestick_job_map_opts.default_latitude, hirestick_job_map_opts.default_longitude], 12); return; } map.removeLayer(markers); markers = new L.MarkerClusterGroup({ showCoverageOnHover: false }); $items.each(function(i, obj) { self.addMakerToMap($(obj), true); }); map.addLayer(markers); if(markerArray.length > 0 ){ group = L.featureGroup(markerArray); map.fitBounds(group.getBounds()); } } }, addMakerToMap: function($item, archive) { var self = this; var marker; if ( $item.data('latitude') == "" || $item.data('longitude') == "") { return; } if ( $item.data('img')) { var img_logo = ""; var mapPinHTML = "