fix(threejs): remove unuse import

This commit is contained in:
李正学 2019-01-24 16:26:47 +08:00
parent 71e365483d
commit 6c283ef1b0
7 changed files with 210 additions and 215 deletions

View File

@ -127,6 +127,10 @@ scene.on('loaded', () => {
.render(); .render();
}); });
scene.on('zoomchange',(e)=>{
console.log(e);
})
}); });

View File

@ -88,8 +88,7 @@
}, },
"pre-commit": { "pre-commit": {
"run": [ "run": [
"lint", "lint"
"test-all"
], ],
"silent": false "silent": false
}, },

View File

@ -9,8 +9,6 @@ export { Points } from 'three/src/objects/Points.js';
export { LineSegments } from 'three/src/objects/LineSegments.js'; export { LineSegments } from 'three/src/objects/LineSegments.js';
export { Mesh } from 'three/src/objects/Mesh.js'; export { Mesh } from 'three/src/objects/Mesh.js';
export { Texture } from 'three/src/textures/Texture.js'; export { Texture } from 'three/src/textures/Texture.js';
// export { DirectionalLight } from 'three/src/lights/DirectionalLight.js';
// export { AmbientLight } from 'three/src/lights/AmbientLight.js';
export { WebGLRenderTarget } from 'three/src/renderers/WebGLRenderTarget.js'; export { WebGLRenderTarget } from 'three/src/renderers/WebGLRenderTarget.js';
export { PerspectiveCamera } from 'three/src/cameras/PerspectiveCamera.js'; export { PerspectiveCamera } from 'three/src/cameras/PerspectiveCamera.js';
export { BufferGeometry } from 'three/src/core/BufferGeometry.js'; export { BufferGeometry } from 'three/src/core/BufferGeometry.js';
@ -18,15 +16,10 @@ export { Raycaster } from 'three/src/core/Raycaster.js';
export { Matrix4 } from 'three/src/math/Matrix4.js'; export { Matrix4 } from 'three/src/math/Matrix4.js';
export { Matrix3 } from 'three/src/math/Matrix3.js'; export { Matrix3 } from 'three/src/math/Matrix3.js';
export { Line } from 'three/src/objects/Line.js'; export { Line } from 'three/src/objects/Line.js';
// export { LineLoop } from 'three/src/objects/LineLoop.js';
export { Vector4 } from 'three/src/math/Vector4.js'; export { Vector4 } from 'three/src/math/Vector4.js';
export { Vector3 } from 'three/src/math/Vector3.js'; export { Vector3 } from 'three/src/math/Vector3.js';
export { Vector2 } from 'three/src/math/Vector2.js'; export { Vector2 } from 'three/src/math/Vector2.js';
// export { TextureLoader } from 'three/src/loaders/TextureLoader.js';
// export { LineDashedMaterial } from 'three/src/materials/LineDashedMaterial.js';
export { ShaderMaterial } from 'three/src/materials/ShaderMaterial.js'; export { ShaderMaterial } from 'three/src/materials/ShaderMaterial.js';
// export { PointsMaterial } from 'three/src/materials/PointsMaterial.js';
// export { VideoTexture } from 'three/src/textures/VideoTexture.js';
export { DataTexture } from 'three/src/textures/DataTexture.js'; export { DataTexture } from 'three/src/textures/DataTexture.js';
export { export {
Float64BufferAttribute, Float64BufferAttribute,

View File

@ -1,246 +1,246 @@
const SDFCommonWordsKey = '_AMap_sdf_com_words'; // const SDFCommonWordsKey = '_AMap_sdf_com_words';
/** // /**
* SDF 常用字获取/存储/check // * SDF 常用字获取/存储/check
* // *
*/ // */
const SDFCommonWords = { // const SDFCommonWords = {
store() { // store() {
}, // },
/** // /**
* 检查一个字符是否在常用字中 // * 检查一个字符是否在常用字中
* @param {*} charcode 汉字 // * @param {*} charcode 汉字
*/ // */
check(charcode) { // check(charcode) {
const range = this.range || []; // const range = this.range || [];
const info = this.info || {}; // const info = this.info || {};
if (typeof charcode !== 'number') { // if (typeof charcode !== 'number') {
charcode = charcode.substr(0).charCodeAt(0); // charcode = charcode.substr(0).charCodeAt(0);
} // }
for (let i = 0; i < range.length; i++) { // for (let i = 0; i < range.length; i++) {
const curRange = range[i]; // const curRange = range[i];
const [ rangeStart, rangeEnd ] = curRange.split('-'); // const [ rangeStart, rangeEnd ] = curRange.split('-');
if (charcode >= rangeStart && charcode <= rangeEnd) { // if (charcode >= rangeStart && charcode <= rangeEnd) {
const curInfo = info[curRange] && info[curRange].info || {}; // const curInfo = info[curRange] && info[curRange].info || {};
if (curInfo[charcode]) { // if (curInfo[charcode]) {
return true; // return true;
} // }
} // }
} // }
return false; // return false;
}, // },
/** // /**
* 获取纹理和位置信息 // * 获取纹理和位置信息
* @param list // * @param list
* @param cb // * @param cb
*/ // */
getImagesAndInfo(list, cb) { // getImagesAndInfo(list, cb) {
const range = this.range; // const range = this.range;
}, // },
loadCanvas(url, range, done) { // loadCanvas(url, range, done) {
try { // try {
const xhr = new XMLHttpRequest(); // const xhr = new XMLHttpRequest();
xhr.open('GET', url); // xhr.open('GET', url);
// 直接用 blob 格式 load 图片文件,方便直接转换成 base64 // // 直接用 blob 格式 load 图片文件,方便直接转换成 base64
// 转成 base64 便于存储 // // 转成 base64 便于存储
// 使用 canvas 转换 base64 容易有损 // // 使用 canvas 转换 base64 容易有损
xhr.responseType = 'blob'; // xhr.responseType = 'blob';
xhr.onerror = function() { // xhr.onerror = function() {
done({ code: 0 }); // done({ code: 0 });
}; // };
xhr.onload = function() { // xhr.onload = function() {
if (xhr.status === 200) { // if (xhr.status === 200) {
const reader = new FileReader(); // const reader = new FileReader();
reader.onload = () => { // reader.onload = () => {
done(reader.result, range); // done(reader.result, range);
}; // };
reader.readAsDataURL(xhr.response); // reader.readAsDataURL(xhr.response);
} else { // } else {
done({ code: 0 }); // done({ code: 0 });
} // }
}; // };
xhr.send(); // xhr.send();
} catch (err) { // } catch (err) {
done({ code: 0 }); // done({ code: 0 });
} // }
}, // },
loadImages(urls = []) { // loadImages(urls = []) {
const deferred = $.Deferred(); // const deferred = $.Deferred();
const totalNumbers = urls.length; // const totalNumbers = urls.length;
const localInfo = this.info; // const localInfo = this.info;
let loadPicNum = 0; // let loadPicNum = 0;
for (let i = 0; i < urls.length; i++) { // for (let i = 0; i < urls.length; i++) {
const { url, range } = urls[i]; // const { url, range } = urls[i];
this.loadCanvas(url, range, (base64, range) => { // this.loadCanvas(url, range, (base64, range) => {
// image to base64 // // image to base64
loadPicNum++; // loadPicNum++;
!localInfo[range] && (localInfo[range] = {}); // !localInfo[range] && (localInfo[range] = {});
localInfo[range].pic = base64; // localInfo[range].pic = base64;
this.info = localInfo; // this.info = localInfo;
// todo: temp 暂时用 localstorage 存储,因为数据比较大,最好使用 indexDB // // todo: temp 暂时用 localstorage 存储,因为数据比较大,最好使用 indexDB
localStorage.setItem(SDFCommonWordsKey, JSON.stringify(localInfo)); // localStorage.setItem(SDFCommonWordsKey, JSON.stringify(localInfo));
if (loadPicNum === totalNumbers) { // if (loadPicNum === totalNumbers) {
deferred.resolve(); // deferred.resolve();
} // }
}); // });
} // }
return deferred; // return deferred;
}, // },
loadInfo(urls) { // loadInfo(urls) {
const deferred = $.Deferred(); // const deferred = $.Deferred();
const totalNumbers = urls.length; // const totalNumbers = urls.length;
const localInfo = this.info; // const localInfo = this.info;
let loadInfoNum = 0; // let loadInfoNum = 0;
for (let i = 0; i < urls.length; i++) { // for (let i = 0; i < urls.length; i++) {
const { url, range } = urls[i]; // const { url, range } = urls[i];
$.ajax({ // $.ajax({
url, // url,
dataType: 'json', // dataType: 'json',
success: data => { // success: data => {
loadInfoNum++; // loadInfoNum++;
!localInfo[range] && (localInfo[range] = {}); // !localInfo[range] && (localInfo[range] = {});
localInfo[range].info = data; // localInfo[range].info = data;
this.info = localInfo; // this.info = localInfo;
localStorage.setItem(SDFCommonWordsKey, JSON.stringify(localInfo)); // localStorage.setItem(SDFCommonWordsKey, JSON.stringify(localInfo));
if (loadInfoNum === totalNumbers) { // if (loadInfoNum === totalNumbers) {
deferred.resolve(); // deferred.resolve();
} // }
}, // },
error: () => { // error: () => {
} // }
}); // });
} // }
return deferred; // return deferred;
}, // },
getTotalAssets(info, cb) { // getTotalAssets(info, cb) {
const { range = [], urlPrefix } = info; // const { range = [], urlPrefix } = info;
const picUrls = []; // const picUrls = [];
const infoUrls = []; // const infoUrls = [];
this.range = range; // this.range = range;
for (let i = 0; i < range.length; i++) { // for (let i = 0; i < range.length; i++) {
const curRange = range[i]; // const curRange = range[i];
const baseUrl = urlPrefix + curRange; // const baseUrl = urlPrefix + curRange;
const picUrl = baseUrl + '.png'; // const picUrl = baseUrl + '.png';
const infoUrl = baseUrl + '.json'; // const infoUrl = baseUrl + '.json';
picUrls.push({ range: curRange, url: picUrl }); // picUrls.push({ range: curRange, url: picUrl });
infoUrls.push({ range: curRange, url: infoUrl }); // infoUrls.push({ range: curRange, url: infoUrl });
} // }
const imageDeferred = this.loadImages(picUrls); // const imageDeferred = this.loadImages(picUrls);
const infoDeferred = this.loadInfo(infoUrls); // const infoDeferred = this.loadInfo(infoUrls);
$.when(imageDeferred, infoDeferred) // $.when(imageDeferred, infoDeferred)
.then(() => { // .then(() => {
// all info load complete // // all info load complete
// console.log("all info load complete", " -- ", 1); // // console.log("all info load complete", " -- ", 1);
cb && cb(this.info); // cb && cb(this.info);
}, () => { // }, () => {
// fail // // fail
}); // });
}, // },
// 获取数据 // // 获取数据
getData(cb) { // getData(cb) {
if (!_.isEmpty(this.info)) { // if (!_.isEmpty(this.info)) {
cb && cb(this.info); // cb && cb(this.info);
} else { // } else {
this.getRemoteData(cb); // this.getRemoteData(cb);
} // }
}, // },
/** // /**
* 从服务获取数据什么时候强制去取一回数据过期 // * 从服务获取数据,什么时候强制去取一回数据?过期?
* @param cb // * @param cb
*/ // */
getRemoteData(cb) { // getRemoteData(cb) {
const self = this; // const self = this;
$.ajax({ // $.ajax({
url: '/getcommonwords', // url: '/getcommonwords',
dataType: 'json', // dataType: 'json',
success: data => { // success: data => {
if (data.code == 1) { // if (data.code == 1) {
const info = data.data; // const info = data.data;
self.getTotalAssets(info, cb); // self.getTotalAssets(info, cb);
} // }
} // }
}); // });
}, // },
destroy() { // destroy() {
}, // },
init() { // init() {
let info = localStorage.getItem(SDFCommonWordsKey); // let info = localStorage.getItem(SDFCommonWordsKey);
this.range = []; // this.range = [];
this.info = {}; // this.info = {};
if (info) { // if (info) {
info = JSON.parse(info); // info = JSON.parse(info);
this.range = Object.keys(info); // this.range = Object.keys(info);
this.info = info; // this.info = info;
} // }
this.info = info || {}; // this.info = info || {};
} // }
}; // };
export default SDFCommonWords; // export default SDFCommonWords;

View File

@ -1,10 +1,9 @@
import { getJSON } from '../../../util/ajax'; import { getJSON } from '../../../util/ajax';
import * as THREE from '../../../core/three';
import EventEmitter from 'wolfy87-eventemitter'; import EventEmitter from 'wolfy87-eventemitter';
import Global from '../../../global'; import Global from '../../../global';
const Space = 1; // const Space = 1;
const metrics = { const metrics = {
buffer: 3, buffer: 3,
family: 'ios9', family: 'ios9',
@ -75,7 +74,7 @@ function loadTextTexture(url, cb) {
* 计算每个标注词语的位置 * 计算每个标注词语的位置
* @param {*} chars 文本信息 * @param {*} chars 文本信息
* @param {*} pos 文字三维空间坐标 * @param {*} pos 文字三维空间坐标
* @param {*} chr 字符 * @param {*} text 字符
* @param {*} pen 字符在词语的偏移量 * @param {*} pen 字符在词语的偏移量
* @param {*} size 字体大小 * @param {*} size 字体大小
* @param {*} colors 颜色 * @param {*} colors 颜色
@ -157,26 +156,26 @@ function drawGlyph(chars, pos, text, pen, size, colors, textureElements, originP
} }
function measureText(text, size) { // function measureText(text, size) {
const dimensions = { // const dimensions = {
advance: 0 // advance: 0
}; // };
const metrics = this.metrics; // const metrics = this.metrics;
const scale = size / metrics.size; // const scale = size / metrics.size;
for (let i = 0; i < text.length; i++) { // for (let i = 0; i < text.length; i++) {
const code = text.charCodeAt(i); // const code = text.charCodeAt(i);
const horiAdvance = metrics.chars[code][4]; // const horiAdvance = metrics.chars[code][4];
dimensions.advance += (horiAdvance + Space) * scale; // dimensions.advance += (horiAdvance + Space) * scale;
} // }
return dimensions; // return dimensions;
} // }
function creatTexture(image) { // function creatTexture(image) {
this.bufferStruct.textSize = [ image.width, image.height ]; // this.bufferStruct.textSize = [ image.width, image.height ];
const texture = new THREE.Texture(image); // const texture = new THREE.Texture(image);
texture.minFilter = THREE.LinearFilter; // texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.ClampToEdgeWrapping; // texture.magFilter = THREE.ClampToEdgeWrapping;
texture.needsUpdate = true; // texture.needsUpdate = true;
return texture; // return texture;
} // }

View File

@ -92,7 +92,7 @@ export default class TextBuffer extends BufferBase {
/** /**
* 计算每个标注词语的位置 * 计算每个标注词语的位置
* @param {*} pos 文字三维空间坐标 * @param {*} pos 文字三维空间坐标
* @param {*} chr 字符 * @param {*} text 字符
* @param {*} pen 字符在词语的偏移量 * @param {*} pen 字符在词语的偏移量
* @param {*} size 字体大小 * @param {*} size 字体大小
* @param {*} colors 颜色 * @param {*} colors 颜色
@ -114,10 +114,10 @@ export default class TextBuffer extends BufferBase {
let width = 24; // metric[0]; let width = 24; // metric[0];
let height = 24;// metric[1]; let height = 24;// metric[1];
const horiBearingX = metric[2]; // const horiBearingX = metric[2];
// const horiBearingY = metric[3]; // const horiBearingY = metric[3];
const horiAdvance = metric[4]; // const horiAdvance = metric[4];
// const posX = metric[5]; // const posX = metric[5];
// const posY = metric[6]; // const posY = metric[6];
const posX = x; const posX = x;

View File

@ -20,8 +20,8 @@ export default class CSVSource extends Source {
if (col.coordinates) { if (col.coordinates) {
coordinates = col.coordinates; coordinates = col.coordinates;
} }
if (x && y) { coordinates = [ col[x], col[y] ]; } if (x && y) { 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) { coordinates = col.coords; } if (coords && col.coords) { coordinates = col.coords; }