diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php index 06e8b0759..1014a8b5f 100644 --- a/controllers/front/ContactController.php +++ b/controllers/front/ContactController.php @@ -237,15 +237,16 @@ class ContactControllerCore extends FrontController $this->addJS(_PS_JS_DIR_.'validate.js'); // GOOGLE MAP - if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { Media::addJsDef( array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID, ) ); $this->addJS( 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. - '&libraries=places&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/controllers/front/GuestTrackingController.php b/controllers/front/GuestTrackingController.php index 9a9df2490..596d54185 100644 --- a/controllers/front/GuestTrackingController.php +++ b/controllers/front/GuestTrackingController.php @@ -639,6 +639,7 @@ class GuestTrackingControllerCore extends FrontController if (Validate::isLoadedObject($objHotelBranchInformation)) { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -646,10 +647,11 @@ class GuestTrackingControllerCore extends FrontController Media::addJsDef(array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), 'initiateMap' => 1, + 'PS_MAP_ID' => $PS_MAP_ID, )); $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places,marker&loading=async&callback=initMap&language='. $this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php index 6be63643b..40f3edaf6 100644 --- a/controllers/front/OrderDetailController.php +++ b/controllers/front/OrderDetailController.php @@ -871,6 +871,7 @@ class OrderDetailControllerCore extends FrontController if (Validate::isLoadedObject($objHotelBranchInformation)) { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -878,10 +879,10 @@ class OrderDetailControllerCore extends FrontController Media::addJsDef(array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), 'initiateMap' => 1, + 'PS_MAP_ID' => $PS_MAP_ID, )); - $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places,marker&loading=async&callback=initMap&language='. $this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } diff --git a/controllers/front/OurPropertiesController.php b/controllers/front/OurPropertiesController.php index cb651ba1b..52fd94a86 100644 --- a/controllers/front/OurPropertiesController.php +++ b/controllers/front/OurPropertiesController.php @@ -111,7 +111,7 @@ class OurPropertiesControllerCore extends FrontController $hotelsInfo = array_slice($hotelsInfo, $page * 10, 10); } - if ($displayHotelMap && Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if ($displayHotelMap && Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP') && Configuration::get('PS_MAP_ID')) { if ($hotelLocations = $objHotelInfo->getMapFormatHotelsInfo(Configuration::get('WK_MAP_HOTEL_ACTIVE_ONLY'))) { $hotelLocationArray = str_replace(array('\n', '\r'), '', json_encode($hotelLocations)); } @@ -144,16 +144,17 @@ class OurPropertiesControllerCore extends FrontController $this->addJS(_THEME_JS_DIR_.'our-properties.js'); $this->addCSS(_THEME_CSS_DIR_.'our-properties.css'); // GOOGLE MAP - if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP')) { Media::addJsDef( array( 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID ) ); $this->addJS( 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. - '&libraries=places&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index 24cc682af..67627e5ac 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -66,10 +66,11 @@ class ProductControllerCore extends FrontController $this->addJqueryPlugin('jqzoom'); } - if (($PS_API_KEY = Configuration::get('PS_API_KEY'))) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) + ) { $objHotelRoomType = new HotelRoomType(); - $roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id); - if ($roomTypeInfo) { + if ($roomTypeInfo = $objHotelRoomType->getRoomTypeInfoByIdProduct($this->product->id)) { $objHotelBranchInformation = new HotelBranchInformation($roomTypeInfo['id_hotel']); if (floatval($objHotelBranchInformation->latitude) != 0 && floatval($objHotelBranchInformation->longitude) != 0 @@ -79,12 +80,13 @@ class ProductControllerCore extends FrontController 'latitude' => $objHotelBranchInformation->latitude, 'longitude' => $objHotelBranchInformation->longitude, ), - 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')) + 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => $PS_MAP_ID )); $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='. - $this->context->language->iso_code.'®ion='.$this->context->country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY. + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); } } diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 08813efcb..75feb0dd4 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -214,7 +214,7 @@ class AdminAddHotelController extends ModuleAdminController } $smartyVars['state_var'] = $stateOptions; - $smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && Configuration::get('WK_GOOGLE_ACTIVE_MAP'); + $smartyVars['enabledDisplayMap'] = Configuration::get('PS_API_KEY') && Configuration::get('PS_MAP_ID') && Configuration::get('WK_GOOGLE_ACTIVE_MAP'); $smartyVars['ps_img_dir'] = _PS_IMG_.'l/'; $smartyVars['PS_MAX_CHECKOUT_OFFSET'] = (int) Configuration::get('PS_MAX_CHECKOUT_OFFSET'); $smartyVars['PS_MIN_BOOKING_OFFSET'] = (int) Configuration::get('PS_MIN_BOOKING_OFFSET'); @@ -605,8 +605,8 @@ class AdminAddHotelController extends ModuleAdminController $objHotelBranch->check_in = $check_in; $objHotelBranch->check_out = $check_out; $objHotelBranch->rating = $rating; - $objHotelBranch->latitude = $latitude; - $objHotelBranch->longitude = $longitude; + $objHotelBranch->latitude = Tools::ps_round($latitude, 8); + $objHotelBranch->longitude = Tools::ps_round($longitude, 8); $objHotelBranch->map_formated_address = $map_formated_address; $objHotelBranch->map_input_text = $map_input_text; $objHotelBranch->save(); @@ -984,15 +984,16 @@ class AdminAddHotelController extends ModuleAdminController 'primaryHotelId' => Configuration::get('WK_PRIMARY_HOTEL'), 'disableHotelMsg' => $this->l('Primary hotel for website will be updated to first available active hotel.', null, true), 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), + 'PS_MAP_ID' => ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) ); // GOOGLE MAP $language = $this->context->language; $country = $this->context->country; - if ($PS_API_KEY = Configuration::get('PS_API_KEY')) { + if (($PS_API_KEY = Configuration::get('PS_API_KEY')) && $PS_MAP_ID) { $this->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places&language='. - $language->iso_code.'®ion='.$country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$PS_API_KEY.'&libraries=places,marker&loading=async&language='. + $language->iso_code.'®ion='.$country->iso_code.'&callback=initGoogleMaps' ); } //tinymce diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php index ca6e55912..9cc4d589a 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelGeneralSettingsController.php @@ -397,6 +397,11 @@ class AdminHotelGeneralSettingsController extends ModuleAdminController 'hint' => $this->l('Unique API key for Google Maps.'), 'type' => 'text', ), + 'PS_MAP_ID' => array( + 'title' => $this->l('Google Maps Id'), + 'hint' => $this->l('Map Id for Google Maps.'), + 'type' => 'text' + ), 'WK_GOOGLE_ACTIVE_MAP' => array( 'title' => $this->l('Display Google Maps For Hotel Location'), 'cast' => 'intval', diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 8da3931ea..41b38b695 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -285,6 +285,7 @@ class HotelReservationSystem extends Module if (Tools::getValue('controller') == 'category') { if (($apiKey = Configuration::get('PS_API_KEY')) && Configuration::get('WK_GOOGLE_ACTIVE_MAP') + && ($PS_MAP_ID = Configuration::get('PS_MAP_ID')) ) { $idCategory = Tools::getValue('id_category'); $idHotel = HotelBranchInformation::getHotelIdByIdCategory($idCategory); @@ -299,13 +300,14 @@ class HotelReservationSystem extends Module 'longitude' => $objHotel->longitude, 'map_input_text' => $objHotel->map_input_text, ), + 'PS_MAP_ID' => $PS_MAP_ID, 'hotel_name' => $objHotel->hotel_name, 'PS_STORES_ICON' => $this->context->link->getMediaLink(_PS_IMG_.Configuration::get('PS_STORES_ICON')), )); $this->context->controller->addJS( - 'https://maps.googleapis.com/maps/api/js?key='.$apiKey.'&libraries=places&language='. - $this->context->language->iso_code.'®ion='.$this->context->country->iso_code + 'https://maps.googleapis.com/maps/api/js?key='.$apiKey. + '&libraries=places,marker&loading=async&callback=initMap&language='.$this->context->language->iso_code.'®ion='.$this->context->country->iso_code ); $this->context->controller->addJS($this->getPathUri().'views/js/searchResultsMap.js'); $this->context->controller->addCSS($this->getPathUri().'views/css/searchResultsMap.css'); diff --git a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css index 5dd54412f..b27f73368 100644 --- a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css +++ b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css @@ -472,10 +472,7 @@ p.room_cat_data } #pac-input { - background-color: #fff; - height: 38px; width: 300px; - font-size: 14px; text-overflow: ellipsis; } diff --git a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js index c6e6a80a2..24d0ea886 100644 --- a/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelReservationAdmin.js @@ -22,17 +22,12 @@ var GoogleMapsManager = { defaultZoom: 10, map: null, markers: [], - placesService: null, + placeService: null, init: function(jQDiv) { this.mapDiv = jQDiv; this.geocoder = new google.maps.Geocoder(); }, - setPlacesService: function() { - if (!this.placesService && this.map) { - this.placesService = new google.maps.places.PlacesService(this.map); - } - }, setDefaultLatLng: function(cb) { if (!this.defaultLatLng) { var latitude = Number($("#loclatitude").val()); @@ -64,6 +59,24 @@ var GoogleMapsManager = { } } }, + fetchFields: async function(request) { + if (!request.placeId) return; + const place = new google.maps.places.Place({ + id: request.placeId + }); + + const fieldsRequest = { + fields: ["displayName", "formattedAddress", "location"] + }; + + try { + await place.fetchFields(fieldsRequest); + this.placeService = place; + return place; + } catch (error) { + console.log(error); + } + }, initMap: function(cb) { if (!this.map) { var that = this; @@ -71,85 +84,26 @@ var GoogleMapsManager = { that.map = new google.maps.Map($(that.mapDiv).get(0), { zoom: that.defaultZoom, clickableIcons: true, + mapId: PS_MAP_ID }); that.map.setCenter(that.defaultLatLng); if (that.defaultLatLng && that.formattedAddress) { that.addMarker(that.defaultLatLng, null, that.formattedAddress); } - that.setPlacesService(); - // register marker events that.map.addListener('click', function (e) { var latLng = e.latLng; - - var isInfoWindowNeeded = true; // if it is a Place Of Interest (POI), event contains the property 'placeId' if (Object.hasOwn(e, 'placeId')) { - isInfoWindowNeeded = false; - - that.geocoder.geocode({ location: latLng }, function (results, status) { - if (status == google.maps.GeocoderStatus.OK && results[0]) { - var request = { - placeId: e.placeId, - fields: ['name'], - }; - - that.placesService.getDetails(request, function(place, status) { - if (status === google.maps.places.PlacesServiceStatus.OK) { - var content = '
' + place.name + '

