@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
174 lines (173 loc) • 7.28 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var bind_1 = __importDefault(require("../../../utils/bind"));
var constant_1 = require("./mapThemeStyle/constant");
// @ts-ignore
var mapboxGlLanguage_js_1 = __importDefault(require("./js/mapboxGlLanguage.js"));
var constants_1 = require("./constants");
require("./style.mless");
var Mapbox = /** @class */ (function (_super) {
__extends(Mapbox, _super);
function Mapbox(props) {
var _this = _super.call(this, props) || this;
_this.onStyleLoad = function (map, e) {
var onStyleLoad = _this.props.onStyleLoad;
_this.map = map;
if (onStyleLoad) {
onStyleLoad(map, e);
}
};
// @ts-ignore
_this.language = new mapboxGlLanguage_js_1.default();
var queryPath = props.queryPath, worldView = props.worldView, local = props.local, theme = props.theme, tilePath = props.tilePath;
_this.style = _this.language.setLanguage(props.createStyles(queryPath, {
worldView: worldView,
mapThemeType: theme,
tilePath: tilePath
}), local);
return _this;
}
Mapbox.prototype.worldViewControl = function (worldView) {
var _this = this;
if (!this.map || !worldView)
return;
var adminLayers = [
'admin-0-boundary',
'admin-1-boundary',
'admin-0-boundary-disputed',
'admin-1-boundary-bg',
'admin-0-boundary-bg'
];
adminLayers.forEach(function (adminLayer) {
_this.map.setFilter(adminLayer, [
'match',
['get', 'worldview'],
['all', worldView],
true,
false
]);
});
};
Mapbox.prototype.localControl = function (local) {
if (!this.map || !local)
return;
this.map.setStyle(this.language.setLanguage(this.map.getStyle(), local));
};
Mapbox.prototype.themeControl = function (props) {
var queryPath = props.queryPath, worldView = props.worldView, local = props.local, theme = props.theme, tilePath = props.tilePath;
if (!this.map || !worldView || !local || !theme) {
return;
}
var oldStyle = this.map.getStyle();
var newStyle = props.createStyles(queryPath, {
worldView: worldView,
mapThemeType: theme,
tilePath: tilePath
});
oldStyle.sprite = newStyle.sprite;
newStyle.layers.forEach(function (_a) {
var id = _a.id, paint = _a.paint;
var layer = oldStyle.layers.find(function (value) { return value.id === id; }) || {};
layer.paint = paint;
});
this.map.setStyle(oldStyle);
};
Mapbox.prototype.UNSAFE_componentWillReceiveProps = function (nextProps) {
if (nextProps.theme !== this.props.theme) {
this.themeControl(nextProps);
}
if (nextProps.local !== this.props.local) {
this.localControl(nextProps.local);
}
if (nextProps.worldView !== this.props.worldView) {
this.worldViewControl(nextProps.worldView);
}
};
Mapbox.prototype.render = function () {
var ReactMapboxGL = this.props.ReactMapboxGL;
return (React.createElement(ReactMapboxGL, __assign({}, this.props, { style: this.style, onStyleLoad: this.onStyleLoad })));
};
Mapbox.defaultProps = {
zoom: [0],
local: 'zh-Hans',
worldView: constant_1.WORLD_VIEW.CN,
theme: constant_1.MapboxThemeTypes.Light,
queryPath: constants_1.DEFAULT_QUERY_PATH
};
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], Mapbox.prototype, "worldViewControl", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", void 0)
], Mapbox.prototype, "localControl", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], Mapbox.prototype, "themeControl", null);
return Mapbox;
}(React.Component));
exports.default = Mapbox;