Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (this.options['project']) {
c = this.map.coordinateToPoint(new maptalks.Coordinate(data.vertices[i], data.vertices[i + 1]), targetZ);
bottom.push(c.x, c.y, 0);
top.push(c.x, c.y, height);
} else {
bottom.push(data.vertices[i], data.vertices[i + 1], 0);
top.push(data.vertices[i], data.vertices[i + 1], height);
}
}
data.vertices = bottom;
let triangles = earcut(data.vertices, data.holes, dimension);
if (triangles.length <= 2) {
return;
}
const deviation = earcut.deviation(data.vertices, data.holes, dimension, triangles);
if (Math.round(deviation * 1E3) / 1E3 !== 0) {
if (console) {
console.warn('Failed triangluation.');
}
return;
}
const count = bottom.length / dimension;
const preCount = this.vertexArray.length / dimension;
if (preCount > 0) {
triangles = triangles.map(e => e + preCount);
}
// push bottom vertice
maptalks.Util.pushIn(this.vertexArray, bottom);
// push bottom elements
const data = earcut.flatten(vertice);
if (this.options['project']) {
const v = [];
let c;
for (let i = 0, l = data.vertices.length; i < l; i += 2) {
c = this.map.coordinateToPoint(new maptalks.Coordinate(data.vertices[i], data.vertices[i + 1]), targetZ);
v.push(c.x, c.y);
}
data.vertices = v;
}
let triangles = earcut(data.vertices, data.holes, 2);
if (triangles.length <= 2) {
return this;
}
const deviation = earcut.deviation(data.vertices, data.holes, 2, triangles);
if (Math.round(deviation * 1E3) / 1E3 !== 0) {
if (console) {
console.warn('Failed triangluation.');
}
return this;
}
const count = this.vertexArray.length / 2;
if (count > 0) {
triangles = triangles.map(e => e + count);
}
maptalks.Util.pushIn(this.vertexArray, data.vertices);
maptalks.Util.pushIn(this.elementArray, triangles);
// 添加样式数据
this._addTexCoords(data.vertices.length / 2, style);
return this;