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