fix(line):line

This commit is contained in:
李正学 2018-11-19 12:06:42 +08:00
parent a0499b78d1
commit 5dc568fb19
14 changed files with 143 additions and 149 deletions

View File

@ -1,4 +1,4 @@
import Material from '../../../geom/material/material' import Material from '../../../geom/material/material';
import picking_frag from './picking_frag.glsl'; import picking_frag from './picking_frag.glsl';
import picking_vert from './picking_vert.glsl'; import picking_vert from './picking_vert.glsl';

View File

@ -6,7 +6,6 @@ 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 * as source from '../source/index'; import * as source from '../source/index';
import * as turfMeta from '@turf/meta';
import PickingMaterial from '../core/engine/picking/pickingMaterial'; import PickingMaterial from '../core/engine/picking/pickingMaterial';
import Attr from '../attr/index'; import Attr from '../attr/index';
import Util from '../util'; import Util from '../util';
@ -277,7 +276,7 @@ export default class Layer extends Base {
const attrOptions = this.get('attrOptions'); const attrOptions = this.get('attrOptions');
for (const type in attrOptions) { for (const type in attrOptions) {
if (attrOptions.hasOwnProperty(type)) { if (attrOptions.hasOwnProperty(type)) {
this._updateAttr(type) this._updateAttr(type);
} }
} }
} }
@ -462,11 +461,10 @@ export default class Layer extends Base {
} }
_addPickingEvents() { _addPickingEvents() {
// TODO: Find a way to properly remove this listener on destroy // TODO: Find a way to properly remove this listener on destroy
this.scene.on('pick', (e) => { this.scene.on('pick', e => {
// Re-emit click event from the layer // Re-emit click event from the layer
const { featureId, point2d, point3d, intersects } = e; const { featureId, point2d, point3d, intersects } = e;
if(intersects.length === 0) if (intersects.length === 0) { return; }
return;
const source = this.layerSource.get('data'); const source = this.layerSource.get('data');
const feature = source.features[featureId]; const feature = source.features[featureId];
const lnglat = this.scene.containerToLngLat(point2d); const lnglat = this.scene.containerToLngLat(point2d);
@ -474,7 +472,7 @@ export default class Layer extends Base {
feature, feature,
pixel: point2d, pixel: point2d,
lnglat: { lng: lnglat.lng, lat: lnglat.lat } lnglat: { lng: lnglat.lng, lat: lnglat.lat }
} };
this.emit('click', target); this.emit('click', target);
// this.emit('move', target); // this.emit('move', target);
}); });
@ -503,7 +501,7 @@ export default class Layer extends Base {
break; break;
} }
} }
colorAttr.needsUpdate =true colorAttr.needsUpdate = true;
return; return;
} }
@ -540,7 +538,7 @@ export default class Layer extends Base {
colorAttr.array[index * 4 + 3] = color[3]; colorAttr.array[index * 4 + 3] = color[3];
pickAttr.array[index] = id; pickAttr.array[index] = id;
} }
}) });
colorAttr.needsUpdate = true; colorAttr.needsUpdate = true;
pickAttr.needsUpdate = true; pickAttr.needsUpdate = true;
this._needUpdateFilter = false; this._needUpdateFilter = false;
@ -581,7 +579,7 @@ export default class Layer extends Base {
colorAttr.array[i * 4 + 3] = color[3]; colorAttr.array[i * 4 + 3] = color[3];
} }
} }
}) });
colorAttr.needsUpdate = true; colorAttr.needsUpdate = true;
} }
/** /**

View File

@ -296,7 +296,7 @@ export default class BufferBase extends Base {
pickingIds, pickingIds,
shapePositions, shapePositions,
a_size, a_size,
faceUv: new Float32Array(polygon.faceUv), faceUv: new Float32Array(polygon.faceUv)
}; };

View File

@ -55,7 +55,6 @@ export default class PointBuffer extends BufferBase {
let indexCount = 0; let indexCount = 0;
this.bufferStruct.style = properties; this.bufferStruct.style = properties;
coordinates.forEach((geo, index) => { coordinates.forEach((geo, index) => {
const m1 = new THREE.Matrix4();
let { size, shape } = properties[index]; let { size, shape } = properties[index];
let shapeType = 'extrude'; let shapeType = 'extrude';
@ -66,7 +65,7 @@ export default class PointBuffer extends BufferBase {
Util.isArray(size) || (size = [ size, size, size ]); Util.isArray(size) || (size = [ size, size, size ]);
} }
if (regularShape[shape] == null) { if (regularShape[shape] == null) {
uvs.push(0,0,1,0,1,1,1,1,0,1,0,0) uvs.push(0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0);
shape = 'square'; shape = 'square';
} }
const vert = regularShape[shape](shapeType); const vert = regularShape[shape](shapeType);

View File

@ -53,16 +53,15 @@ export default class PointLayer extends Layer {
u_zoom: this.scene.getZoom() u_zoom: this.scene.getZoom()
}); });
mtl.setDefinesvalue('SHAPE', true); mtl.setDefinesvalue('SHAPE', true);
if(shape=='radar') { if (shape === 'radar') {
mtl.fragmentShader = radar; mtl.fragmentShader = radar;
} }
if(shape=='warn') { if (shape === 'warn') {
mtl.fragmentShader = warn; mtl.fragmentShader = warn;
} }
} else { // sdf 绘制点 } else { // sdf 绘制点
mtl = new PointMaterial({ mtl = new PointMaterial({
u_opacity: opacity, u_opacity: opacity,
@ -83,11 +82,9 @@ export default class PointLayer extends Layer {
if (this.shapeType === 'image') { if (this.shapeType === 'image') {
geometry.addAttribute('uv', new THREE.Float32BufferAttribute(attributes.uvs, 2)); geometry.addAttribute('uv', new THREE.Float32BufferAttribute(attributes.uvs, 2));
geometry.addAttribute('a_size', new THREE.Float32BufferAttribute(attributes.sizes, 1)); geometry.addAttribute('a_size', new THREE.Float32BufferAttribute(attributes.sizes, 1));
} else if(this.shapeType=== undefined) } else if (this.shapeType === undefined) {
{
geometry.addAttribute('a_size', new THREE.Float32BufferAttribute(attributes.sizes, 1)); geometry.addAttribute('a_size', new THREE.Float32BufferAttribute(attributes.sizes, 1));
} } else { // 多边形面
else { // 多边形面
geometry.addAttribute('normal', new THREE.Float32BufferAttribute(attributes.normals, 3)); geometry.addAttribute('normal', new THREE.Float32BufferAttribute(attributes.normals, 3));
geometry.addAttribute('a_shape', new THREE.Float32BufferAttribute(attributes.shapePositions, 3)); geometry.addAttribute('a_shape', new THREE.Float32BufferAttribute(attributes.shapePositions, 3));
geometry.addAttribute('a_size', new THREE.Float32BufferAttribute(attributes.a_size, 3)); geometry.addAttribute('a_size', new THREE.Float32BufferAttribute(attributes.a_size, 3));

View File

@ -10,23 +10,22 @@ export default class CSVSource extends Source {
const y = this.get('y'); const y = this.get('y');
const x1 = this.get('x1'); const x1 = this.get('x1');
const y1 = this.get('y1'); const y1 = this.get('y1');
const coords = this.get('coordinates') const coords = this.get('coordinates');
this.propertiesData = [];// 临时使用 this.propertiesData = [];// 临时使用
this.geoData = []; this.geoData = [];
let csvdata = data; let csvdata = data;
Util.isArray(csvdata) || (csvdata = csvParse(data)); Util.isArray(csvdata) || (csvdata = csvParse(data));
this.propertiesData = csvdata; this.propertiesData = csvdata;
csvdata.forEach((col, featureIndex) => { csvdata.forEach((col, featureIndex) => {
let coordinates = [];
if(col['coordinates']){ if (col.coordinates) {
coordinates = col['coordinates']; coordinates = col.coordinates;
} }
let coordinates = [ col[x], col[y] ]; let coordinates = [ col[x], col[y] ];
if (x1 && y1) { if (x1 && y1) {
coordinates = [[ col[x], col[y] ], [ col[x1], col[y1] ]]; coordinates = [[ col[x], col[y] ], [ col[x1], col[y1] ]];
} }
if(coords&& col['coords']) if (coords && col.coords) { coordinates = col.coords; }
coordinates =col['coords'];
col._id = featureIndex + 1; col._id = featureIndex + 1;
this._coordProject(coordinates); this._coordProject(coordinates);
this.geoData.push(this._coordProject(coordinates)); this.geoData.push(this._coordProject(coordinates));

View File

@ -25,6 +25,7 @@ export default class GeojsonSource extends Source {
const data = this.get('data'); const data = this.get('data');
const selectFeatureIds = []; const selectFeatureIds = [];
let featureStyleId = 0; let featureStyleId = 0;
/* eslint-disable */
turfMeta.flattenEach(data, (currentFeature, featureIndex, multiFeatureIndex) => { turfMeta.flattenEach(data, (currentFeature, featureIndex, multiFeatureIndex) => {
/* eslint-disable */ /* eslint-disable */
if (featureIndex === (featureId)) { if (featureIndex === (featureId)) {