Skip to content

Commit

Permalink
feat(layer): add tile
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed Apr 2, 2019
1 parent ee284d8 commit 181d7bc
Show file tree
Hide file tree
Showing 16 changed files with 395 additions and 54 deletions.
17 changes: 10 additions & 7 deletions demos/01_point_circle.html
Expand Up @@ -24,7 +24,7 @@
<script src="../build/L7.js"></script>
<script>
const colorObj ={
blue["#E8FCFF", "#CFF6FF", "#A1E9ff", "#65CEF7", "#3CB1F0", "#2894E0", "#1772c2", "#105CB3", "#0D408C", "#002466"].reverse(),
blue["#E8FCFF", "#CFF6FF", "#A1E9ff", "#65CEF7", "#3CB1F0", "#2894E0", "#1772c2", "#105CB3", "#0D408C", "#002466"],
red["#FFF4F2", "#FFDFDB", "#FAADAA", "#F77472", "#F04850", "#D63147", "#BD223E", "#A81642", "#820C37", "#5C0023"].reverse(),
orange:["#FFF7EB", "#FFECD4", "#FAD09D", "#F7B16A", "#F08D41", "#DB6C2C", "#C2491D", "#AD2B11", "#871D0C", "#610800"].reverse(),
green:["#FAFFF0", "#EBF7D2", "#C8E695", "#A5D660", "#7DC238", "#59A616", "#3F8C0B", "#237804", "#125200", "#082B00"].reverse(),
Expand All @@ -35,7 +35,7 @@

const scene = new L7.Scene({
id: 'map',
mapStyle: 'light', // 样式URL
mapStyle: 'dark', // 样式URL
center: [ 120.19382669582967, 30.258134 ],
pitch: 0,
zoom: 12,
Expand All @@ -52,14 +52,14 @@
isCluster:true
})
.shape('hexagon')
.size('point_count', [ 2, 30]) // default 1
.size('point_count', [ 5, 40]) // default 1
//.size('value', [ 10, 300]) // default 1
.active(true)
.color('#2894E0')
.color('point_count',colorObj.blue)
.style({
stroke: 'rgb(255,255,255)',
strokeWidth: 1,
opacity: 0.8
opacity: 1
})
.render();
window.circleLayer = circleLayer;
Expand All @@ -69,8 +69,11 @@
.source(circleLayer.layerSource)
.shape('point_count', 'text')
.active(true)
.size('point_count', [ 0, 16]) // default 1
.color('#f00')
.filter('point_count',(p)=>{
return p > 50
})
.size('point_count', [ 5, 20]) // default 1
.color('#fff')
.style({
stroke: '#999',
strokeWidth: 0,
Expand Down
70 changes: 50 additions & 20 deletions demos/line.html
Expand Up @@ -9,51 +9,81 @@
<title>city demo</title>
<style>
#map { position:absolute; top:0; bottom:0; width:100%; }
#timepannel {
background: white;
z-index: 10;
position: absolute;
right:50px;
padding: 10px;
}
</style>
</head>

<body>
<div id = 'gui' style="position:absolute;top:0px;right:0px;z-index:2;"></div>
<div id="map"></div>
<script src="https://webapi.amap.com/maps?v=1.4.8&key=15cd8a57710d40c9b7c0e3cc120f1200&plugin=Map3D"></script>
<div id ='timepannel'>时间: 6时</div>
<div id="map">

</div>
<script src="https://webapi.amap.com/maps?v=1.4.8&key=f28fca5384129d180ad82915156a9baf&plugin=Map3D"></script>
<script src="./assets/jquery-3.2.1.min.js"></script>
<script src="./assets/dat.gui.min.js"></script>
<script src="../build/L7.js"></script>
<script>
var buildLayer =null;
const scene = new L7.Scene({
id: 'map',
mapStyle: 'dark', // 样式URL
center: [116.428925,39.903969 ],
mapStyle: 'amap://styles/c9f1d10cae34f8ab05e425462c5a58d7', // 样式URL
center: [120.102915,30.261396],
pitch: 0,
zoom: 15,
zoom: 12,
minZoom: 5,
maxZoom: 18
});
scene.on('loaded', () => {
const line = {"type":"FeatureCollection",
"features":[{"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[116.379883,39.865601,0],[116.379997,39.865498,15],[116.380104,39.865364,47],[116.380203,39.865246,95],[116.380348,39.865032,170],[116.380478,39.864765,277],[116.380478,39.864765,384],[116.380745,39.864727,514],[116.381218,39.864799,685],[116.381439,39.864841,875],[116.381798,39.864906,1097],[116.382034,39.864979,1341],[116.382309,39.865093,1612],[116.383095,39.865559,1968],[116.383575,39.865742,2370],[116.383896,39.865822,2801],[116.384232,39.865871,3261],[116.384537,39.865883,3747],[116.384903,39.865868,4264],[116.385132,39.865841,4801],[116.385422,39.865761,5364],[116.385582,39.865696,5942],[116.385582,39.865696,6520],[116.385788,39.865623,7117],[116.386055,39.865517,7740],[116.38694,39.86525,8444],[116.387482,39.865128,9196],[116.387672,39.865204,9966],[116.387741,39.865391,10758],[116.387772,39.865475,11560],[116.387901,39.866009,12422],[116.387955,39.866352,13322],[116.38797,39.866581,14248],[116.38797,39.867085,15230],[116.38797,39.867371,16244],[116.387947,39.867935,17321],[116.387939,39.868587,18471],[116.387932,39.869381,19709],[116.387932,39.870155,21033],[116.387901,39.870506,22396],[116.387901,39.870506,23759],[116.388077,39.870682,25147],[116.388222,39.870762,26550],[116.388275,39.870773,27958],[116.388542,39.87077,29389],[116.389153,39.870762,30872],[116.390015,39.870762,32429],[116.390114,39.870777,33995],[116.39019,39.870804,35568],[116.390259,39.870827,37147],[116.390755,39.87112,38779],[116.390961,39.871201,40431],[116.392235,39.871254,42192],[116.392296,39.871258,43958],[116.394577,39.871346,45919],[116.395042,39.871368,47920],[116.395279,39.871368,49941],[116.396156,39.871372,52037],[116.396156,39.871372,54133],[116.397476,39.871574,56344],[116.398438,39.871616,58637],[116.399734,39.871685,61041],[116.400322,39.871693,63495],[116.401268,39.871746,66030],[116.402931,39.871826,68707],[116.403282,39.871861,71414],[116.404373,39.871948,74215],[116.405106,39.87196,77079],[116.406166,39.871979,80034],[116.40712,39.872005,83071],[116.40934,39.872074,86298],[116.411125,39.872124,89678],[116.411407,39.872135,93082],[116.413887,39.872189,96698],[116.414276,39.8722,100347],[116.414642,39.872192,104027],[116.414818,39.872177,107722],[116.415344,39.872074,111463],[116.415779,39.871899,115246],[116.41687,39.871395,119138],[116.417328,39.871201,123075],[116.417603,39.871124,127037],[116.417801,39.87109,131016],[116.418159,39.871048,135026],[116.418488,39.87104,139064],[116.419136,39.871075,143157],[116.419708,39.871113,147299],[116.419891,39.87112,151457],[116.420082,39.87114,155631],[116.420425,39.871159,159834],[116.420761,39.871178,164066],[116.420853,39.871185,168306],[116.420944,39.871193,172554],[116.421066,39.871201,176812],[116.421219,39.871201,181083],[116.421257,39.871208,185357],[116.421883,39.871246,189685],[116.421883,39.871246,194013],[116.42202,39.871201,198354],[116.422081,39.87117,202701],[116.422127,39.871124,207054],[116.422195,39.871033,211419],[116.422226,39.870586,215834],[116.422211,39.870533,220255],[116.422188,39.870476,224683],[116.422142,39.87043,229117],[116.422081,39.87038,233559],[116.421997,39.87035,238009],[116.421867,39.87035,242470],[116.421783,39.870361,246938],[116.421715,39.870388,251413],[116.42157,39.870453,255902],[116.421501,39.870502,260399],[116.421501,39.870502,264896],[116.421486,39.870792,269425],[116.421478,39.870861,273962],[116.421455,39.871437,278563],[116.421425,39.872169,283246],[116.421379,39.873272,288052],[116.421326,39.874275,292970],[116.42131,39.875,297969],[116.421295,39.87532,303004],[116.421272,39.875843,308097],[116.421219,39.876854,313303],[116.42112,39.878708,318716],[116.42112,39.878853,324145],[116.421051,39.880367,329743],[116.421028,39.880692,335377],[116.421021,39.880863,341030],[116.421013,39.880928,346690],[116.421005,39.881634,352429],[116.420952,39.882782,358296],[116.420944,39.88303,364191],[116.420914,39.883743,370165],[116.420906,39.883854,376151],[116.420898,39.883934,382146],[116.42083,39.884594,388215],[116.420784,39.884773,394304],[116.420723,39.884964,400415],[116.420486,39.885441,406583],[116.420471,39.885475,412755],[116.419678,39.88699,419109],[116.419647,39.887062,425471],[116.419304,39.887848,431925],[116.41925,39.888035,438400],[116.419197,39.888264,444901],[116.419167,39.888504,451429],[116.419144,39.888882,457999],[116.419128,39.889191,464603],[116.419075,39.890392,471341],[116.419075,39.890545,478096],[116.419052,39.890923,484893],[116.419029,39.891357,491738],[116.419014,39.89204,498659],[116.419029,39.89259,505641],[116.419037,39.892956,512664],[116.419029,39.893246,519719],[116.418999,39.893608,526814],[116.418961,39.893852,533936],[116.418915,39.894402,541119],[116.418915,39.894592,548323],[116.418846,39.895786,555660],[116.4188,39.897121,563146],[116.4188,39.897209,570642],[116.418709,39.899338,578375],[116.418663,39.900223,586207],[116.418655,39.900414,594060],[116.418571,39.901062,601985],[116.418556,39.901173,609922],[116.418533,39.901489,617894],[116.418526,39.90163,625882],[116.418488,39.902054,633917],[116.418465,39.902344,641984],[116.418442,39.902649,650085],[116.418434,39.902706,658192],[116.418434,39.903198,666354],[116.418419,39.903553,674556],[116.418365,39.904186,682829],[116.418335,39.904579,691146],[116.418327,39.904858,699494],[116.41832,39.905056,707864],[116.418312,39.905304,716262],[116.418266,39.906265,724767],[116.418121,39.908184,733486],[116.418121,39.908184,742205],[116.420853,39.908241,751157],[116.421234,39.908241,760142],[116.422356,39.90826,769223],[116.422928,39.908272,778353],[116.42334,39.908279,787518],[116.423454,39.908283,796693],[116.424446,39.908283,805953],[116.424522,39.908283,815219],[116.425194,39.908302,824542],[116.426964,39.908337,834016],[116.426964,39.908337,843490],[116.426987,39.908001,853001],[116.42701,39.907352,862584],[116.427032,39.906639,872246],[116.427048,39.906246,881952],[116.427055,39.905941,891692],[116.427063,39.90509,901527],[116.427238,39.904968,911382],[116.42746,39.904915,921257],[116.428894,39.904907,931254],[116.428894,39.904907,941251],[116.428909,39.904835,951256],[116.428925,39.904427,961306],[116.428963,39.904129,971389],[116.428963,39.904129,981472],[116.428909,39.90406,991564],[116.428925,39.903969,1001666],[116.42894,39.90329,1011844],[116.42894,39.90329,1022022],[116.427841,39.903244,1032294],[116.427299,39.903233,1042612]]}}]};

$.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(line)
.color('#ff893a')
.source(mapData)
.color('type',function(type){
return type ==='pjc_end' ? '#2b83ba' :'#d7191c'
})
.animate({
enable:true,
interval:1,
interval:0.8,
duration:2,
trailLength:0.1,
repeat:1000,
trailLength:0.2,
})
.render();
linelayer.on('animateEnd',()=>{
scene.removeLayer(linelayer);
//linelayer.hide();
})

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)
});
})
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@antv/l7",
"version": "1.1.7",
"version": "1.1.8",
"description": "Large-scale WebGL-powered Geospatial Data Visualization",
"main": "build/l7.js",
"browser": "build/l7.js",
Expand Down
4 changes: 2 additions & 2 deletions src/core/layer.js
Expand Up @@ -557,7 +557,6 @@ export default class Layer extends Base {
let { featureId, point2d, type } = e;
if (featureId < 0 && this._activeIds !== null) {
type = 'mouseleave';
// featureId = this._activeIds;
}
this._activeIds = featureId;
const feature = this.layerSource.getSelectFeature(featureId);
Expand All @@ -579,7 +578,7 @@ export default class Layer extends Base {
}
/**
* 用于过滤数据
* @param {*} object 需要过滤的mesh
* @param {*} object 更新颜色和数据过滤
*/
_updateFilter(object) {
this._updateMaping();
Expand Down Expand Up @@ -629,6 +628,7 @@ export default class Layer extends Base {
this._object3D.visible = true;
}
}

// 重新构建mesh
redraw() {
this._object3D.children.forEach(child => {
Expand Down
45 changes: 31 additions & 14 deletions src/geom/base.js
@@ -1,21 +1,38 @@
import Base from '../core/base';
export class GeomBase extends Base {
geometryBuffer() {

}
geometry() {
}

material() {

}

drawMesh() {
export const GeomBase = {
color: 'updateDraw',
size: 'repaint',
filter: 'updateDraw',
layer: '',
pickable: true,
setLayer(layer) {
this.layer = layer;
this.style = layer.get('styleOption');
},
getShape(type) {
return type;
},
draw() {
const shape = this.getShape();
this.Mesh = shape.Mesh();
},
// 更新geometry buffer;
updateDraw() {

},
repaint() {

}
};
export const shapeBae = {
geometryBuffer() {
},

geometry() {},

}
material() {},

mesh() {

export default GeomBase;
}
};
3 changes: 2 additions & 1 deletion src/geom/material/lineMaterial.js
Expand Up @@ -55,7 +55,8 @@ export function MeshLineMaterial(options) {
},
vertexShader: vs,
fragmentShader: fs,
transparent: true
transparent: true,
blending: THREE.AdditiveBlending
});
return material;
}
Expand Down
3 changes: 2 additions & 1 deletion src/geom/shader/line_vert.glsl
Expand Up @@ -16,7 +16,8 @@ void main() {
}
#ifdef ANIMATE
vTime = 1.0- (mod(u_time*50.,3600.)- position.z) / 100.;
// vTime = 1.0- (28800. + mod(u_time* 10.,28800.)- position.z / 1000.) / 100.;
#endif
gl_Position = matModelViewProjection * vec4(position.xy,0., 1.0);
gl_Position = matModelViewProjection * vec4(position.xy, 0., 1.0);
worldId = id_toPickColor(pickingId);
}
5 changes: 3 additions & 2 deletions src/geom/shader/meshline_vert.glsl
Expand Up @@ -20,7 +20,7 @@ uniform float u_trailLength;

void main() {
mat4 matModelViewProjection = projectionMatrix * modelViewMatrix;
vec3 pointPos = position.xyz + vec3(normal * a_size * pow(2.0,20.0-u_zoom) / 2.0 * a_miter);
vec3 pointPos = vec3(position.xy,0.) + vec3(normal * a_size * pow(2.0,20.0-u_zoom) / 2.0 * a_miter);
v_color = a_color;
if(pickingId == u_activeId) {
v_color = u_activeColor;
Expand All @@ -30,8 +30,9 @@ void main() {
float alpa =1.0 - fract( mod(1.0- a_distance,u_interval)* (1.0/u_interval) + u_time / u_duration);
alpa = (alpa + u_trailLength -1.0) / u_trailLength;
vTime = clamp(alpa,0.,1.);
// vTime = (28800. + mod(u_time* 1000.,28800.)- position.z) / 100.;
#endif
worldId = id_toPickColor(pickingId);
gl_Position = matModelViewProjection * vec4(pointPos, 1.0);
gl_Position = matModelViewProjection * vec4(pointPos.xy, 0., 1.0);

}
2 changes: 1 addition & 1 deletion src/geom/shape/line.js
Expand Up @@ -94,7 +94,7 @@ export function Line(path, props, positionsIndex) {
indexArray[c++] = i + 2;
indexArray[c++] = i + 3;
}
point[2] = size[1];
// point[2] = size[1];
positions.push(...point);
positions.push(...point);

Expand Down
4 changes: 2 additions & 2 deletions src/layer/pointLayer.js
Expand Up @@ -135,9 +135,9 @@ export default class PointLayer extends Layer {
const preBox = cfg.bbox;
const preZoom = cfg.zoom;
if (!(preBox && preBox[0] < bbox[0] && preBox[1] < bbox[1] && preBox[2] > bbox[2] && preBox[3] < bbox[3] && // 当前范围在范围内
(Math.abs(zoom - preZoom)) < 1)) {
(Math.abs(zoom - preZoom)) < 0.5)) {
const newbbox = [ SW.lng - step, SW.lat - step, NE.lng + step, NE.lat + step ];
this.layerSource.updateCusterData(Math.floor(zoom), newbbox);
this.layerSource.updateCusterData(Math.floor(zoom - 1), newbbox);
this.repaint();
}
}
Expand Down

0 comments on commit 181d7bc

Please sign in to comment.