Skip to content

Commit

Permalink
fix(src): merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Mar 25, 2019
2 parents 1374309 + 9d936e7 commit 9015a3f
Show file tree
Hide file tree
Showing 25 changed files with 209 additions and 72 deletions.
19 changes: 9 additions & 10 deletions demos/01_point_circle.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,14 @@
scene.on('loaded', () => {
$.get('https://gw.alipayobjects.com/os/rmsportal/epnZEheZeDgsiSjSPcCv.json', data => {
const circleLayer = scene.PointLayer({
zIndex: 2
zIndex: 2,
})
.source(data,{
scale:{
min:0,
max:1000,
type:'linear'
}
.source(data)
.shape('circle')
.size('value', [ 2, 30]) // default 1
.scale('value', {
type:'log',
})
.shape('2d:circle')
.size('value', [ 2, 80]) // default 1
//.size('value', [ 10, 300]) // default 1
.active(true)
.filter('value', field_8 => {
Expand All @@ -69,7 +66,9 @@
opacity: 1.
})
.render();

console.log(circleLayer);
var a = circleLayer.getLegendCfg('type','color');
console.log(a);
circleLayer.on('click',(e)=>{
console.log(e);
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/l7",
"version": "1.1.3",
"version": "1.1.6",
"description": "Large-scale WebGL-powered Geospatial Data Visualization",
"main": "build/l7.js",
"browser": "build/l7.js",
Expand Down
3 changes: 3 additions & 0 deletions src/attr/color-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const ColorUtil = {
const rgba = this.toRGB(str);
return rgba.map(v => v / 255);
},
colorArray2RGBA(arr) {
return `rgba(${arr[0] * 255},${arr[1] * 255},${arr[2] * 255},${arr[3]})`;
},
color2RGBA(str) {
return this.color2Arr(str);
},
Expand Down
7 changes: 4 additions & 3 deletions src/attr/size.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class Size extends Base {
_scaling(scale, v) {
if (scale.type === 'identity') {
return v;
} else if (scale.type === 'linear') {
const percent = scale.scale(v);
return this.getLinearValue(percent);
}
const percent = scale.scale(v);
return this.getLinearValue(percent);

// else if (scale.type === 'linear') {
}

getLinearValue(percent) {
Expand Down
5 changes: 1 addition & 4 deletions src/core/engine/renderpass.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ RenderPass.prototype = {
render: function ( renderer, writeBuffer, readBuffer, delta ) {

this.scene.overrideMaterial = this.overrideMaterial;
const oldAutoClear = renderer.autoClear;
// renderer.autoClear = false;
if ( this.clearColor ) {

this.oldClearColor.copy( renderer.getClearColor() );
Expand All @@ -43,7 +41,7 @@ RenderPass.prototype = {
}

renderer.render( this.scene, this.camera, readBuffer, this.clear );
// if(this.clear)renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );


if ( this.clearColor ) {

Expand All @@ -52,7 +50,6 @@ RenderPass.prototype = {
}

this.scene.overrideMaterial = null;
renderer.autoClear = oldAutoClear;

}

Expand Down
74 changes: 74 additions & 0 deletions src/core/engine/shaderPass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// jscs:disable
/* eslint-disable */

import * as THREE from '../three';

/**
* @author alteredq / http://alteredqualia.com/
*/

var ShaderPass = function( shader, textureID ) {

this.textureID = ( textureID !== undefined ) ? textureID : "tDiffuse";

if ( shader instanceof THREE.ShaderMaterial ) {

this.uniforms = shader.uniforms;

this.material = shader;

}
else if ( shader ) {

this.uniforms = THREE.UniformsUtils.clone( shader.uniforms );

this.material = new THREE.ShaderMaterial( {

defines: shader.defines || {},
uniforms: this.uniforms,
vertexShader: shader.vertexShader,
fragmentShader: shader.fragmentShader

} );

}

this.renderToScreen = false;

this.enabled = true;
this.needsSwap = true;
this.clear = true;


this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
this.scene = new THREE.Scene();

this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
this.scene.add( this.quad );

};

ShaderPass.prototype = {

render: function( renderer, writeBuffer, readBuffer, delta ) {
if ( this.uniforms[ this.textureID ] ) {
this.uniforms[ this.textureID ].value = readBuffer.texture;

}
renderer.autoClear = false;
this.quad.material = this.material;

if ( this.renderToScreen ) {
renderer.render( this.scene, this.camera );

} else {

renderer.render( this.scene, this.camera, writeBuffer, this.clear );

}
renderer.autoClear = true;
}

};

export default ShaderPass;
81 changes: 79 additions & 2 deletions src/core/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Base from './base';
import * as THREE from './three';
import ColorUtil from '../attr/color-util';
import Controller from './controller/index';
import source from './source';
import pickingFragmentShader from '../core/engine/picking/picking_frag.glsl';
// import PickingMaterial from '../core/engine/picking/pickingMaterial';
Expand All @@ -31,8 +32,10 @@ export default class Layer extends Base {
minZoom: 0,
maxZoom: 22,
rotation: 0,
option: {},
attrOptions: {
},
scaleOptions: {},
scales: {},
attrs: {},
// 样式配置项
Expand Down Expand Up @@ -152,6 +155,16 @@ export default class Layer extends Base {
this._createAttrOption('size', field, values, Global.size);
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) {
if (field.split(':').length === 2) {
this.shapeType = field.split(':')[0];
Expand Down Expand Up @@ -207,11 +220,13 @@ export default class Layer extends Base {
this.set('styleOptions', styleOptions);
return this;
}

filter(field, values) {
this._needUpdateFilter = true;
this._createAttrOption('filter', field, values, true);
return this;
}

animate(field, cfg) {
let animateOptions = this.get('animateOptions');
if (!animateOptions) {
Expand Down Expand Up @@ -247,10 +262,11 @@ export default class Layer extends Base {
return this;
}
_createScale(field) {
// TODO scale更新
const scales = this.get('scales');
let scale = scales[field];
if (!scale) {
scale = this.layerSource.createScale(field);
scale = this.createScale(field);
scales[field] = scale;
}
return scale;
Expand All @@ -277,8 +293,30 @@ export default class Layer extends Base {
}
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() {
this._initControllers();
this._initAttrs();
this._scaleByZoom();
this._mapping();
Expand All @@ -295,11 +333,16 @@ export default class Layer extends Base {
this.off('mouseleave', resetHander);
}
}

setActive(id, color) {
this._activeIds = id;
this.layerMesh.material.setUniformsValue('u_activeId', id);
this.layerMesh.material.setUniformsValue('u_activeColor', ColorUtil.color2RGBA(color));
if (!Array.isArray(color)) {
color = ColorUtil.color2RGBA(color);
}
this.layerMesh.material.setUniformsValue('u_activeColor', color);
}

_addActiveFeature(e) {
const { featureId } = e;
this._activeIds = featureId;
Expand All @@ -315,6 +358,7 @@ export default class Layer extends Base {
}
}
}

_updateAttr(type) {
const self = this;
const attrs = this.get('attrs');
Expand Down Expand Up @@ -354,6 +398,7 @@ export default class Layer extends Base {
}
this.emit('sizeUpdated', this.zoomSizeCache[zoom]);
}

_mapping() {
const self = this;
const attrs = self.get('attrs');
Expand Down Expand Up @@ -388,6 +433,7 @@ export default class Layer extends Base {
}
this.layerData = mappedData;
}

// 更新地图映射
_updateMaping() {
const self = this;
Expand Down Expand Up @@ -416,6 +462,7 @@ export default class Layer extends Base {
}
}
}

// 获取属性映射的值
_getAttrValues(attr, record) {
const scales = attr.scales;
Expand Down Expand Up @@ -505,9 +552,11 @@ export default class Layer extends Base {
}
const feature = this.layerSource.getSelectFeature(featureId);
const lnglat = this.scene.containerToLngLat(point2d);
const style = this.layerData[featureId - 1];
const target = {
featureId,
feature,
style,
pixel: point2d,
type,
lnglat: { lng: lnglat.lng, lat: lnglat.lat }
Expand Down Expand Up @@ -648,6 +697,34 @@ export default class Layer extends Base {
this.scene.off('zoomchange', this._zoomchangeHander);
this.destroyed = true;
}

/**
* 获取图例配置项
* @param {*} field 字段
* @param {*} type 图例类型 color, size
* @return {*} 图例配置项
*/
getLegendCfg(field, type = 'color') {
// todo heatmap
if (this.type === 'heatmap' && this.shapeType === 'heatmap') {
return this.get('styleOptions').rampColors;
}
const scales = this.get('scales');
const scale = scales[field];
const colorAttrs = this.get('attrs')[type];
const lengendCfg = {};
if (scale) {
const ticks = scale.ticks;
lengendCfg.value = ticks;
lengendCfg.type = scale.type;
const values = ticks.map(value => {
const v = this._getAttrValues(colorAttrs, { [field]: value });
return type === 'color' ? ColorUtil.colorArray2RGBA(v) : v;
});
lengendCfg[type] = values;
}
return lengendCfg;
}
preRender() {

}
Expand Down
Loading

0 comments on commit 9015a3f

Please sign in to comment.