diff --git a/demos/03_choropleths_polygon.html b/demos/03_choropleths_polygon.html index e1d7994bce..73455cdba3 100644 --- a/demos/03_choropleths_polygon.html +++ b/demos/03_choropleths_polygon.html @@ -64,7 +64,20 @@ scene.on('loaded', () => { $.getJSON('https://gw.alipayobjects.com/os/rmsportal/JToMOWvicvJOISZFCkEI.json', city => { const citylayer = scene.PolygonLayer() .source(city) - .color('pm2_5_24h',(p)=>{ + .color('pm2_5_24h',colorObj['green']) + .shape('fill') + .active(true) + .style({ + opacity: 1 + }) + .render(); + +/** + const colorsEnum = ['blue','red','orange','green','purple','purple'] + setInterval(()=>{ + const index = parseInt(Math.random() * 5) + const colors = colorObj[colorsEnum[index]] + citylayer.color('pm2_5_24h',(p)=>{ if(p>120){ return colors[5]; } else if(p>65){ @@ -78,13 +91,12 @@ scene.on('loaded', () => { }else { return colors[0]; } - }) - .shape('fill') - .active(true) - .style({ - opacity: 1 - }) - .render(); + }).render() + + },10000) + **/ + + const citylayer2 = scene.PolygonLayer() .source(city) @@ -113,7 +125,6 @@ scene.on('loaded', () => { $('.info-panel select').change(function(){ const color = $(this).val(); citylayer.color('pm2_5_24h',colorObj[color]).render(); - console.timeEnd('color') }) }); }); diff --git a/demos/dashline.html b/demos/dashline.html index 537388f68c..d6afa040ae 100644 --- a/demos/dashline.html +++ b/demos/dashline.html @@ -41,7 +41,7 @@ scene.on('loaded', () => { .shape('line') .style({ lineType: 'dash', - dashArray: 200, + dashArray: 20, dashOffset: 0.2, dashRatio: 0.5 }) diff --git a/src/core/controller/mapping.js b/src/core/controller/mapping.js index 799bed9e8d..258c42e469 100644 --- a/src/core/controller/mapping.js +++ b/src/core/controller/mapping.js @@ -169,7 +169,6 @@ export default class Mapping { for (let i = 0; i < fields.length; i++) { const field = fields[i]; const scale = self._createScale(field); - if (type === 'color' && Util.isNil(option.values)) { // 设置 color 的默认色值 option.values = Global.colors; } diff --git a/src/core/layer.js b/src/core/layer.js index e66465551d..fbcf9d53d8 100644 --- a/src/core/layer.js +++ b/src/core/layer.js @@ -416,25 +416,14 @@ export default class Layer extends Base { this.draw(); return; } - // 更新数据过滤 filter - if (!Util.isEqual(preAttrs.filter, nextAttrs.filter)) { + + if (!Util.isEqual(preAttrs.filter, nextAttrs.filter) || + !Util.isEqual(preAttrs.color, nextAttrs.color) || + !Util.isEqual(preAttrs.size, nextAttrs.size) || + !Util.isEqual(preAttrs.shape, nextAttrs.shape) + ) { this.repaint(); this._setPreOption(); - return; - } - - if (!Util.isEqual(preAttrs.color, nextAttrs.color)) { - this._updateAttributes(this.layerMesh); - } - // 更新Size - if (!Util.isEqual(preAttrs.size, nextAttrs.size)) { - // 更新color; - this.repaint(); - } - // 更新形状 - if (!Util.isEqual(preAttrs.shape, nextAttrs.shape)) { - // 更新color; - this.repaint(); } if (!Util.isEqual(preStyle, nextStyle)) { // 判断新增,修改,删除 @@ -505,31 +494,20 @@ export default class Layer extends Base { */ _updateAttributes(object) { this.get('mappingController').update(); - const filterData = this.layerData; this._activeIds = null; // 清空选中元素 const colorAttr = object.geometry.attributes.a_color; const pickAttr = object.geometry.attributes.pickingId; pickAttr.array.forEach((id, index) => { id = Math.abs(id); - const color = [ ...this.layerData[id - 1].color ]; + const color = [ ...this.layerData[ id - 1 ].color ]; id = Math.abs(id); - const item = filterData[id - 1]; - if (item.hasOwnProperty('filter') && item.filter === false) { - colorAttr.array[index * 4 + 0] = 0; - colorAttr.array[index * 4 + 1] = 0; - colorAttr.array[index * 4 + 2] = 0; - colorAttr.array[index * 4 + 3] = 0; - pickAttr.array[index] = -id; // 通过Id数据过滤 id<0 不显示 - } else { - colorAttr.array[index * 4 + 0] = color[0]; - colorAttr.array[index * 4 + 1] = color[1]; - colorAttr.array[index * 4 + 2] = color[2]; - colorAttr.array[index * 4 + 3] = color[3]; - pickAttr.array[index] = id; - } + colorAttr.array[index * 4 + 0] = color[0]; + colorAttr.array[index * 4 + 1] = color[1]; + colorAttr.array[index * 4 + 2] = color[2]; + colorAttr.array[index * 4 + 3] = color[3]; + // pickAttr.array[index] = id; }); colorAttr.needsUpdate = true; - pickAttr.needsUpdate = true; } _visibleWithZoom() { if (this._object3D === null) return; diff --git a/src/geom/shader/meshline_vert.glsl b/src/geom/shader/meshline_vert.glsl index 1a5c3c9e6f..f2a30833f5 100644 --- a/src/geom/shader/meshline_vert.glsl +++ b/src/geom/shader/meshline_vert.glsl @@ -35,7 +35,7 @@ void main() { // extrude along normal float extrude_scale = pow(2.0, 20.0 - u_zoom); v_color = a_color; - v_dash_array = a_dash_array; + v_dash_array = a_dash_array * pow(2.0, 20.0 - u_zoom); float distance_ratio = a_distance / a_total_distance; #if defined DASHLINE || defined ANIMATE v_distance_ratio = distance_ratio; diff --git a/src/layer/line_layer.js b/src/layer/line_layer.js index 0b96e55129..474e5f70a8 100644 --- a/src/layer/line_layer.js +++ b/src/layer/line_layer.js @@ -5,9 +5,10 @@ export default class LineLayer extends Layer { super(scene, cfg); this.set('type', 'line'); } - shape(type) { - this.shapeType = type; - this.set('shape', type); + shape(field, values) { + super.shape(field, values); + this.shapeType = field; + this.set('shape', field); return this; } preRender() { diff --git a/src/map/AMap.js b/src/map/AMap.js index c07c8381f9..adb045cd86 100644 --- a/src/map/AMap.js +++ b/src/map/AMap.js @@ -64,7 +64,7 @@ export default class GaodeMap extends Base { this.map = new AMap.Map(this.container, this._attrs); this.map.on('complete', () => { if (this.get('mapStyle') === 'blank') { - map.setFeatures([]); + this.map.setFeatures([]); } this.addOverLayer(); this.emit('mapLoad');