代码拉取完成,页面将自动刷新
importScripts('js/philogl/PhiloGL.js');
PhiloGL.unpack(self);
onmessage = function(e) {
var cities = e.data,
citiesLayer = createCitiesLayer(cities);
postMessage(citiesLayer);
};
function createCitiesLayer(cities) {
var pi = Math.PI,
pi2 = pi * 2,
sin = Math.sin,
cos = Math.cos,
index = 0,
cityIndex = [],
vertices = [],
normals = [],
pickingColors = [],
indices = [],
vertexCount = 0,
step = Object.keys(cities).length / 5 >> 0,
slice = Array.prototype.slice,
position = {};
for (var prop in cities) {
var city = cities[prop],
theta = pi2 - (+city[3] + 180) / 360 * pi2,
phi = pi - (+city[2] + 90) / 180 * pi,
sinTheta = sin(theta),
cosTheta = cos(theta),
sinPhi = sin(phi),
cosPhi = cos(phi),
ux = cosTheta * sinPhi,
uy = cosPhi,
uz = sinTheta * sinPhi,
coords = [ux, uy, uz],
r = 0,
g = ((index / 256) >> 0) % 256,
b = index % 256,
sphere = new O3D.Sphere({
nlat: 5,
nlong: 5,
radius: 1 / 120,
pickingColors: [0, g / 255, b / 255, 1]
}),
tvertices = slice.call(sphere.vertices).map(function(v, i) { return coords[i % 3] + v; });
position[prop] = coords;
vertices.push.apply(vertices, tvertices);
normals.push.apply(normals, slice.call(sphere.normals));
pickingColors.push.apply(pickingColors, slice.call(sphere.pickingColors));
indices.push.apply(indices, slice.call(sphere.indices).map(function(index) { return index + vertexCount; }));
cityIndex[index++] = prop;
vertexCount += tvertices.length / 3;
if ((index % step) === 0) {
postMessage(Math.round(index / step * 20));
}
}
return {
pickable: true,
vertices: vertices,
normals: normals,
indices: indices,
pickingColors: pickingColors,
citiesIndex: cityIndex,
program: 'layer',
uniforms: {
colorUfm: [1, 1, 0.5, 1]
}
};
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。