UNPKG

wix-style-react

Version:
90 lines (75 loc) 3.28 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var GoogleMapsClient = function () { function GoogleMapsClient() { _classCallCheck(this, GoogleMapsClient); this._autocomplete = new window.google.maps.places.AutocompleteService(); this._geocoder = new window.google.maps.Geocoder(); var map = new window.google.maps.Map(document.createElement('div')); this._placesServices = new window.google.maps.places.PlacesService(map); } _createClass(GoogleMapsClient, [{ key: 'autocomplete', value: function autocomplete(_ref) { var _this = this; var request = _ref.request; return new Promise(function (resolve, reject) { try { _this._autocomplete.getPlacePredictions(request, function (results, status) { if (status !== window.google.maps.GeocoderStatus.OK && status !== window.google.maps.GeocoderStatus.ZERO_RESULTS) { reject({ code: 'internal' }); } else { resolve(results || []); } }); } catch (e) { reject({ code: 'internal', message: e.message }); } }); } }, { key: 'geocode', value: function geocode(_ref2) { var _this2 = this; var request = _ref2.request; return new Promise(function (resolve, reject) { try { _this2._geocoder.geocode(request, function (results, status) { if (status !== window.google.maps.GeocoderStatus.OK && status !== window.google.maps.GeocoderStatus.ZERO_RESULTS) { reject({ code: 'internal' }); } else { resolve(results || []); } }); } catch (e) { reject({ code: 'internal', message: e.message }); } }); } }, { key: 'placeDetails', value: function placeDetails(_ref3) { var _this3 = this; var request = _ref3.request; return new Promise(function (resolve, reject) { try { _this3._placesServices.getDetails(request, function (result, status) { if (status !== window.google.maps.places.PlacesServiceStatus.OK && status !== window.google.maps.places.PlacesServiceStatus.ZERO_RESULTS) { reject({ code: 'internal' }); } else { resolve(result || undefined); } }); } catch (e) { reject({ code: 'internal', message: e.message }); } }); } }]); return GoogleMapsClient; }(); exports.default = GoogleMapsClient;