' + - results[0].formatted_address + '

'; - - var callback = function (latLng) { - that.setFormVars({ - lat: latLng.lat(), - lng: latLng.lng(), - formattedAddress: content, - inputText: $('#pac-input').val(), - }); - } - - that.addMarker( - latLng, - results[0], - null, - isInfoWindowNeeded, - callback(latLng) - ); - } - }); + that.fetchFields({ placeId: e.placeId }).then(place => { + if (place && place.location) { + that.addMarker(place.location, null, place.formattedAddress); } }); } else { - that.geocoder.geocode({ location: latLng }, function (results, status) { - if (status == google.maps.GeocoderStatus.OK && results[0]) { - var request = { - placeId: results[0].place_id, - fields: ['name'], - }; - - that.placesService.getDetails(request, function(place, status) { - if (status === google.maps.places.PlacesServiceStatus.OK) { - var content = '
' + place.name + '

' + - results[0].formatted_address + '

'; - - var callback = function (latLng) { - that.setFormVars({ - lat: latLng.lat(), - lng: latLng.lng(), - formattedAddress: content, - inputText: $('#pac-input').val(), - }); - } - - that.addMarker( - latLng, - results[0], - null, - isInfoWindowNeeded, - callback(latLng) - ); - } - }); + that.geocoder.geocode({ location: latLng }, function(results, status) { + if (status === 'OK' && results[0]) { + that.addMarker(latLng, null, results[0].formatted_address); } }); } @@ -163,42 +117,37 @@ var GoogleMapsManager = { cb(); } } - }, initAutocomplete: function(jQInput, cb) { var that = this; that.initMap(function() { that.autocompleteInput = jQInput; var input = $(that.autocompleteInput).get(0); - that.map.controls[google.maps.ControlPosition.TOP_CENTER].push(input); - that.autocomplete = new google.maps.places.Autocomplete(input); - that.autocomplete.bindTo('bounds', that.map); - - that.autocomplete.addListener('place_changed', function() { - that.clearAllMarkers(); - var place = that.autocomplete.getPlace(); - - if (place.geometry.viewport) { - that.map.fitBounds(place.geometry.viewport); - } else { - that.map.setCenter(place.geometry.location); - that.map.setZoom(18); - } - var latLng = { - lat: place.geometry.location.lat(), - lng: place.geometry.location.lng(), - }; - that.addMarker(latLng, place); - - var content = '
' + place.name + '

