Feat earcut (#1536)

* fix: 文本更新

* fix: iconfont 更新

* fix: 移除console

* docs: scene 增加 setzoom

* fix: 地图实例demo

* fix: polygon triangle

* fix: polygon triangle  dimensions

* fix: 高德地图v2 坐标转换
This commit is contained in:
@thinkinggis 2022-12-13 10:19:33 +08:00 committed by GitHub
parent 4fa5a324db
commit cac672016c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1286 additions and 98 deletions

View File

@ -1,19 +0,0 @@
name: 🤖 Sync to Gitee Mirror
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 🔁 Sync to Gitee
uses: wearerequired/git-mirror-action@master
env:
# 注意在 Settings->Secrets 配置 GITEE_RSA_PRIVATE_KEY
SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
with:
# 注意替换为你的 GitHub 源仓库地址
source-repo: 'git@github.com:antvis/L7.git'
# 注意替换为你的 Gitee 目标仓库地址
destination-repo: 'git@gitee.com:antv-l7/antv-l7.git'

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 ],

View File

@ -1,5 +1,5 @@
import { Scene, PolygonLayer, LineLayer, PointLayer } from "@antv/l7";
import { Mapbox } from "@antv/l7-maps";
import { GaodeMap } from "@antv/l7-maps";
import React, { useEffect } from 'react';
const list = {
portrKey: "PROVINCE_CITY_DITU",
@ -2494,7 +2494,7 @@ export default () => {
useEffect( () => {
const scene = new Scene({
id: "map",
map: new Mapbox({
map: new GaodeMap({
pitch: 0,
style: "blank",
center: [116.368652, 39.93866],

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
import { Scene, PointLayer } from '@antv/l7';
import { GaodeMap } from '@antv/l7-maps';
window.onLoad = function() {
function initMap() {
// 全局加载高德地图API
const map = new AMap.Map('map', {
viewMode: '3D',
mapStyle: 'amap://styles/darkblue',
@ -49,11 +50,5 @@ window.onLoad = function() {
scene.addLayer(pointLayer);
});
});
};
const url = 'https://webapi.amap.com/maps?v=1.4.15&key=15cd8a57710d40c9b7c0e3cc120f1200&callback=onLoad';
// const url = 'https://webapi.amap.com/maps?v=2.0&key=ff533602d57df6f8ab3b0fea226ae52f&callback=onLoad';
const jsapi = document.createElement('script');
jsapi.charset = 'utf-8';
jsapi.src = url;
document.head.appendChild(jsapi);
}
initMap();

View File

@ -66,9 +66,34 @@ export function polygonFillTriangulation(feature: IEncodeFeature) {
const { coordinates } = feature;
const flattengeo = earcut.flatten(coordinates as number[][][]);
const { vertices, dimensions, holes } = flattengeo;
for (let i = 0; i < vertices.length; i += dimensions) {
vertices[i + 1] = project_y(vertices[i + 1]);
}
// https://github.com/mapbox/earcut/issues/159
const triangles = earcut(vertices, holes, dimensions);
for (let i = 0; i < vertices.length; i += dimensions) {
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) {
if(y > 85 || y<-85) {
return y
}
return Math.log(Math.tan((Math.PI * y) / 360));
}
function un_project_y(y: number) {
if(y > 85 || y<-85) {
return y
}
return (Math.atan(Math.exp(y)) * 360) / Math.PI;
}