|
1 | 1 | (function (global, factory) {
|
2 | 2 | if (typeof define === "function" && define.amd) {
|
3 |
| - define(['module', 'exports', './GoogleApiComponent', './components/Marker', '/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/redbox-react/lib/index.js', '/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-catch-errors/lib/index.js', 'react', '/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-hmr/lib/index.js', 'react-dom', './lib/String'], factory); |
| 3 | + define(['module', 'exports', './GoogleApiComponent', './components/Marker', '/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/redbox-react/lib/index.js', '/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-catch-errors/lib/index.js', 'react', '/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-hmr/lib/index.js', 'react-dom', './lib/String', './lib/cancelablePromise'], factory); |
4 | 4 | } else if (typeof exports !== "undefined") {
|
5 |
| - factory(module, exports, require('./GoogleApiComponent'), require('./components/Marker'), require('/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/redbox-react/lib/index.js'), require('/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-catch-errors/lib/index.js'), require('react'), require('/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-hmr/lib/index.js'), require('react-dom'), require('./lib/String')); |
| 5 | + factory(module, exports, require('./GoogleApiComponent'), require('./components/Marker'), require('/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/redbox-react/lib/index.js'), require('/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-catch-errors/lib/index.js'), require('react'), require('/Users/auser/Development/fullstack/GoogleMapComponent/node_modules/react-transform-hmr/lib/index.js'), require('react-dom'), require('./lib/String'), require('./lib/cancelablePromise')); |
6 | 6 | } else {
|
7 | 7 | var mod = {
|
8 | 8 | exports: {}
|
9 | 9 | };
|
10 |
| - factory(mod, mod.exports, global.GoogleApiComponent, global.Marker, global.index, global.index, global.react, global.index, global.reactDom, global.String); |
| 10 | + factory(mod, mod.exports, global.GoogleApiComponent, global.Marker, global.index, global.index, global.react, global.index, global.reactDom, global.String, global.cancelablePromise); |
11 | 11 | global.index = mod.exports;
|
12 | 12 | }
|
13 |
| -})(this, function (module, exports, _GoogleApiComponent, _Marker, _index, _index3, _react2, _index5, _reactDom, _String) { |
| 13 | +})(this, function (module, exports, _GoogleApiComponent, _Marker, _index, _index3, _react2, _index5, _reactDom, _String, _cancelablePromise) { |
14 | 14 | 'use strict';
|
15 | 15 |
|
16 | 16 | Object.defineProperty(exports, "__esModule", {
|
|
121 | 121 | }
|
122 | 122 |
|
123 | 123 | var mapStyles = {
|
124 |
| - map: { |
125 |
| - zIndex: 0, |
| 124 | + container: { |
| 125 | + position: 'absolute', |
126 | 126 | width: '100%',
|
127 | 127 | height: '100%'
|
| 128 | + }, |
| 129 | + map: { |
| 130 | + position: 'absolute', |
| 131 | + left: 0, |
| 132 | + right: 0, |
| 133 | + bottom: 0, |
| 134 | + top: 0 |
128 | 135 | }
|
129 | 136 | };
|
130 | 137 |
|
|
138 | 145 |
|
139 | 146 | var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Map).call(this, props));
|
140 | 147 |
|
| 148 | + _this.listeners = {}; |
141 | 149 | _this.state = {
|
142 | 150 | currentLocation: {
|
143 | 151 | lat: _this.props.initialCenter.lat,
|
|
154 | 162 |
|
155 | 163 | if (this.props.centerAroundCurrentLocation) {
|
156 | 164 | if (navigator && navigator.geolocation) {
|
157 |
| - navigator.geolocation.getCurrentPosition(function (pos) { |
| 165 | + this.geoPromise = (0, _cancelablePromise.makeCancelable)(new Promise(function (resolve, reject) { |
| 166 | + navigator.geolocation.getCurrentPosition(resolve, reject); |
| 167 | + })); |
| 168 | + |
| 169 | + this.geoPromise.promise.then(function (pos) { |
158 | 170 | var coords = pos.coords;
|
159 | 171 | _this2.setState({
|
160 | 172 | currentLocation: {
|
161 | 173 | lat: coords.latitude,
|
162 | 174 | lng: coords.longitude
|
163 | 175 | }
|
164 | 176 | });
|
| 177 | + }).catch(function (e) { |
| 178 | + return e; |
165 | 179 | });
|
166 | 180 | }
|
167 | 181 | }
|
168 | 182 | this.loadMap();
|
169 | 183 | }
|
170 |
| - }, { |
171 |
| - key: 'componentWillReceiveProps', |
172 |
| - value: function componentWillReceiveProps(nextProps) { |
173 |
| - if (nextProps.initialCenter !== this.state.currentLocation) { |
174 |
| - this.setState({ |
175 |
| - currentLocation: nextProps.initialCenter |
176 |
| - }); |
177 |
| - } |
178 |
| - } |
179 | 184 | }, {
|
180 | 185 | key: 'componentDidUpdate',
|
181 | 186 | value: function componentDidUpdate(prevProps, prevState) {
|
|
189 | 194 | this.recenterMap();
|
190 | 195 | }
|
191 | 196 | }
|
| 197 | + }, { |
| 198 | + key: 'componentWillUnmount', |
| 199 | + value: function componentWillUnmount() { |
| 200 | + var _this3 = this; |
| 201 | + |
| 202 | + var google = this.props.google; |
| 203 | + |
| 204 | + if (this.geoPromise) { |
| 205 | + this.geoPromise.cancel(); |
| 206 | + } |
| 207 | + Object.keys(this.listeners).forEach(function (e) { |
| 208 | + google.maps.event.removeListener(_this3.listeners[e]); |
| 209 | + }); |
| 210 | + } |
192 | 211 | }, {
|
193 | 212 | key: 'loadMap',
|
194 | 213 | value: function loadMap() {
|
195 |
| - var _this3 = this; |
| 214 | + var _this4 = this; |
196 | 215 |
|
197 | 216 | if (this.props && this.props.google) {
|
198 | 217 | var google = this.props.google;
|
|
212 | 231 | this.map = new maps.Map(node, mapConfig);
|
213 | 232 |
|
214 | 233 | evtNames.forEach(function (e) {
|
215 |
| - _this3.map.addListener(e, _this3.handleEvent(e)); |
| 234 | + _this4.listeners[e] = _this4.map.addListener(e, _this4.handleEvent(e)); |
216 | 235 | });
|
217 | 236 | maps.event.trigger(this.map, 'ready');
|
218 | 237 | this.forceUpdate();
|
|
221 | 240 | }, {
|
222 | 241 | key: 'handleEvent',
|
223 | 242 | value: function handleEvent(evtName) {
|
224 |
| - var _this4 = this; |
| 243 | + var _this5 = this; |
225 | 244 |
|
226 | 245 | var timeout = void 0;
|
227 | 246 | var handlerName = 'on' + (0, _String.camelize)(evtName);
|
|
232 | 251 | timeout = null;
|
233 | 252 | }
|
234 | 253 | timeout = setTimeout(function () {
|
235 |
| - if (_this4.props[handlerName]) { |
236 |
| - _this4.props[handlerName](_this4.props, _this4.map, e); |
| 254 | + if (_this5.props[handlerName]) { |
| 255 | + _this5.props[handlerName](_this5.props, _this5.map, e); |
237 | 256 | }
|
238 | 257 | }, 0);
|
239 | 258 | };
|
|
267 | 286 | }, {
|
268 | 287 | key: 'renderChildren',
|
269 | 288 | value: function renderChildren() {
|
270 |
| - var _this5 = this; |
| 289 | + var _this6 = this; |
271 | 290 |
|
272 | 291 | var children = this.props.children;
|
273 | 292 |
|
|
276 | 295 |
|
277 | 296 | return _react3.default.Children.map(children, function (c) {
|
278 | 297 | return _react3.default.cloneElement(c, {
|
279 |
| - map: _this5.map, |
280 |
| - google: _this5.props.google, |
281 |
| - mapCenter: _this5.state.currentLocation |
| 298 | + map: _this6.map, |
| 299 | + google: _this6.props.google, |
| 300 | + mapCenter: _this6.state.currentLocation |
282 | 301 | });
|
283 | 302 | });
|
284 | 303 | }
|
285 | 304 | }, {
|
286 | 305 | key: 'render',
|
287 | 306 | value: function render() {
|
288 | 307 | var style = Object.assign({}, mapStyles.map, this.props.style, {
|
289 |
| - display: this.props.visible ? 'block' : 'none' |
| 308 | + display: this.props.visible ? 'inherit' : 'none' |
290 | 309 | });
|
291 | 310 |
|
292 | 311 | return _react3.default.createElement(
|
293 | 312 | 'div',
|
294 |
| - { className: this.props.className }, |
| 313 | + { style: mapStyles.container, className: this.props.className }, |
295 | 314 | _react3.default.createElement(
|
296 | 315 | 'div',
|
297 | 316 | { style: style, ref: 'map' },
|
|
0 commit comments