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

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

View File

@ -88,8 +88,7 @@
},
"pre-commit": {
"run": [
"lint",
"test-all"
"lint"
],
"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 { Mesh } from 'three/src/objects/Mesh.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 { PerspectiveCamera } from 'three/src/cameras/PerspectiveCamera.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 { Matrix3 } from 'three/src/math/Matrix3.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 { Vector3 } from 'three/src/math/Vector3.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 { PointsMaterial } from 'three/src/materials/PointsMaterial.js';
// export { VideoTexture } from 'three/src/textures/VideoTexture.js';
export { DataTexture } from 'three/src/textures/DataTexture.js';
export {
Float64BufferAttribute,

View File

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

View File

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

View File

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

View File

@ -20,8 +20,8 @@ export default class CSVSource extends Source {
if (col.coordinates) {
coordinates = col.coordinates;
}
if (x && y) { coordinates = [ col[x], col[y] ]; }
if (x1 && y1) {
if (x && y) { coordinates = [ col[x], col[y] ]; } // 点数据
if (x1 && y1) { // 弧线 或者线段
coordinates = [[ col[x], col[y] ], [ col[x1], col[y1] ]];
}
if (coords && col.coords) { coordinates = col.coords; }