fix: polygon triangle

This commit is contained in:
lzxue 2022-12-09 23:23:48 +08:00
parent 0b95943bac
commit 701f2ea411
4 changed files with 1276 additions and 69 deletions

View File

@ -9,7 +9,7 @@ export default () => {
const scene = new Scene({
id: 'map',
map: new GaodeMap({
map: new Map({
style: 'light',
pitch: 0,
center: [ 114.07737552216226, 22.542656745583486 ],

File diff suppressed because it is too large Load Diff

View File

@ -355,7 +355,9 @@ export interface ICameraOptions {
type ICenter = [number, number];
scene.setZoomAndCenter(zoom, center);
```
### setZoom(zoom: number): void 设置地图旋转
设置地图缩放等级
```javascript

View File

@ -64,11 +64,29 @@ export function PointFillTriangulation(feature: IEncodeFeature) {
export function polygonFillTriangulation(feature: IEncodeFeature) {
const { coordinates } = feature;
const flattengeo = earcut.flatten(coordinates as number[][][]);
// @ts-ignore
const flatCoord = coordinates.map((coord: number[][]) => coord.map((lnglat: [number, number]) => [lnglat[0], project_y(lnglat[1])]))
const flattengeo = earcut.flatten(flatCoord as number[][][]);
const { vertices, dimensions, holes } = flattengeo;
// https://github.com/mapbox/earcut/issues/159
const triangles = earcut(vertices, holes, dimensions);
for (let i = 0; i < vertices.length; i += 2) {
vertices[i + 1] = un_project_y(vertices[i + 1]);
}
return {
indices: earcut(vertices, holes, dimensions),
indices: triangles,
vertices,
size: dimensions,
};
}
function project_y( y: number) {
return Math.log(Math.tan(Math.PI * y / 360))
}
function un_project_y( y: number) {
return Math.atan(Math.exp(y)) * 360 / Math.PI
}