UNPKG

sails-service-location

Version:

Service for Sails framework with Location features

67 lines (47 loc) 3.01 kB
'use strict'; 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; }; }(); Object.defineProperty(exports, "__esModule", { value: true }); var _nodeGeocoder = require('node-geocoder'); var _nodeGeocoder2 = _interopRequireDefault(_nodeGeocoder); var _BaseLocation2 = require('./BaseLocation'); var _BaseLocation3 = _interopRequireDefault(_BaseLocation2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var OpenStreetMapLocation = function (_BaseLocation) { _inherits(OpenStreetMapLocation, _BaseLocation); function OpenStreetMapLocation(config) { _classCallCheck(this, OpenStreetMapLocation); var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(OpenStreetMapLocation).call(this, config)); _this.setProvider((0, _nodeGeocoder2.default)('openstreetmap', 'http', _this.get())); return _this; } /** * Geocode address and get latitude\longitude for it * @param {String} address * @returns {Promise} */ _createClass(OpenStreetMapLocation, [{ key: 'geocode', value: function geocode(address) { return this.getProvider().geocode(address); } /** * Reverse geocode to address * @param {Number} latitude * @param {Number} longitude * @returns {Promise} */ }, { key: 'reverse', value: function reverse(latitude, longitude) { return this.getProvider().reverse({ lat: latitude, lon: longitude }); } }]); return OpenStreetMapLocation; }(_BaseLocation3.default); exports.default = OpenStreetMapLocation; module.exports = exports['default'];