mirror of https://gitee.com/antv-l7/antv-l7
fix: polygon triangle
This commit is contained in:
parent
0b95943bac
commit
701f2ea411
|
@ -9,7 +9,7 @@ export default () => {
|
||||||
|
|
||||||
const scene = new Scene({
|
const scene = new Scene({
|
||||||
id: 'map',
|
id: 'map',
|
||||||
map: new GaodeMap({
|
map: new Map({
|
||||||
style: 'light',
|
style: 'light',
|
||||||
pitch: 0,
|
pitch: 0,
|
||||||
center: [ 114.07737552216226, 22.542656745583486 ],
|
center: [ 114.07737552216226, 22.542656745583486 ],
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -355,7 +355,9 @@ export interface ICameraOptions {
|
||||||
type ICenter = [number, number];
|
type ICenter = [number, number];
|
||||||
scene.setZoomAndCenter(zoom, center);
|
scene.setZoomAndCenter(zoom, center);
|
||||||
```
|
```
|
||||||
|
|
||||||
### setZoom(zoom: number): void 设置地图旋转
|
### setZoom(zoom: number): void 设置地图旋转
|
||||||
|
|
||||||
设置地图缩放等级
|
设置地图缩放等级
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
|
|
@ -64,11 +64,29 @@ export function PointFillTriangulation(feature: IEncodeFeature) {
|
||||||
|
|
||||||
export function polygonFillTriangulation(feature: IEncodeFeature) {
|
export function polygonFillTriangulation(feature: IEncodeFeature) {
|
||||||
const { coordinates } = feature;
|
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;
|
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 {
|
return {
|
||||||
indices: earcut(vertices, holes, dimensions),
|
indices: triangles,
|
||||||
vertices,
|
vertices,
|
||||||
size: dimensions,
|
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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue