From fb5be34932b1dac06c0476ec71b370d42b400d76 Mon Sep 17 00:00:00 2001 From: thinkinggis Date: Mon, 19 Aug 2019 10:50:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(json):=20point=E6=95=B0=E6=8D=AEcoord?= =?UTF-8?q?=20=E8=AE=BE=E7=BD=AE=E6=94=AF=E6=8C=81=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demos/legend.html | 93 ++++++++++++++++++++ demos/line_bug.html | 136 ++++++++++++++++++++++------- src/component/control/index.js | 4 +- src/core/controller/mapping.js | 28 ++++++ src/core/layer.js | 25 +----- src/geom/material/lineMaterial.js | 3 +- src/layer/render/line/drawArc.js | 1 + src/layer/tile/vector_tile_mesh.js | 2 +- src/source/parser/json.js | 12 ++- 9 files changed, 245 insertions(+), 59 deletions(-) create mode 100644 demos/legend.html diff --git a/demos/legend.html b/demos/legend.html new file mode 100644 index 0000000000..4813267f76 --- /dev/null +++ b/demos/legend.html @@ -0,0 +1,93 @@ + + + + + + 自定义图例组件 + + + +
+ + + + + + + + diff --git a/demos/line_bug.html b/demos/line_bug.html index 4a7079c527..df954f0034 100644 --- a/demos/line_bug.html +++ b/demos/line_bug.html @@ -7,55 +7,127 @@ city demo + + - - -
时间: 6时
-
diff --git a/src/component/control/index.js b/src/component/control/index.js index 841c4f9117..58dc150f8e 100644 --- a/src/component/control/index.js +++ b/src/component/control/index.js @@ -1,11 +1,11 @@ -import Control from './base'; +import Base from './base'; import Zoom from './zoom'; import Scale from './Scale'; import Attribution from './attribution'; import Layers from './layer'; export { - Control, + Base, Zoom, Scale, Attribution, diff --git a/src/core/controller/mapping.js b/src/core/controller/mapping.js index 5f17adfcbd..3ca6a32f9f 100644 --- a/src/core/controller/mapping.js +++ b/src/core/controller/mapping.js @@ -2,6 +2,7 @@ import Util from '../../util'; import Global from '../../global'; import ScaleController from './scale'; import Attr from '../../attr/index'; +import ColorUtil from '../../attr/color-util'; export default class Mapping { /** 初始化mapping * 初始化mapping @@ -186,4 +187,31 @@ export default class Mapping { } return [ field ]; } + /** + * 获取图例配置项 + * @param {*} field 字段 + * @param {*} type 图例类型 color, size + * @return {*} 图例配置项 + */ + getLegendCfg(field, type = 'color') { + // todo heatmap + if (this.layer.type === 'heatmap' && this.layer.shapeType === 'heatmap') { + return this.get('styleOptions').rampColors; + } + const scales = this.layer.get('scales'); + const scale = scales[field]; + const colorAttrs = this.layer.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; + } } diff --git a/src/core/layer.js b/src/core/layer.js index 228057ba08..72ac241715 100644 --- a/src/core/layer.js +++ b/src/core/layer.js @@ -4,10 +4,10 @@ */ 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 diff from '../util/diff'; +import ColorUtil from '../attr/color-util'; import { updateObjecteUniform } from '../util/object3d-util'; import Util from '../util'; import Global from '../global'; @@ -563,7 +563,7 @@ export default class Layer extends Base { // z-fighting let offset = 0; if (this.type === 'point') { - offset = 5; + offset = 3; this.shapeType = 'text' && (offset = 10); } else if (this.type === 'polyline' || this.type === 'line') { @@ -662,25 +662,8 @@ export default class Layer extends Base { * @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; + const mapCtr = this.get('mappingController'); + return mapCtr.getLegendCfg(field, type); } preRender() { diff --git a/src/geom/material/lineMaterial.js b/src/geom/material/lineMaterial.js index 47ab63fd7c..e0334a1845 100644 --- a/src/geom/material/lineMaterial.js +++ b/src/geom/material/lineMaterial.js @@ -38,7 +38,8 @@ export function ArcLineMaterial(options) { vertexShader: vs, fragmentShader: fs, transparent: true, - blending: THREE.AdditiveBlending + blending: THREE.AdditiveBlending, + side: THREE.DoubleSide }); return material; } diff --git a/src/layer/render/line/drawArc.js b/src/layer/render/line/drawArc.js index dd70ae5920..2ffb89d290 100644 --- a/src/layer/render/line/drawArc.js +++ b/src/layer/render/line/drawArc.js @@ -30,5 +30,6 @@ export default function DrawArcLine(layerData, layer, buffer) { SHAPE: false }); const arcMesh = new THREE.Mesh(geometry, lineMaterial); + arcMesh.frustumCulled = false; return arcMesh; } diff --git a/src/layer/tile/vector_tile_mesh.js b/src/layer/tile/vector_tile_mesh.js index afb66aaf33..2307b2b206 100644 --- a/src/layer/tile/vector_tile_mesh.js +++ b/src/layer/tile/vector_tile_mesh.js @@ -37,7 +37,7 @@ export default class VectorTileMesh { this.mesh = getRender(this.layer.get('type'), data.shape)(null, this.layer, data.buffer); if (this.mesh.type !== 'composer') { // 热力图的情况 this.mesh.onBeforeRender = renderer => { - this._renderMask(renderer); + // this._renderMask(renderer); const zoom = this.layer.scene.getZoom(); updateObjecteUniform(this._object3D, { u_time: this.layer.scene._engine.clock.getElapsedTime(), diff --git a/src/source/parser/json.js b/src/source/parser/json.js index d24d324aa1..cbc39b6e31 100644 --- a/src/source/parser/json.js +++ b/src/source/parser/json.js @@ -3,15 +3,23 @@ export default function json(data, cfg) { const { x, y, x1, y1, coordinates } = cfg; const resultdata = []; - data.forEach((col, featureIndex) => { + + data.slice(0).forEach((col, featureIndex) => { let coords = []; if (x && y) { coords = [ col[x], col[y] ]; } // 点数据 if (x1 && y1) { // 弧线 或者线段 coords = [[ col[x], col[y] ], [ col[x1], col[y1] ]]; } if (coordinates) { + let type = 'Polygon'; + if (!Array.isArray(coordinates[0])) { + type = 'Point'; + } + if (Array.isArray(coordinates[0]) && !Array.isArray(coordinates[0][0])) { + type = 'LineString'; + } const geometry = { - type: 'Polygon', + type, coordinates: [ ...col[coordinates] ] }; rewind(geometry, true); From 8a59eb0067a0d450226a7950f7155c83a3074fb7 Mon Sep 17 00:00:00 2001 From: thinkinggis Date: Mon, 19 Aug 2019 11:15:09 +0800 Subject: [PATCH 2/2] fix(merge):fix conflict --- src/layer/tile/vector_tile_mesh.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/tile/vector_tile_mesh.js b/src/layer/tile/vector_tile_mesh.js index 2307b2b206..afb66aaf33 100644 --- a/src/layer/tile/vector_tile_mesh.js +++ b/src/layer/tile/vector_tile_mesh.js @@ -37,7 +37,7 @@ export default class VectorTileMesh { this.mesh = getRender(this.layer.get('type'), data.shape)(null, this.layer, data.buffer); if (this.mesh.type !== 'composer') { // 热力图的情况 this.mesh.onBeforeRender = renderer => { - // this._renderMask(renderer); + this._renderMask(renderer); const zoom = this.layer.scene.getZoom(); updateObjecteUniform(this._object3D, { u_time: this.layer.scene._engine.clock.getElapsedTime(),