代码拉取完成,页面将自动刷新
function createMap(res) {
res = JSON.parse(res);
res.features.forEach((province) => {
// 省市的物体
let provinceObj = new THREE.Object3D();
if (province.geometry.type === "Polygon") {
province.geometry.coordinates.forEach((polygon) => {
let shape = new THREE.Shape();
let arr = [];
for (let i = 0; i < polygon.length; i++) {
let (x, y) = projection(polygon[i]);
if (i === 0) {
shape.moveTo(x, -y);
} else {
shape.lineTo(x, -y);
}
arr.push(x, -y, 1);
}
let mesh = createPolygon(shape, arr, province);
provinceObj.add(mesh);
});
} else if (province.geometry.type === "MultiPolygon") {
province.geometry.coordinates.forEach((multipolygon) => {
multipolygon.forEach((polygon) => {
let shape = new THREE.Shape();
let arr = [];
for (let i = 0; i < polygon.length; i++) {
let (x, y) = projection(polygon[i]);
if (i === 0) {
shape.moveTo(x, -y);
} else {
shape.lineTo(x, -y);
}
arr.push(x, -y, 1);
}
let mesh = createPolygon(shape, arr, province);
provinceObj.add(mesh);
});
});
}
chinaObj.add(provinceObj);
});
}
function createPolygon(shape, arr, province) {
let extrudeMats = {
steps: 20,
depth: 0.2,
bevelEnabled: false,
bevelThickness: 1,
bevelSize: 1,
bevelOffset: 0,
bevelSegments: 1
}
let geo = new THREE.ExtrudeGeometry(shape);
let mesh = new THREE.Mesh(geo, extrudeMats);
if (province.properties.name) {
mesh.name = province.properties.name;
}
// 其他代码...
return mesh;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。