' + place.formatted_address + '

'; - that.setFormVars({ - lat: latLng.lat, - lng: latLng.lng, - formattedAddress: content, - inputText: $('#pac-input').val(), - }); + that.autocomplete = new google.maps.places.PlaceAutocompleteElement({ + locationRestriction: that.map.getBounds() }); + that.autocomplete.id = "place-autocomplete-input"; + input.appendChild(that.autocomplete); + + that.map.controls[google.maps.ControlPosition.TOP_LEFT].push(input); + that.infoWindow = new google.maps.InfoWindow({}); + that.autocomplete.addEventListener("gmp-select", async (event) => { + const place = event.placePrediction.toPlace(); + + await place.fetchFields({ + fields: ["displayName", "formattedAddress", "location", "viewport"] + }); + // Fit the map to the place + if (place.viewport) { + that.map.fitBounds(place.viewport); + } else { + that.map.setCenter(place.location); + that.map.setZoom(18); + } + + that.addMarker(place.location, null, place.formattedAddress); + }); google.maps.event.addDomListener(input, 'keydown', function (e) { if (e.keyCode === 13) { e.preventDefault(); @@ -213,11 +162,17 @@ var GoogleMapsManager = { addMarker: function(latLng, address = null, fa = null, addInfoWindow = true, cb = null) { var that = this; that.clearAllMarkers(); - var marker = new google.maps.Marker({ + + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + var marker = new google.maps.marker.AdvancedMarkerElement({ position: latLng, map: that.map, + content: icon, draggable: true, - icon: PS_STORES_ICON }); that.markers.push(marker); marker.addListener('dragend', function(e) { @@ -237,22 +192,11 @@ var GoogleMapsManager = { // open info window that.addInfoWindow(marker, fa); } else { - var request = { - placeId: address.place_id, - fields: ['name'], - }; - - that.placesService.getDetails(request, function(place, status) { - if (status === google.maps.places.PlacesServiceStatus.OK) { - // open info window - var content = '
' + place.name + '

