mirror of https://gitee.com/antv-l7/antv-l7
parent
1eebca1c4c
commit
33274bf610
|
@ -31,59 +31,47 @@
|
|||
var buildLayer =null;
|
||||
const scene = new L7.Scene({
|
||||
id: 'map',
|
||||
mapStyle: 'amap://styles/c9f1d10cae34f8ab05e425462c5a58d7', // 样式URL
|
||||
center: [120.102915,30.261396],
|
||||
mapStyle: 'normal', // 样式URL
|
||||
center: [120.1998700000, 30.2638300000],
|
||||
pitch: 0,
|
||||
zoom: 12,
|
||||
zoom: 14,
|
||||
minZoom: 5,
|
||||
maxZoom: 18
|
||||
});
|
||||
scene.on('loaded', () => {
|
||||
$.get('https://gw.alipayobjects.com/os/basement_prod/a0f3363f-4f95-4145-9161-cca6b9134277.json',(data)=>{
|
||||
let startTime = 3600 * 6;
|
||||
const interval = 3600;
|
||||
const mapData = {
|
||||
"type": "FeatureCollection",
|
||||
"features": []
|
||||
};
|
||||
mapData.features = data.features.filter((feature)=>{
|
||||
const time = feature.properties.time;
|
||||
const type = feature.properties.type
|
||||
return time >= startTime && time <= (startTime + interval)
|
||||
|
||||
})
|
||||
const linelayer = scene.LineLayer({
|
||||
zIndex: 2
|
||||
})
|
||||
.shape('line')
|
||||
.size([2,0])
|
||||
.source(mapData)
|
||||
.color('type',function(type){
|
||||
return type ==='pjc_end' ? '#2b83ba' :'#d7191c'
|
||||
})
|
||||
.animate({
|
||||
enable:true,
|
||||
interval:0.8,
|
||||
duration:2,
|
||||
trailLength:0.2,
|
||||
})
|
||||
.render();
|
||||
setInterval(()=>{
|
||||
startTime += interval
|
||||
document.getElementById('timepannel').innerHTML=`时间:${startTime / 3600}时`
|
||||
mapData.features = data.features.filter((feature)=>{
|
||||
const time = feature.properties.time;
|
||||
const type = feature.properties.type
|
||||
return time >= startTime && time <= (startTime + interval)
|
||||
})
|
||||
if(startTime == interval * 24) {
|
||||
startTime = 3600 * 6;
|
||||
}
|
||||
//if( mapData.features.length ==0) return;
|
||||
linelayer.setData(mapData);
|
||||
|
||||
},2000)
|
||||
});
|
||||
const layer = scene.LineLayer({
|
||||
zIndex: 3
|
||||
}).source([{
|
||||
'x': 120.1998700000,
|
||||
'y': 30.2638300000,
|
||||
'x1': 119.575328,
|
||||
'y1': 30.106775
|
||||
}],{
|
||||
parser: {
|
||||
type: 'json',
|
||||
x: 'x',
|
||||
y: 'y',
|
||||
x1: 'x1',
|
||||
y1: 'y1'
|
||||
}
|
||||
}).shape('greatCircle').size(2).color('rgb(13,64,140)').animate({
|
||||
enable: false,
|
||||
interval: 1,
|
||||
duration: 2,
|
||||
trailLength: 0.8
|
||||
}).style({
|
||||
opacity: 1
|
||||
}).render()
|
||||
console.log(layer);
|
||||
new L7.Marker({
|
||||
color: 'red'
|
||||
}).setLnglat([120.1998700000, 30.2638300000]).addTo(scene);
|
||||
scene.map.add(new AMap.Marker({
|
||||
position: new AMap.LngLat(120.1998700000, 30.2638300000),
|
||||
// icon: icon, // 添加 Icon 实例
|
||||
zoom: 13,
|
||||
//offset: new AMap.Pixel(-0.2 * this.rem, -0.4 * this.rem)
|
||||
}))
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<meta name="geometry" content="diagram">
|
||||
<link rel="stylesheet" href="./assets/common.css">
|
||||
<link rel="stylesheet" href="./assets/info.css">
|
||||
|
||||
<title>hexagon demo</title>
|
||||
<style>
|
||||
body {margin: 0;}
|
||||
#map { position:absolute; top:0; bottom:0; width:100%; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
|
||||
<script src="https://webapi.amap.com/maps?v=1.4.8&key=15cd8a57710d40c9b7c0e3cc120f1200&plugin=Map3D"></script>
|
||||
<script src="./assets/jquery-3.2.1.min.js"></script>
|
||||
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
|
||||
<script src="../build/L7.js"></script>
|
||||
<script>
|
||||
const colorObj ={
|
||||
blue: ["#E8FCFF", "#CFF6FF", "#98E3FA", "#65CEF7", "#3CB4F0", "#2894E0", "#1A76C7", "#105CB3", "#0D408C", "#002466"],
|
||||
red: ["#FFF4F2", "#FFDFDB", "#FAADAA", "#F77472", "#F04850", "#D63147", "#BD223E", "#A81642", "#820C37", "#5C0023"],
|
||||
orange:["#FFF7EB", "#FFECD4", "#FAD09D", "#F7B16A", "#F08D41", "#DB6C2C", "#C2491D", "#AD2B11", "#871D0C", "#610800"],
|
||||
green:["#FAFFF0", "#EBF7D2", "#C8E695", "#A5D660", "#7DC238", "#59A616", "#3F8C0B", "#237804", "#125200", "#082B00"],
|
||||
yellow:["#FFFFE8", "#FFFECC", "#FAF896", "#F7E463", "#F0CE3A", "#DBB125", "#C29117", "#AD7410", "#87500C", "#613000"],
|
||||
purple:["#FCF2FF", "#F5DEFF", "#DDB3F2", "#BE7BE3", "#9B4ECF", "#7737B3", "#5B2899", "#411C85", "#270F5E", "#100338"],
|
||||
}
|
||||
|
||||
const scene = new L7.Scene({
|
||||
id: 'map',
|
||||
mapStyle: 'blank', // 样式URL
|
||||
center: [70.838088,34.075889 ],
|
||||
pitch: 0,
|
||||
zoom: 3,
|
||||
|
||||
});
|
||||
window.scene = scene;
|
||||
scene.on('loaded', () => {
|
||||
Promise.all([
|
||||
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/world.geo.json').then(d => d.json()),
|
||||
fetch('https://gw.alipayobjects.com/os/basement_prod/4472780b-fea1-4fc2-9e4b-3ca716933dc7.json').then(d => d.text()),
|
||||
fetch('https://gw.alipayobjects.com/os/basement_prod/a5ac7bce-181b-40d1-8a16-271356264ad8.json').then(d => d.text())
|
||||
]).then(function onLoad ([world, dot, fiyline]) {
|
||||
const dotData = eval(dot);
|
||||
function bezier3(arr, t) {
|
||||
var ut = 1 - t
|
||||
return (arr[0] * ut + arr[1] * t) * ut + (arr[1] * ut + arr[2] * t) * t
|
||||
}
|
||||
const fiylineData = eval(fiyline).map(item=>{
|
||||
const latlngs = [];
|
||||
const latlng1 = item.from.split(',').map(e => {return e *1});
|
||||
const latlng2 = item.to.split(',').map(e => {return e *1});
|
||||
const offsetX = latlng2[1] - latlng1[1],
|
||||
offsetY = latlng2[0] - latlng1[0];
|
||||
const r = Math.sqrt( Math.pow(offsetX, 2) + Math.pow(offsetY, 2) ),
|
||||
theta = Math.atan2(offsetY, offsetX);
|
||||
|
||||
const thetaOffset = (3.14/10);
|
||||
|
||||
const r2 = (r/2)/(Math.cos(thetaOffset)),
|
||||
theta2 = theta + thetaOffset;
|
||||
|
||||
const midpointX = (r2 * Math.cos(theta2)) + latlng1[1],
|
||||
midpointY = (r2 * Math.sin(theta2)) + latlng1[0];
|
||||
|
||||
const midpointLatLng = [midpointY, midpointX];
|
||||
const x = [latlng1[0],midpointLatLng[0], latlng2[0]];
|
||||
const y = [latlng1[1],midpointLatLng[1], latlng2[1]];
|
||||
const coords = []
|
||||
for(let i = 0; i<=1;i+=0.02) {
|
||||
coords.push([bezier3(x,i),bezier3(y,i)])
|
||||
}
|
||||
coords.push(latlng2)
|
||||
return turf.lineString(coords)
|
||||
});
|
||||
console.log(fiylineData);
|
||||
const citylayer = scene.PolygonLayer()
|
||||
.source(world)
|
||||
.color('#98E3FA')
|
||||
.shape('fill')
|
||||
.active({
|
||||
fill:'#2894E0'
|
||||
})
|
||||
.style({
|
||||
opacity: 1
|
||||
})
|
||||
.render();
|
||||
|
||||
const citylayer2 = scene.PolygonLayer()
|
||||
.source(world)
|
||||
.shape('line')
|
||||
.color('#fff')
|
||||
.style({
|
||||
opacity: 1.0
|
||||
})
|
||||
.render();
|
||||
|
||||
const pointLayer = scene.PointLayer()
|
||||
.source(dotData,{
|
||||
parser:{
|
||||
type:'json',
|
||||
x:'lng',
|
||||
y:'lat'
|
||||
}
|
||||
})
|
||||
.shape('circle')
|
||||
.color('#1A76C7')
|
||||
.size(10)
|
||||
.style({
|
||||
opacity:0.5
|
||||
})
|
||||
.render();
|
||||
|
||||
const pointLayerText = scene.PointLayer()
|
||||
.source(dotData,{
|
||||
parser:{
|
||||
type:'json',
|
||||
x:'lng',
|
||||
y:'lat'
|
||||
}
|
||||
})
|
||||
.shape('area','text')
|
||||
.color('#fff')
|
||||
.style({
|
||||
stroke: '#3CB4F0',
|
||||
strokeWidth:2,
|
||||
textAnchor: 'top',
|
||||
textOffset:[0,30]
|
||||
})
|
||||
.size(15)
|
||||
.render();
|
||||
|
||||
const line= scene.LineLayer()
|
||||
.source(turf.featureCollection(fiylineData))
|
||||
.shape('line')
|
||||
.color('#3CB4F0')
|
||||
.size(2)
|
||||
.style({
|
||||
blending:'additive'
|
||||
})
|
||||
.animate({
|
||||
enable: true,
|
||||
interval: 0.2,
|
||||
duration: 2,
|
||||
trailLength: 0.4
|
||||
})
|
||||
.render();
|
||||
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -6,7 +6,7 @@ export default class Marker extends Base {
|
|||
constructor(cfg) {
|
||||
super({
|
||||
element: '', // DOM element
|
||||
anchor: 'center',
|
||||
anchor: 'bottom',
|
||||
offset: [ 0, 0 ],
|
||||
color: '#2f54eb',
|
||||
draggable: false,
|
||||
|
|
|
@ -163,6 +163,7 @@ export default class Scene extends Base {
|
|||
}
|
||||
layer.destroy();
|
||||
layer = null;
|
||||
this._engine.update();
|
||||
}
|
||||
startAnimate() {
|
||||
if (this.animateCount === 0) {
|
||||
|
@ -204,6 +205,9 @@ export default class Scene extends Base {
|
|||
removeControl(ctr) {
|
||||
this.get('controlController').removeControl(ctr);
|
||||
}
|
||||
render() {
|
||||
this._engine.update();
|
||||
}
|
||||
destroy() {
|
||||
super.destroy();
|
||||
this._layers.forEach(layer => {
|
||||
|
|
|
@ -2,7 +2,6 @@ import * as THREE from '../../core/three';
|
|||
import Material from './material';
|
||||
import { getModule, wrapUniforms } from '../../util/shaderModule';
|
||||
import merge from '@antv/util/lib/deep-mix';
|
||||
|
||||
export function LineMaterial(options) {
|
||||
const { vs, fs } = getModule('line');
|
||||
const material = new Material({
|
||||
|
@ -15,11 +14,12 @@ export function LineMaterial(options) {
|
|||
},
|
||||
vertexShader: vs,
|
||||
fragmentShader: fs,
|
||||
transparent: true
|
||||
// blending: THREE.AdditiveBlending
|
||||
transparent: true,
|
||||
blending: THREE[Material.blendingEnum[options.blending]]
|
||||
});
|
||||
return material;
|
||||
}
|
||||
// 弧线绘制 大圆航线 3D弧线
|
||||
export function ArcLineMaterial(options) {
|
||||
let moduleName = 'arcline';
|
||||
if (options.shapeType === 'greatCircle') {
|
||||
|
@ -29,7 +29,7 @@ export function ArcLineMaterial(options) {
|
|||
const material = new Material({
|
||||
uniforms: wrapUniforms(merge(uniforms, {
|
||||
u_opacity: options.u_opacity,
|
||||
segmentNumber: 29,
|
||||
segmentNumber: 30,
|
||||
u_time: 0,
|
||||
u_zoom: options.u_zoom,
|
||||
u_activeId: options.activeId,
|
||||
|
@ -38,8 +38,8 @@ export function ArcLineMaterial(options) {
|
|||
vertexShader: vs,
|
||||
fragmentShader: fs,
|
||||
transparent: true,
|
||||
blending: THREE.AdditiveBlending,
|
||||
side: THREE.DoubleSide
|
||||
side: THREE.DoubleSide,
|
||||
blending: THREE[Material.blendingEnum[options.blending]]
|
||||
});
|
||||
return material;
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ export function MeshLineMaterial(options, defines) {
|
|||
vertexShader: vs,
|
||||
fragmentShader: fs,
|
||||
transparent: true
|
||||
// blending: THREE.AdditiveBlending
|
||||
});
|
||||
return material;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
|
||||
import * as THREE from '../../core/three';
|
||||
const blendingEnum = {
|
||||
normal: 'NormalBlending',
|
||||
additive: 'AdditiveBlending',
|
||||
subtractive: 'SubtractiveBlending'
|
||||
};
|
||||
|
||||
|
||||
export default class Material extends THREE.ShaderMaterial {
|
||||
static blendingEnum = {
|
||||
normal: 'NormalBlending',
|
||||
additive: 'AdditiveBlending',
|
||||
subtractive: 'SubtractiveBlending'
|
||||
}
|
||||
setUniformsValue(name, value) {
|
||||
if (!this.uniforms[name]) { return; }
|
||||
this.uniforms[name].value = value;
|
||||
|
@ -32,6 +34,6 @@ export default class Material extends THREE.ShaderMaterial {
|
|||
}
|
||||
}
|
||||
setBending(type) {
|
||||
this.blending = THREE[blendingEnum[type]] || THREE.NormalBlending;
|
||||
this.blending = THREE[this.blendingEnum[type]] || THREE.NormalBlending;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ export default class PointMaterial extends Material {
|
|||
this.vertexShader = vs;
|
||||
this.fragmentShader = fs;
|
||||
this.transparent = true;
|
||||
|
||||
if (!this.uniforms.shape) { this.blending = THREE.AdditiveBlending; }
|
||||
if (this.uniforms.u_texture) {
|
||||
this.defines.TEXCOORD_0 = true;
|
||||
|
|
|
@ -19,7 +19,7 @@ float maps (float value, float start1, float stop1, float start2, float stop2) {
|
|||
}
|
||||
|
||||
float getSegmentRatio(float index) {
|
||||
return smoothstep(0.0, 1.0, index / (segmentNumber - 1.0));
|
||||
return smoothstep(0.0, 1.0, index / (segmentNumber - 1.));
|
||||
}
|
||||
|
||||
float paraboloid(vec2 source, vec2 target, float ratio) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import * as THREE from '../../../core/three';
|
||||
import { ArcLineMaterial } from '../../../geom/material/lineMaterial';
|
||||
import { getBuffer } from '../../../geom/buffer/';
|
||||
|
||||
export default function DrawArcLine(layerData, layer, buffer) {
|
||||
const style = layer.get('styleOptions');
|
||||
const activeOption = layer.get('activedOptions');
|
||||
|
@ -47,7 +48,6 @@ export default function DrawArcLine(layerData, layer, buffer) {
|
|||
u_trailLength: trailLength
|
||||
});
|
||||
lineMaterial.setDefinesvalue('ANIMATE', true);
|
||||
// lineMaterial.setDefinesvalue('DASHLINE', true);
|
||||
}
|
||||
const arcMesh = new THREE.Mesh(geometry, lineMaterial);
|
||||
arcMesh.frustumCulled = false;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import * as THREE from '../../../core/three';
|
||||
import TextMaterial from '../../../geom/material/textMaterial';
|
||||
import TextBuffer from '../../../geom/buffer/point/text';
|
||||
import ColorUtil from '../../../attr/color-util';
|
||||
import CollisionIndex from '../../../util/collision-index';
|
||||
const defaultTextStyle = {
|
||||
fontWeight: 500,
|
||||
|
@ -21,7 +20,6 @@ export default function DrawText(layerData, layer) {
|
|||
layer.set('styleOptions', style);
|
||||
const activeOption = layer.get('activedOptions');
|
||||
const { strokeWidth, stroke, opacity } = style;
|
||||
|
||||
const { width, height } = layer.scene.getSize();
|
||||
const { geometry, texture, fontAtlas } = _updateGeometry(layerData, layer);
|
||||
layer.scene.on('camerachange', () => {
|
||||
|
@ -34,7 +32,7 @@ export default function DrawText(layerData, layer) {
|
|||
const material = new TextMaterial({
|
||||
name: layer.layerId,
|
||||
u_sdf_map: texture,
|
||||
u_stroke: ColorUtil.toRGB(stroke).map(e => e / 255),
|
||||
u_stroke: stroke,
|
||||
u_strokeWidth: strokeWidth,
|
||||
u_halo_blur: 0.5,
|
||||
u_opacity: opacity,
|
||||
|
@ -43,7 +41,6 @@ export default function DrawText(layerData, layer) {
|
|||
u_activeColor: activeOption.fill
|
||||
});
|
||||
const mesh = new THREE.Mesh(geometry, material);
|
||||
|
||||
// 更新 viewport
|
||||
window.addEventListener('resize', () => {
|
||||
const { width, height } = layer.scene.getSize();
|
||||
|
|
Loading…
Reference in New Issue