UNPKG

2.51 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = function (d, b) {
3 extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return extendStatics(d, b);
7 }
8 return function (d, b) {
9 extendStatics(d, b);
10 function __() { this.constructor = d; }
11 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12 };
13})();
14import * as React from 'react';
15import { withMap } from './context';
16var Image = (function (_super) {
17 __extends(Image, _super);
18 function Image() {
19 return _super !== null && _super.apply(this, arguments) || this;
20 }
21 Image.prototype.componentDidMount = function () {
22 this.loadImage(this.props);
23 };
24 Image.prototype.componentWillUnmount = function () {
25 Image.removeImage(this.props);
26 };
27 Image.prototype.componentDidUpdate = function (prevProps) {
28 var id = prevProps.id;
29 if (prevProps.map !== this.props.map) {
30 Image.removeImage(this.props);
31 }
32 if (this.props.map && !this.props.map.hasImage(id)) {
33 this.loadImage(this.props);
34 }
35 };
36 Image.prototype.render = function () {
37 return null;
38 };
39 Image.prototype.loadImage = function (props) {
40 var _this = this;
41 var map = props.map, id = props.id, url = props.url, data = props.data, options = props.options, onError = props.onError;
42 if (data) {
43 map.addImage(id, data, options);
44 this.loaded();
45 }
46 else if (url) {
47 map.loadImage(url, function (error, image) {
48 if (error) {
49 if (onError) {
50 onError(error);
51 }
52 return;
53 }
54 map.addImage(id, image, options);
55 _this.loaded();
56 });
57 }
58 };
59 Image.removeImage = function (props) {
60 var id = props.id, map = props.map;
61 if (map && map.getStyle()) {
62 map.removeImage(id);
63 }
64 };
65 Image.prototype.loaded = function () {
66 var onLoaded = this.props.onLoaded;
67 if (onLoaded) {
68 onLoaded();
69 }
70 };
71 return Image;
72}(React.Component));
73export default withMap(Image);
74//# sourceMappingURL=image.js.map
\No newline at end of file