' + address.formatted_address + '

'; - that.addInfoWindow(marker, content); - - if(cb && typeof cb === 'function') { - cb(); - } - } - }); + var content = '
' + this.placeService.displayName + '

' + address.formatted_address + '

'; + that.addInfoWindow(marker, content); + if(cb && typeof cb === 'function') { + cb(); + } } } else { if(cb && typeof cb === 'function') { @@ -287,10 +231,10 @@ var GoogleMapsManager = { that.clearAllMarkers(); }); - var latLng = marker.getPosition(); + var latLng = marker.position; that.setFormVars({ - lat: latLng.lat(), - lng: latLng.lng(), + lat: latLng.lat, + lng: latLng.lng, formattedAddress: content, inputText: $('#pac-input').val(), }); @@ -988,8 +932,6 @@ $(document).ready(function() { $('input[name="min_booking_offset"]').closest('.form-group').show(200); } }); - - initGoogleMaps(); }); function toggleGoogleMapsFields() diff --git a/modules/hotelreservationsystem/views/js/searchResultsMap.js b/modules/hotelreservationsystem/views/js/searchResultsMap.js index f24c762c4..39fc4faf7 100644 --- a/modules/hotelreservationsystem/views/js/searchResultsMap.js +++ b/modules/hotelreservationsystem/views/js/searchResultsMap.js @@ -28,33 +28,36 @@ function initMap() { center: hotelLocation, disableDefaultUI: true, fullscreenControl: true, + mapId: PS_MAP_ID }); - const marker = new google.maps.Marker({ - position: hotelLocation, + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + const marker = new google.maps.marker.AdvancedMarkerElement({ map: map, - title: hotel_name, - icon: PS_STORES_ICON + position: hotelLocation, + title: location.hotel_name, + content: icon, }); + marker.query = location.query || null; + marker.latitude = hotelLocation.lat; + marker.longitude = hotelLocation.lng; + marker.addListener('click', function() { let query = ''; - if (hotel_location.map_input_text != '') { - query = hotel_location.map_input_text; - } else { - query = hotel_location.latitude + ',' + hotel_location.longitude; + if (this.query) { + query = this.query; + } else if (this.latitude && this.longitude) { + query = `${this.latitude},${this.longitude}`; } - window.open('https://www.google.com/maps/search/?api=1&query='+encodeURIComponent(query), '_blank'); + if (query) { + window.open(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`, '_blank'); + } }); } -$(document).ready(function() { - if (typeof hotel_location == 'object' - && $('#search-results-wrap .map-wrap').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } -}); diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index db7b2070a..1fd9dd071 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -303,7 +303,7 @@ - +
diff --git a/themes/hotel-reservation-theme/js/contact-form.js b/themes/hotel-reservation-theme/js/contact-form.js index 4f8f51dc2..9b16260d5 100644 --- a/themes/hotel-reservation-theme/js/contact-form.js +++ b/themes/hotel-reservation-theme/js/contact-form.js @@ -48,15 +48,6 @@ $(document).ready(function() { }); showProductSelect($('select[name=id_order]').attr('value')); - - //By Webkul JS for Map locations of the hotels on google Map - if (typeof hotelLocationArray != 'undefined' - && $('#map').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } }); function showProductSelect(id_order) { @@ -75,7 +66,7 @@ function initMap() { hotelLocationArray = JSON.parse(hotelLocationArray); // Display a map on the page - map = new google.maps.Map(document.getElementById("map")); + map = new google.maps.Map(document.getElementById("map"), {mapId: PS_MAP_ID}); google.maps.event.trigger(map, 'resize'); map.setTilt(45); @@ -88,14 +79,17 @@ function initMap() { $.each(hotelLocationArray, function(i, location) { var position = new google.maps.LatLng(location.latitude, location.longitude); bounds.extend(position); - marker = new google.maps.Marker({ - position: position, - map: map, - title: location.hotel_name, - animation: google.maps.Animation.DROP, - icon: PS_STORES_ICON - }); + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + marker = new google.maps.marker.AdvancedMarkerElement({ + map: map, + position: position, + title: location.hotel_name, + content: icon, + }); // Allow each marker to have an info window google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { diff --git a/themes/hotel-reservation-theme/js/order-detail.js b/themes/hotel-reservation-theme/js/order-detail.js index b60101ccf..800440304 100644 --- a/themes/hotel-reservation-theme/js/order-detail.js +++ b/themes/hotel-reservation-theme/js/order-detail.js @@ -144,24 +144,36 @@ function initMap() { center: hotelLocation, disableDefaultUI: true, fullscreenControl: true, + mapId: PS_MAP_ID }); - const marker = new google.maps.Marker({ + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + const marker = new google.maps.marker.AdvancedMarkerElement({ position: hotelLocation, map: map, - title: $(this).attr('title'), - icon: PS_STORES_ICON + title: location.hotel_name, + content: icon, }); + marker.query = location.query || null; + marker.latitude = hotelLocation.lat; + marker.longitude = hotelLocation.lng; + marker.addListener('click', function() { let query = ''; - if ($(this).attr('query') != '') { - query = $(this).attr('query'); - } else { - query = $(this).attr('latitude') + ',' + $(this).attr('longitude'); + if (this.query) { + query = this.query; + } else if (this.latitude && this.longitude) { + query = `${this.latitude},${this.longitude}`; } - window.open('https://www.google.com/maps/search/?api=1&query='+encodeURIComponent(query), '_blank'); + if (query) { + window.open(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(query)}`, '_blank'); + } }); }); } @@ -376,14 +388,5 @@ $(document).ready(function () { }); initPriceTooltip(); - - if (typeof google === 'object' - && typeof google.maps === 'object' - && typeof initiateMap !== 'undefined' - && initiateMap === 1 - ) { - initMap(); - } - initRefundDeniedTooltip(); }); diff --git a/themes/hotel-reservation-theme/js/our-properties.js b/themes/hotel-reservation-theme/js/our-properties.js index ba9408875..81a0d0be9 100644 --- a/themes/hotel-reservation-theme/js/our-properties.js +++ b/themes/hotel-reservation-theme/js/our-properties.js @@ -21,15 +21,6 @@ */ $(document).ready(function() { - //By Webkul JS for Map locations of the hotels on google Map - if (typeof hotelLocationArray != 'undefined' - && $('#map').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } - $(document).on('click', 'ul.pagination li a', function(e){ e.preventDefault(); $('#pagination').val($(this).data('pagination')); @@ -43,7 +34,7 @@ function initMap() { hotelLocationArray = JSON.parse(hotelLocationArray); // Display a map on the page - map = new google.maps.Map(document.getElementById("map")); + map = new google.maps.Map(document.getElementById("map"), {mapId: PS_MAP_ID}); google.maps.event.trigger(map, 'resize'); map.setTilt(45); @@ -56,12 +47,16 @@ function initMap() { $.each(hotelLocationArray, function(i, location) { var position = new google.maps.LatLng(location.latitude, location.longitude); bounds.extend(position); - marker = new google.maps.Marker({ - position: position, + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + + marker = new google.maps.marker.AdvancedMarkerElement({ map: map, + position: position, title: location.hotel_name, - animation: google.maps.Animation.DROP, - icon: PS_STORES_ICON + content: icon, }); // Allow each marker to have an info window diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index 22e483de5..cfdaea6f1 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -1089,15 +1089,6 @@ $(document).ready(function() { } e.preventDefault(); }); - - if (typeof hotel_location == 'object' - && $('#room_type_map_tab .map-wrap').length - && typeof google == 'object' - && typeof google.maps == 'object' - ) { - initMap(); - } - // normal product $(document).on('click', '.add_roomtype_product', function(e){ e.preventDefault(); @@ -1306,6 +1297,7 @@ function initMap() { const map = new google.maps.Map($('#room_type_map_tab .map-wrap').get(0), { zoom: 10, streetViewControl: false, + mapId: PS_MAP_ID }); const hotelLatLng = { @@ -1314,11 +1306,14 @@ function initMap() { }; map.setCenter(hotelLatLng); - - const marker = new google.maps.Marker({ + let icon = document.createElement('img'); + icon.src = PS_STORES_ICON; + icon.style.width = '24px'; + icon.style.height = '24px'; + let marker = new google.maps.marker.AdvancedMarkerElement({ position: hotelLatLng, map: map, - icon: PS_STORES_ICON + content: icon, }); const uiContent = $('#room-info-map-ui-content .hotel-info-wrap').get(0);