reactor(layer): scaleContorller

This commit is contained in:
thinkinggis 2019-03-23 18:30:28 +08:00
parent fbadd00dff
commit b8883b047b
3 changed files with 50 additions and 33 deletions

View File

@ -48,16 +48,12 @@ scene.on('loaded', () => {
const circleLayer = scene.PointLayer({ const circleLayer = scene.PointLayer({
zIndex: 2, zIndex: 2,
}) })
.source(data,{ .source(data)
scaledefs:{ .shape('circle')
value:{ .size('value', [ 2, 30]) // default 1
type:'log' .scale('value', {
} type:'log',
}
}) })
.shape('2d:circle')
.size('value', [ 2, 80]) // default 1
//.size('value', [ 10, 300]) // default 1 //.size('value', [ 10, 300]) // default 1
.active(true) .active(true)
.filter('value', field_8 => { .filter('value', field_8 => {

View File

@ -5,6 +5,7 @@
import Base from './base'; import Base from './base';
import * as THREE from './three'; import * as THREE from './three';
import ColorUtil from '../attr/color-util'; import ColorUtil from '../attr/color-util';
import Controller from './controller/index';
import source from './source'; import source from './source';
import pickingFragmentShader from '../core/engine/picking/picking_frag.glsl'; import pickingFragmentShader from '../core/engine/picking/picking_frag.glsl';
// import PickingMaterial from '../core/engine/picking/pickingMaterial'; // import PickingMaterial from '../core/engine/picking/pickingMaterial';
@ -31,8 +32,10 @@ export default class Layer extends Base {
minZoom: 0, minZoom: 0,
maxZoom: 22, maxZoom: 22,
rotation: 0, rotation: 0,
option: {},
attrOptions: { attrOptions: {
}, },
scaleOptions: {},
scales: {}, scales: {},
attrs: {}, attrs: {},
// 样式配置项 // 样式配置项
@ -140,6 +143,16 @@ export default class Layer extends Base {
this._createAttrOption('size', field, values, Global.size); this._createAttrOption('size', field, values, Global.size);
return this; return this;
} }
scale(field, cfg) {
const options = this.get('scaleOptions');
const scaleDefs = options;
if (Util.isObject(field)) {
Util.mix(scaleDefs, field);
} else {
scaleDefs[field] = cfg;
}
return this;
}
shape(field, values) { shape(field, values) {
if (field.split(':').length === 2) { if (field.split(':').length === 2) {
this.shapeType = field.split(':')[0]; this.shapeType = field.split(':')[0];
@ -195,11 +208,13 @@ export default class Layer extends Base {
this.set('styleOptions', styleOptions); this.set('styleOptions', styleOptions);
return this; return this;
} }
filter(field, values) { filter(field, values) {
this._needUpdateFilter = true; this._needUpdateFilter = true;
this._createAttrOption('filter', field, values, true); this._createAttrOption('filter', field, values, true);
return this; return this;
} }
animate(field, cfg) { animate(field, cfg) {
let animateOptions = this.get('animateOptions'); let animateOptions = this.get('animateOptions');
if (!animateOptions) { if (!animateOptions) {
@ -235,10 +250,11 @@ export default class Layer extends Base {
return this; return this;
} }
_createScale(field) { _createScale(field) {
// TODO scale更新
const scales = this.get('scales'); const scales = this.get('scales');
let scale = scales[field]; let scale = scales[field];
if (!scale) { if (!scale) {
scale = this.layerSource.createScale(field); scale = this.createScale(field);
scales[field] = scale; scales[field] = scale;
} }
return scale; return scale;
@ -265,8 +281,30 @@ export default class Layer extends Base {
} }
this._setAttrOptions(attrName, attrCfg); this._setAttrOptions(attrName, attrCfg);
} }
_initControllers() {
const scales = this.get('scaleOptions');
const scaleController = new Controller.Scale({
defs: {
...scales
}
});
this.set('scaleController', scaleController);
}
createScale(field) {
const data = this.layerSource.data.dataArray;
const scales = this.get('scales');
let scale = scales[field];
const scaleController = this.get('scaleController');
if (!scale) {
scale = scaleController.createScale(field, data);
scales[field] = scale;
}
return scale;
}
// 初始化图层 // 初始化图层
init() { init() {
this._initControllers();
this._initAttrs(); this._initAttrs();
this._scaleByZoom(); this._scaleByZoom();
this._mapping(); this._mapping();
@ -283,6 +321,7 @@ export default class Layer extends Base {
this.off('mouseleave', resetHander); this.off('mouseleave', resetHander);
} }
} }
setActive(id, color) { setActive(id, color) {
this._activeIds = id; this._activeIds = id;
this.layerMesh.material.setUniformsValue('u_activeId', id); this.layerMesh.material.setUniformsValue('u_activeId', id);
@ -291,6 +330,7 @@ export default class Layer extends Base {
} }
this.layerMesh.material.setUniformsValue('u_activeColor', color); this.layerMesh.material.setUniformsValue('u_activeColor', color);
} }
_addActiveFeature(e) { _addActiveFeature(e) {
const { featureId } = e; const { featureId } = e;
this._activeIds = featureId; this._activeIds = featureId;
@ -306,6 +346,7 @@ export default class Layer extends Base {
} }
} }
} }
_updateAttr(type) { _updateAttr(type) {
const self = this; const self = this;
const attrs = this.get('attrs'); const attrs = this.get('attrs');
@ -345,6 +386,7 @@ export default class Layer extends Base {
} }
this.emit('sizeUpdated', this.zoomSizeCache[zoom]); this.emit('sizeUpdated', this.zoomSizeCache[zoom]);
} }
_mapping() { _mapping() {
const self = this; const self = this;
const attrs = self.get('attrs'); const attrs = self.get('attrs');
@ -379,6 +421,7 @@ export default class Layer extends Base {
} }
this.layerData = mappedData; this.layerData = mappedData;
} }
// 更新地图映射 // 更新地图映射
_updateMaping() { _updateMaping() {
const self = this; const self = this;
@ -407,6 +450,7 @@ export default class Layer extends Base {
} }
} }
} }
// 获取属性映射的值 // 获取属性映射的值
_getAttrValues(attr, record) { _getAttrValues(attr, record) {
const scales = attr.scales; const scales = attr.scales;

View File

@ -1,5 +1,4 @@
import Base from './base'; import Base from './base';
import Controller from './controller/index';
import { getTransform, getParser } from '../source'; import { getTransform, getParser } from '../source';
import { extent, tranfrormCoord } from '../util/geo'; import { extent, tranfrormCoord } from '../util/geo';
import { getMap } from '../map/index'; import { getMap } from '../map/index';
@ -28,7 +27,6 @@ export default class Source extends Base {
// 坐标转换 // 坐标转换
this._projectCoords(); this._projectCoords();
this._initControllers();
} }
_excuteParser() { _excuteParser() {
const parser = this.get('parser'); const parser = this.get('parser');
@ -55,27 +53,6 @@ export default class Source extends Base {
data.coordinates = tranfrormCoord(data.coordinates, this._coorConvert.bind(this)); data.coordinates = tranfrormCoord(data.coordinates, this._coorConvert.bind(this));
}); });
} }
createScale(field) {
const data = this.data.dataArray;
const scales = this.get('scales');
let scale = scales[field];
const scaleController = this.get('scaleController');
if (!scale) {
scale = scaleController.createScale(field, data);
scales[field] = scale;
}
return scale;
}
_initControllers() {
const scales = this.get('scaledefs');
const scaleController = new Controller.Scale({
defs: {
...scales
}
});
this.set('scaleController', scaleController);
}
_getCoord(geo) { _getCoord(geo) {
if (geo.geometry) { if (geo.geometry) {
// GeoJSON feature // GeoJSON feature