mirror of https://gitee.com/antv-l7/antv-l7
Merge branch 'master' of https://github.com/antvis/L7
This commit is contained in:
commit
6547b80198
|
@ -104,18 +104,25 @@ void main() {
|
||||||
|
|
||||||
// gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, a_Size.y, 1.0));
|
// gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, a_Size.y, 1.0));
|
||||||
|
|
||||||
float h = float((a_Position.z)) * u_vertexScale; // 线顶点的高度 - 兼容不存在第三个数值的情况
|
float h = float(a_Position.z) * u_vertexScale; // 线顶点的高度 - 兼容不存在第三个数值的情况
|
||||||
|
|
||||||
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x
|
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x
|
||||||
// gl_Position = u_Mvp * (vec4(project_pos.xy + offset, a_Size.y, 1.0));
|
gl_Position = u_Mvp * (vec4(project_pos.xy + offset, project_pixel(a_Size.y) + h * 0.2, 1.0));
|
||||||
gl_Position = u_Mvp * (vec4(project_pos.xy + offset, a_Size.y / 8.0 + h, 1.0)); // 额外除 8.0 是为了和gaode1.x的高度兼容
|
|
||||||
} else {
|
} else {
|
||||||
float lineHeight = a_Size.y;
|
float lineHeight = a_Size.y;
|
||||||
// 兼容 mapbox 在线高度上的效果表现基本一致
|
// 兼容 mapbox 在线高度上的效果表现基本一致
|
||||||
if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {
|
if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {
|
||||||
lineHeight = lineHeight*2.0/pow(2.0, 20.0 - u_Zoom);
|
// 保持高度相对不变
|
||||||
|
h *= 2.0/pow(2.0, 20.0 - u_Zoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
// #define COORDINATE_SYSTEM_P20 5.0
|
||||||
|
// #define COORDINATE_SYSTEM_P20_OFFSET 6.0
|
||||||
|
// amap1.x
|
||||||
|
if(u_CoordinateSystem == COORDINATE_SYSTEM_P20 || u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) {
|
||||||
|
// 保持高度相对不变
|
||||||
|
lineHeight *= pow(2.0, 20.0 - u_Zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, lineHeight + h, 1.0));
|
gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, lineHeight + h, 1.0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,25 +102,37 @@ export default class ExtrudePolyline {
|
||||||
const total = points.length;
|
const total = points.length;
|
||||||
let count = complex.startIndex;
|
let count = complex.startIndex;
|
||||||
for (let i = 1; i < total; i++) {
|
for (let i = 1; i < total; i++) {
|
||||||
const last = points[i - 1] as vec3;
|
const last = points[i - 1];
|
||||||
const originLast = originPoints[i - 1] as vec2;
|
last.push(originPoints[i - 1][2] ?? 0);
|
||||||
|
// @ts-ignore
|
||||||
|
const originLast = originPoints[i - 1] as vec3;
|
||||||
|
|
||||||
const cur = points[i] as vec3;
|
const cur = points[i];
|
||||||
const originCur = originPoints[i] as vec2;
|
cur.push(originPoints[i][2] ?? 0);
|
||||||
|
// @ts-ignore
|
||||||
|
const originCur = originPoints[i] as vec3;
|
||||||
|
|
||||||
const next = i < points.length - 1 ? points[i + 1] : null;
|
const next =
|
||||||
|
i < points.length - 1
|
||||||
|
? [...points[i + 1], originPoints[i + 1][2] ?? 0]
|
||||||
|
: null;
|
||||||
const originNext =
|
const originNext =
|
||||||
i < originPoints.length - 1 ? originPoints[i + 1] : null;
|
i < originPoints.length - 1 ? originPoints[i + 1] : null;
|
||||||
|
|
||||||
const amt = this.segment_gaode2(
|
const amt = this.segment_gaode2(
|
||||||
complex,
|
complex,
|
||||||
count,
|
count,
|
||||||
last,
|
// @ts-ignore
|
||||||
cur,
|
last as vec3,
|
||||||
|
// @ts-ignore
|
||||||
|
cur as vec3,
|
||||||
|
// @ts-ignore
|
||||||
next as vec3,
|
next as vec3,
|
||||||
|
// @ts-ignore
|
||||||
originLast,
|
originLast,
|
||||||
originCur,
|
originCur,
|
||||||
originNext as vec2,
|
// @ts-ignore
|
||||||
|
originNext as vec3,
|
||||||
);
|
);
|
||||||
count += amt;
|
count += amt;
|
||||||
}
|
}
|
||||||
|
@ -166,9 +178,9 @@ export default class ExtrudePolyline {
|
||||||
last: vec3,
|
last: vec3,
|
||||||
cur: vec3,
|
cur: vec3,
|
||||||
next: vec3,
|
next: vec3,
|
||||||
originLast: vec2,
|
originLast: vec3,
|
||||||
originCur: vec2,
|
originCur: vec3,
|
||||||
originNext: vec2,
|
originNext: vec3,
|
||||||
) {
|
) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
const indices = complex.indices;
|
const indices = complex.indices;
|
||||||
|
@ -184,9 +196,11 @@ export default class ExtrudePolyline {
|
||||||
number,
|
number,
|
||||||
number,
|
number,
|
||||||
];
|
];
|
||||||
direction(lineA, cur as vec2, last as vec2);
|
// @ts-ignore
|
||||||
|
direction(lineA, cur as vec3, last as vec3);
|
||||||
let segmentDistance = 0;
|
let segmentDistance = 0;
|
||||||
if (this.dash) {
|
if (this.dash) {
|
||||||
|
// @ts-ignore
|
||||||
segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
|
segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
|
||||||
this.totalDistance += segmentDistance;
|
this.totalDistance += segmentDistance;
|
||||||
}
|
}
|
||||||
|
@ -281,16 +295,22 @@ export default class ExtrudePolyline {
|
||||||
);
|
);
|
||||||
count += 2;
|
count += 2;
|
||||||
} else {
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
if (isPointEqual(cur as vec2, next as vec2)) {
|
if (isPointEqual(cur as vec2, next as vec2)) {
|
||||||
vec2.add(
|
vec2.add(
|
||||||
|
// @ts-ignore
|
||||||
next as vec2,
|
next as vec2,
|
||||||
|
// @ts-ignore
|
||||||
cur as vec2,
|
cur as vec2,
|
||||||
vec2.normalize(
|
vec2.normalize(
|
||||||
|
// @ts-ignore
|
||||||
next as vec2,
|
next as vec2,
|
||||||
|
// @ts-ignore
|
||||||
vec2.subtract(next as vec2, cur as vec2, last as vec2),
|
vec2.subtract(next as vec2, cur as vec2, last as vec2),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// @ts-ignore
|
||||||
direction(lineB, next as vec2, cur as vec2);
|
direction(lineB, next as vec2, cur as vec2);
|
||||||
// stores tangent & miter
|
// stores tangent & miter
|
||||||
|
|
||||||
|
@ -394,9 +414,11 @@ export default class ExtrudePolyline {
|
||||||
const joinBevel = this.join === 'bevel';
|
const joinBevel = this.join === 'bevel';
|
||||||
const flatCur = aProjectFlat([cur[0], cur[1]]) as [number, number];
|
const flatCur = aProjectFlat([cur[0], cur[1]]) as [number, number];
|
||||||
const flatLast = aProjectFlat([last[0], last[1]]) as [number, number];
|
const flatLast = aProjectFlat([last[0], last[1]]) as [number, number];
|
||||||
|
// @ts-ignore
|
||||||
direction(lineA, flatCur, flatLast);
|
direction(lineA, flatCur, flatLast);
|
||||||
let segmentDistance = 0;
|
let segmentDistance = 0;
|
||||||
if (this.dash) {
|
if (this.dash) {
|
||||||
|
// @ts-ignore
|
||||||
segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
|
segmentDistance = this.lineSegmentDistance(flatCur, flatLast);
|
||||||
this.totalDistance += segmentDistance;
|
this.totalDistance += segmentDistance;
|
||||||
}
|
}
|
||||||
|
@ -620,7 +642,7 @@ export default class ExtrudePolyline {
|
||||||
point[2] | 0,
|
point[2] | 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
private lineSegmentDistance(b1: vec2, a1: vec2) {
|
private lineSegmentDistance(b1: vec3, a1: vec3) {
|
||||||
const dx = a1[0] - b1[0];
|
const dx = a1[0] - b1[0];
|
||||||
const dy = a1[1] - b1[1];
|
const dy = a1[1] - b1[1];
|
||||||
return Math.sqrt(dx * dx + dy * dy);
|
return Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
// @ts-ignore
|
||||||
|
import { PointLayer, Scene, LineLayer, PolygonLayer } from '@antv/l7';
|
||||||
|
import { GaodeMap, GaodeMapV2, Mapbox } from '@antv/l7-maps';
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as turf from '@turf/turf';
|
||||||
|
|
||||||
|
const aspaceLnglat = [120.1019811630249, 30.264701434772807] as [
|
||||||
|
number,
|
||||||
|
number,
|
||||||
|
];
|
||||||
|
export default class BusLine extends React.Component {
|
||||||
|
// @ts-ignore
|
||||||
|
private scene: Scene;
|
||||||
|
|
||||||
|
public componentWillUnmount() {
|
||||||
|
this.scene.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async componentDidMount() {
|
||||||
|
const scene = new Scene({
|
||||||
|
id: 'map',
|
||||||
|
map: new Mapbox({
|
||||||
|
center: [103.83735604457024, 1.360253881403068],
|
||||||
|
pitch: 4.00000000000001,
|
||||||
|
zoom: 10.210275860702593,
|
||||||
|
rotation: 19.313180925794313,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
this.scene = scene;
|
||||||
|
|
||||||
|
scene.on('loaded', () => {
|
||||||
|
fetch(
|
||||||
|
'https://gw.alipayobjects.com/os/basement_prod/ee07641d-5490-4768-9826-25862e8019e1.json',
|
||||||
|
)
|
||||||
|
.then((res) => res.json())
|
||||||
|
.then((data) => {
|
||||||
|
const layer = new LineLayer({})
|
||||||
|
.source(data, {
|
||||||
|
parser: {
|
||||||
|
type: 'json',
|
||||||
|
coordinates: 'path',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.size('level', (level) => {
|
||||||
|
return [0.8, level * 1];
|
||||||
|
})
|
||||||
|
.style({
|
||||||
|
// vertexHeightScale: 0.01
|
||||||
|
})
|
||||||
|
.shape('line')
|
||||||
|
.active(true)
|
||||||
|
.color(
|
||||||
|
'level',
|
||||||
|
[
|
||||||
|
'#0A3663',
|
||||||
|
'#1558AC',
|
||||||
|
'#3771D9',
|
||||||
|
'#4D89E5',
|
||||||
|
'#64A5D3',
|
||||||
|
'#72BED6',
|
||||||
|
'#83CED6',
|
||||||
|
'#A6E1E0',
|
||||||
|
'#B8EFE2',
|
||||||
|
'#D7F9F0',
|
||||||
|
]
|
||||||
|
.reverse()
|
||||||
|
.slice(0, 8),
|
||||||
|
);
|
||||||
|
scene.addLayer(layer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public render() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
id="map"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -63,6 +63,7 @@ import Amap2demo_styleMap from "./components/amap2demo_styleMap"
|
||||||
import Amap2demo_textOffset from "./components/amap2demo_textOffset"
|
import Amap2demo_textOffset from "./components/amap2demo_textOffset"
|
||||||
|
|
||||||
import ShapeUpdate from './components/shapeUpdate'
|
import ShapeUpdate from './components/shapeUpdate'
|
||||||
|
import BusLine from './components/busline'
|
||||||
import AmapPlugin from './components/plugin'
|
import AmapPlugin from './components/plugin'
|
||||||
import PointUV from './components/pointUV'
|
import PointUV from './components/pointUV'
|
||||||
import DestroyClear from './components/destroyClear'
|
import DestroyClear from './components/destroyClear'
|
||||||
|
@ -146,3 +147,4 @@ storiesOf('地图方法', module)
|
||||||
.add('Slider', () => <Slider/>)
|
.add('Slider', () => <Slider/>)
|
||||||
.add('SimplePoint', () => <SimplePoint/>)
|
.add('SimplePoint', () => <SimplePoint/>)
|
||||||
.add('LineWall', () => <LineWall/>)
|
.add('LineWall', () => <LineWall/>)
|
||||||
|
.add('BusLine', () => <BusLine/>)
|
||||||
|
|
Loading…
Reference in New Issue