fix(layerservice): fix init bugs in layer service

This commit is contained in:
yuqi.pyq 2019-11-21 17:36:04 +08:00
parent b63fa3fbbd
commit fd586c60ab
9 changed files with 63 additions and 11 deletions

View File

@ -91,6 +91,9 @@ module.exports = api => {
] ]
} }
], ],
isCDNBundle ? {} : [
'transform-import-styles',
],
[ [
// @see https://github.com/babel/babel/issues/8741#issuecomment-509041135 // @see https://github.com/babel/babel/issues/8741#issuecomment-509041135
'const-enum', 'const-enum',
@ -101,7 +104,7 @@ module.exports = api => {
// 按需引用 @see https://github.com/lodash/babel-plugin-lodash // 按需引用 @see https://github.com/lodash/babel-plugin-lodash
'lodash', 'lodash',
// 内联 WebGL 常量 @see https://www.npmjs.com/package/babel-plugin-inline-webgl-constants // 内联 WebGL 常量 @see https://www.npmjs.com/package/babel-plugin-inline-webgl-constants
isCDNBundle ? 'inline-webgl-constants' : {} // isCDNBundle ? 'inline-webgl-constants' : {}
], ],
ignore: [ ignore: [
'node_modules', 'node_modules',

View File

@ -7,6 +7,8 @@ import { terser } from "rollup-plugin-terser";
import analyze from 'rollup-plugin-analyzer'; import analyze from 'rollup-plugin-analyzer';
import babel from 'rollup-plugin-babel'; import babel from 'rollup-plugin-babel';
import glsl from './rollup-plugin-glsl'; import glsl from './rollup-plugin-glsl';
import postcss from 'rollup-plugin-postcss';
import url from 'postcss-url';
function resolveFile(filePath) { function resolveFile(filePath) {
return path.join(__dirname, '..', filePath) return path.join(__dirname, '..', filePath)
@ -16,7 +18,7 @@ module.exports = [
{ {
input: resolveFile('build/bundle.ts'), input: resolveFile('build/bundle.ts'),
output: { output: {
file: resolveFile('dist/bundle.js'), file: resolveFile('packages/l7/dist/bundle.js'),
format: 'umd', format: 'umd',
name: 'L7', name: 'L7',
globals: { globals: {
@ -49,6 +51,11 @@ module.exports = [
true, true,
), ),
json(), json(),
postcss({
plugins: [
url({ url: 'inline' }),
],
}),
// @see https://github.com/rollup/rollup-plugin-node-resolve#using-with-rollup-plugin-commonjs // @see https://github.com/rollup/rollup-plugin-node-resolve#using-with-rollup-plugin-commonjs
commonjs({ commonjs({
namedExports: { namedExports: {

View File

@ -42,6 +42,7 @@
"babel-plugin-inline-import": "^3.0.0", "babel-plugin-inline-import": "^3.0.0",
"babel-plugin-inline-webgl-constants": "^1.0.1", "babel-plugin-inline-webgl-constants": "^1.0.1",
"babel-plugin-lodash": "^3.3.4", "babel-plugin-lodash": "^3.3.4",
"babel-plugin-transform-import-styles": "^0.0.11",
"babel-plugin-transform-postcss": "^0.3.0", "babel-plugin-transform-postcss": "^0.3.0",
"babel-preset-gatsby": "^0.2.20", "babel-preset-gatsby": "^0.2.20",
"clean-webpack-plugin": "^0.1.19", "clean-webpack-plugin": "^0.1.19",
@ -73,6 +74,7 @@
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"postcss": "^7.0.18", "postcss": "^7.0.18",
"postcss-plugin": "^1.0.0", "postcss-plugin": "^1.0.0",
"postcss-url": "^8.0.0",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"raw-loader": "^1.0.0", "raw-loader": "^1.0.0",
"react": "^16.8.6", "react": "^16.8.6",
@ -85,6 +87,7 @@
"rollup-plugin-babel": "^4.3.3", "rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-terser": "^5.1.2", "rollup-plugin-terser": "^5.1.2",
"rollup-pluginutils": "^2.8.2", "rollup-pluginutils": "^2.8.2",
"sass-loader": "^7.1.0", "sass-loader": "^7.1.0",

View File

@ -6,4 +6,8 @@ import Zoom from './control/zoom';
import Marker from './marker'; import Marker from './marker';
import Popup from './popup'; import Popup from './popup';
// 引入样式
// TODO: 使用 Less 或者 Sass每个组件单独引用自身样式
import './css/l7.css';
export { Control, Logo, Scale, Zoom, Layers, Marker, Popup }; export { Control, Logo, Scale, Zoom, Layers, Marker, Popup };

View File

@ -51,6 +51,7 @@ export interface IPickedFeature {
export interface ILayer { export interface ILayer {
id: string; // 一个场景中同一类型 Layer 可能存在多个 id: string; // 一个场景中同一类型 Layer 可能存在多个
name: string; // 代表 Layer 的类型 name: string; // 代表 Layer 的类型
inited: boolean; // 是否初始化完成
visible: boolean; visible: boolean;
zIndex: number; zIndex: number;
minZoom: number; minZoom: number;

View File

@ -24,17 +24,17 @@ export default class LayerService implements ILayerService {
public add(layer: ILayer) { public add(layer: ILayer) {
this.layers.push(layer); this.layers.push(layer);
this.initPlugin(layer);
layer.init();
} }
public initLayers() { public initLayers() {
this.layers.forEach((layer) => { this.layers.forEach((layer) => {
// register plugins in every layer if (!layer.inited) {
for (const plugin of layer.plugins) { // register plugins in every layer
plugin.apply(layer); for (const plugin of layer.plugins) {
plugin.apply(layer);
}
layer.init();
} }
layer.init();
}); });
} }

View File

@ -119,9 +119,6 @@ export default class Scene extends EventEmitter implements ISceneService {
// 重新绑定非首次相机更新事件 // 重新绑定非首次相机更新事件
this.map.onCameraChanged(this.handleMapCameraChanged); this.map.onCameraChanged(this.handleMapCameraChanged);
this.logger.info('map loaded'); this.logger.info('map loaded');
// scene 创建完成自动调用render 方法
this.render();
}); });
/** /**
@ -155,6 +152,8 @@ export default class Scene extends EventEmitter implements ISceneService {
public addLayer(layer: ILayer) { public addLayer(layer: ILayer) {
this.logger.info(`add layer ${layer.name}`); this.logger.info(`add layer ${layer.name}`);
this.layerService.add(layer); this.layerService.add(layer);
// scene 创建完成自动调用render 方法
this.render();
} }
public async render() { public async render() {
@ -169,6 +168,8 @@ export default class Scene extends EventEmitter implements ISceneService {
this.emit('loaded'); this.emit('loaded');
} }
// 尝试初始化未初始化的图层
this.layerService.initLayers();
this.layerService.renderLayers(); this.layerService.renderLayers();
this.logger.info('render'); this.logger.info('render');
} }

30
packages/l7/package.json Normal file
View File

@ -0,0 +1,30 @@
{
"name": "@antv/l7",
"version": "2.0.0-beta.4",
"description": "A Large-scale WebGL-powered Geospatial Data Visualization",
"main": "dist/bundle.js",
"sideEffects": true,
"files": [
"dist",
"lib",
"es",
"README.md"
],
"scripts": {
"tsc": "tsc --project tsconfig.build.json",
"clean": "rimraf dist; rimraf es; rimraf lib;",
"build": "run-p build:*",
"build:cjs": "BABEL_ENV=cjs babel src --root-mode upward --out-dir lib --source-maps --extensions .ts,.tsx --delete-dir-on-start --no-comments",
"build:esm": "BABEL_ENV=esm babel src --root-mode upward --out-dir es --source-maps --extensions .ts,.tsx --delete-dir-on-start --no-comments",
"watch": "BABEL_ENV=cjs babel src --watch --root-mode upward --out-dir lib --source-maps --extensions .ts,.tsx --delete-dir-on-start --no-comments"
},
"author": "xiaoiver",
"license": "ISC",
"gitHead": "0563f357f3a07c099bf1ffa9350e6fa3c88353ae",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@antv/l7": "2.0.0-beta.4"
}
}

View File

@ -69,6 +69,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
public zIndex: number = 0; public zIndex: number = 0;
public minZoom: number; public minZoom: number;
public maxZoom: number; public maxZoom: number;
public inited: boolean = false;
// 生命周期钩子 // 生命周期钩子
public hooks = { public hooks = {
@ -179,6 +180,8 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
public init() { public init() {
this.hooks.init.call(); this.hooks.init.call();
this.buildModels(); this.buildModels();
this.inited = true;
return this; return this;
} }