feat(tile): add tile

This commit is contained in:
thinkinggis 2019-04-17 15:41:26 +08:00
parent 71d810a20a
commit 6dd6c5dd01
18 changed files with 183 additions and 197 deletions

View File

@ -59,11 +59,11 @@ scene.on('loaded', () => {
.source(data,{ .source(data,{
isCluster:true isCluster:true
}) })
.shape('hexagon') .shape('circle')
.size('point_count', [ 5, 40]) // default 1 .size('point_count', [ 5, 40]) // default 1
//.size('value', [ 10, 300]) // default 1 //.size('value', [ 10, 300]) // default 1
.active(true) .active(true)
.color('point_count',colorObj.blue) .color('point_count',["#002466","#105CB3","#2894E0","#CFF6FF","#FFF5B8","#FFAB5C","#F27049","#730D1C"])
.style({ .style({
stroke: 'rgb(255,255,255)', stroke: 'rgb(255,255,255)',
strokeWidth: 1, strokeWidth: 1,

View File

@ -96,6 +96,7 @@
}, },
"dependencies": { "dependencies": {
"@antv/g": "^3.1.3", "@antv/g": "^3.1.3",
"@antv/geo-coord": "^1.0.8",
"@antv/util": "~2.0.1", "@antv/util": "~2.0.1",
"@mapbox/tiny-sdf": "^1.1.0", "@mapbox/tiny-sdf": "^1.1.0",
"@turf/bbox": "^6.0.1", "@turf/bbox": "^6.0.1",

View File

@ -87,21 +87,11 @@ class Picking {
id = -999; id = -999;
// return; // return;
} }
this._raycaster.setFromCamera(normalisedPoint, this._camera);
const intersects = this._raycaster.intersectObjects(this._pickingScene.children, true);
const _point2d = { x: point.x, y: point.y }; const _point2d = { x: point.x, y: point.y };
let _point3d;
if (intersects.length > 0) {
_point3d = intersects[0].point;
}
const item = { const item = {
layerId, layerId,
featureId: id, featureId: id,
point2d: _point2d, point2d: _point2d
point3d: _point3d,
intersects
}; };
return item; return item;

View File

@ -33,7 +33,7 @@ export default class Source extends Base {
// 数据转换 统计,聚合,分类 // 数据转换 统计,聚合,分类
this._executeTrans(); this._executeTrans();
// 坐标转换 // 坐标转换
this._projectCoords(); // this._projectCoords();
} }
setData(data, cfg = {}) { setData(data, cfg = {}) {
Object.assign(this._attrs, cfg); Object.assign(this._attrs, cfg);

0
src/geo/point.js Normal file
View File

View File

@ -23,7 +23,7 @@ export default class ImageBuffer extends BufferBase {
const uv = [ 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 ]; const uv = [ 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0 ];
const texture = new THREE.Texture(image); const texture = new THREE.Texture(image);
texture.magFilter = THREE.LinearFilter; texture.magFilter = THREE.LinearFilter;
texture.minFilter = THREE.LinearFilter; texture.minFilter = THREE.LinearMipMapLinearFilter;
texture.needsUpdate = true; texture.needsUpdate = true;
const attributes = { const attributes = {
vertices: new Float32Array(positions), vertices: new Float32Array(positions),

View File

@ -19,18 +19,18 @@ export default function extrudePolygon(points, extrude) {
const flattengeo = earcut.flatten(points); const flattengeo = earcut.flatten(points);
const positions = []; const positions = [];
let cells = []; let cells = [];
const { dimensions } = flattengeo;
const triangles = earcut(flattengeo.vertices, flattengeo.holes, flattengeo.dimensions); const triangles = earcut(flattengeo.vertices, flattengeo.holes, flattengeo.dimensions);
cells = triangles; cells = triangles;
const pointCount = flattengeo.vertices.length / 3; const pointCount = flattengeo.vertices.length / dimensions;
const { vertices } = flattengeo; const { vertices } = flattengeo;
extrude ? full() : flat(); extrude ? full() : flat();
function flat() { function flat() {
for (let i = 0; i < pointCount; i++) { for (let i = 0; i < pointCount; i++) {
positions.push([ vertices[ i * 3 ], vertices[i * 3 + 1 ], 0 ]); positions.push([ vertices[ i * dimensions ], vertices[i * dimensions + 1 ], 0 ]);
} }
} }
function full() { function full() {
@ -41,10 +41,10 @@ export default function extrudePolygon(points, extrude) {
// 顶部坐标 // 顶部坐标
for (let i = 0; i < pointCount; i++) { for (let i = 0; i < pointCount; i++) {
positions.push([ vertices[ i * 3 ], vertices[i * 3 + 1 ], 1 ]); positions.push([ vertices[ i * dimensions ], vertices[i * dimensions + 1 ], 1 ]);
} }
for (let i = 0; i < pointCount; i++) { for (let i = 0; i < pointCount; i++) {
positions.push([ vertices[ i * 3 ], vertices[i * 3 + 1 ], 0 ]); positions.push([ vertices[ i * dimensions ], vertices[i * dimensions + 1 ], 0 ]);
} }
for (let i = 0; i < n; i++) { for (let i = 0; i < n; i++) {
if (i === (n - 1)) { if (i === (n - 1)) {

View File

@ -41,6 +41,10 @@ import image_frag from '../shader/image_frag.glsl';
import raster_vert from '../shader/raster_vert.glsl'; import raster_vert from '../shader/raster_vert.glsl';
import raster_frag from '../shader/raster_frag.glsl'; import raster_frag from '../shader/raster_frag.glsl';
// tile
import tile_polygon_vert from '../shader/tile/polygon_vert.glsl';
import tile_polygon_frag from '../shader/tile/polygon_frag.glsl';
import common from './common.glsl'; import common from './common.glsl';
import { registerModule } from '../../util/shaderModule'; import { registerModule } from '../../util/shaderModule';
import pick_color from './shaderChunks/pick_color.glsl'; import pick_color from './shaderChunks/pick_color.glsl';
@ -60,5 +64,6 @@ export function compileBuiltinModules() {
registerModule('text', { vs: text_vert, fs: text_frag }); registerModule('text', { vs: text_vert, fs: text_frag });
registerModule('image', { vs: image_vert, fs: image_frag }); registerModule('image', { vs: image_vert, fs: image_frag });
registerModule('raster', { vs: raster_vert, fs: raster_frag }); registerModule('raster', { vs: raster_vert, fs: raster_frag });
registerModule('tilepolygon', { vs: tile_polygon_vert, fs: tile_polygon_frag });
} }

View File

@ -41,7 +41,12 @@ float sdRect(vec2 p, vec2 sz) {
float inside = min(max(d.x, d.y), 0.); float inside = min(max(d.x, d.y), 0.);
return outside + inside; return outside + inside;
} }
float circle(in vec2 _st, in float _radius){
vec2 dist = _st-vec2(0.5);
return 1.-smoothstep(_radius-(_radius*0.01),
_radius+(_radius*0.01),
dot(dist,dist)*4.0);
}
void main() { void main() {
if(v_color.w == 0.0) { if(v_color.w == 0.0) {
@ -106,6 +111,12 @@ void main() {
gl_FragColor = vec4(foggedColor,1.0); gl_FragColor = vec4(foggedColor,1.0);
} }
#else #else
// #ifdef SHAPE
// vec2 st = gl_FragCoord.xy / v_size ;
// vec3 color = vec3(circle(st,0.5));
// gl_FragColor = vec4(color, 1.0 );
// return;
// #endif
gl_FragColor = vec4(v_color.xyz , v_color.w); gl_FragColor = vec4(v_color.xyz , v_color.w);
#endif #endif

View File

@ -30,6 +30,7 @@ void main() {
if(pickingId == u_activeId) { if(pickingId == u_activeId) {
v_color = u_activeColor; v_color = u_activeColor;
} }
v_size = a_size.x * scale;
gl_Position = matModelViewProjection * vec4(newposition, 1.0); gl_Position = matModelViewProjection * vec4(newposition, 1.0);
return; return;
} }
@ -49,7 +50,7 @@ void main() {
float lightWeight = ambientRatio + diffuseRatio * lambert + specularRatio * specular; float lightWeight = ambientRatio + diffuseRatio * lambert + specularRatio * specular;
v_texCoord = faceUv; v_texCoord = faceUv;
v_lightWeight = lightWeight; v_lightWeight = lightWeight;
// v_size = a_size;
v_color =vec4(a_color.rgb*lightWeight, a_color.w); v_color =vec4(a_color.rgb*lightWeight, a_color.w);
if(pickingId == u_activeId) { if(pickingId == u_activeId) {
v_color = u_activeColor; v_color = u_activeColor;

View File

@ -16,7 +16,7 @@ function triangle() {
return polygonPath(3); return polygonPath(3);
} }
function hexagon() { function hexagon() {
return polygonPath(6); return polygonPath(6, 1);
} }
export { export {
circle, circle,
@ -29,11 +29,11 @@ export {
square as squareColumn square as squareColumn
}; };
export function polygonPath(pointCount) { export function polygonPath(pointCount, start = 0) {
const step = Math.PI * 2 / pointCount; const step = Math.PI * 2 / pointCount;
const line = []; const line = [];
for (let i = 0; i < pointCount; i++) { for (let i = 0; i < pointCount; i++) {
line.push(step * i - Math.PI / 12); line.push(step * i - start * Math.PI / 12);
} }
const path = line.map(t => { const path = line.map(t => {
const x = Math.sin(t + Math.PI / 4), const x = Math.sin(t + Math.PI / 4),

View File

@ -0,0 +1,13 @@
import * as THREE from '../../../core/three';
import ImageMaterial from '../../../geom/material/imageMaterial';
export default function DrawImage(attributes, style) {
this.geometry = new THREE.BufferGeometry();
this.geometry.addAttribute('position', new THREE.Float32BufferAttribute(attributes.vertices, 3));
this.geometry.addAttribute('uv', new THREE.Float32BufferAttribute(attributes.uvs, 2));
const { opacity } = style;
const material = new ImageMaterial({
u_texture: attributes.texture,
u_opacity: opacity
});
return new THREE.Mesh(this.geometry, material);
}

View File

@ -1,5 +1,7 @@
import * as THREE from '../../../core/three'; import * as THREE from '../../../core/three';
import PolygonMaterial from '../../../geom/material/polygonMaterial'; // import PolygonMaterial from '../../../geom/material/polygonMaterial';
import TileMaterial from '../../../geom/material/tile/polygon';
export default function DrawPolygonFill(attributes, style) { export default function DrawPolygonFill(attributes, style) {
const { opacity, activeColor } = style; const { opacity, activeColor } = style;
const geometry = new THREE.BufferGeometry(); const geometry = new THREE.BufferGeometry();
@ -7,7 +9,13 @@ export default function DrawPolygonFill(attributes, style) {
geometry.addAttribute('a_color', new THREE.Float32BufferAttribute(attributes.colors, 4)); geometry.addAttribute('a_color', new THREE.Float32BufferAttribute(attributes.colors, 4));
geometry.addAttribute('pickingId', new THREE.Float32BufferAttribute(attributes.pickingIds, 1)); geometry.addAttribute('pickingId', new THREE.Float32BufferAttribute(attributes.pickingIds, 1));
geometry.addAttribute('normal', new THREE.Float32BufferAttribute(attributes.normals, 3)); geometry.addAttribute('normal', new THREE.Float32BufferAttribute(attributes.normals, 3));
const material = new PolygonMaterial({ // const material = new PolygonMaterial({
// u_opacity: opacity,
// u_activeColor: activeColor
// }, {
// SHAPE: false
// });
const material = new TileMaterial({
u_opacity: opacity, u_opacity: opacity,
u_activeColor: activeColor u_activeColor: activeColor
}, { }, {

View File

@ -1,137 +1,83 @@
// import * as THREE from '../../core/three';
// import Tile from './tile';
// export default class ImageTile extends Tile {
// constructor(layer, z, x, y) {
// } import Tile from './tile';
// requestTileAsync() { import ImageBuffer from '../../geom/buffer/image';
// // Making this asynchronous really speeds up the LOD framerate import DrawImage from '../render/image/drawImage';
// setTimeout(() => { export default class ImageTile extends Tile {
// if (!this._mesh) { requestTileAsync() {
// this._mesh = this._createMesh(); // Making this asynchronous really speeds up the LOD framerate
// this._requestTile(); setTimeout(() => {
// } if (!this._mesh) {
// }, 0); this._mesh = this._createMesh();
// } this._requestTile();
// _requestTile() { }
// const urlParams = { }, 0);
// x: this._tile[0], }
// y: this._tile[1], _requestTile() {
// z: this._tile[2] const urlParams = {
// }; x: this._tile[0],
y: this._tile[1],
z: this._tile[2]
};
// const url = this._getTileURL(urlParams); const url = this._getTileURL(urlParams);
// const image = document.createElement('img'); const image = document.createElement('img');
// image.addEventListener('load', event => { image.addEventListener('load', () => {
// const texture = new THREE.Texture();
// texture.image = image; this._createMesh(image);
// texture.needsUpdate = true; this._ready = true;
}, false);
// // Silky smooth images when tilted // image.addEventListener('progress', event => {}, false);
// texture.magFilter = THREE.LinearFilter; // image.addEventListener('error', event => {}, false);
// texture.minFilter = THREE.LinearMipMapLinearFilter;
// // TODO: Set this to renderer.getMaxAnisotropy() / 4 image.crossOrigin = '';
// texture.anisotropy = 4;
// texture.needsUpdate = true; // Load image
image.src = url;
// // Something went wrong and the tile or its material is missing this._image = image;
// // }
// // Possibly removed by the cache before the image loaded _getBufferData(images) {
// if (!this._mesh || !this._mesh.children[0] || !this._mesh.children[0].material) { const NW = this._tileBounds.getTopLeft().to;
// return; const SE = this._tileBounds.getBottomRight();
// } const coordinate = [[ NW.x, NW.y ], [ SE.x, SE.y ]];
return [{
coordinate,
images
}];
}
_createMesh(image) {
if (!this._center) {
return;
}
this._layerData = this._getBufferData(image);
const buffer = new ImageBuffer({
layerData: this._layerData
});
// this._mesh.children[0].material.map = texture; const style = this.get('styleOptions');
// this._mesh.children[0].material.needsUpdate = true; const mesh = DrawImage(buffer.attributes, style);
this.Object3D.push(mesh);
return this.Object3D;
}
_abortRequest() {
if (!this._image) {
return;
}
// this._texture = texture; this._image.src = '';
// this._ready = true; }
// }, false);
// // image.addEventListener('progress', event => {}, false); destroy() {
// // image.addEventListener('error', event => {}, false); // Cancel any pending requests
this._abortRequest();
// image.crossOrigin = ''; // Clear image reference
this._image = null;
// // Load image super.destroy();
// image.src = url; }
// this._image = image; }
// }
// _createMesh() {
// // Something went wrong and the tile
// //
// // Possibly removed by the cache before loaded
// if (!this._center) {
// return;
// }
// const mesh = new THREE.Object3D();
// const geom = new THREE.PlaneBufferGeometry(this._side, this._side, 1);
// let material;
// if (!this._world._environment._skybox) {
// material = new THREE.MeshBasicMaterial({
// depthWrite: false
// });
// // const material = new THREE.MeshPhongMaterial({
// // depthWrite: false
// // });
// } else {
// // Other MeshStandardMaterial settings
// //
// // material.envMapIntensity will change the amount of colour reflected(?)
// // from the environment mapcan be greater than 1 for more intensity
// material = new THREE.MeshStandardMaterial({
// depthWrite: false
// });
// material.roughness = 1;
// material.metalness = 0.1;
// material.envMap = this._world._environment._skybox.getRenderTarget();
// }
// const localMesh = new THREE.Mesh(geom, material);
// localMesh.rotation.x = -90 * Math.PI / 180;
// localMesh.receiveShadow = true;
// mesh.add(localMesh);
// mesh.renderOrder = 0.1;
// mesh.position.x = this._center[0];
// mesh.position.z = this._center[1];
// // const box = new BoxHelper(localMesh);
// // mesh.add(box);
// //
// // mesh.add(this._createDebugMesh());
// return mesh;
// }
// _abortRequest() {
// if (!this._image) {
// return;
// }
// this._image.src = '';
// }
// destroy() {
// // Cancel any pending requests
// this._abortRequest();
// // Clear image reference
// this._image = null;
// super.destroy();
// }
// }

View File

@ -1,59 +1,62 @@
// const r2d = 180 / Math.PI; import * as THREE from '../../core/three';
// const tileURLRegex = /\{([zxy])\}/g; import { toLngLatBounds, toBounds } from '@antv/geo-coord';
// export class Tile { import { sphericalMercator } from '@antv/geo-coord/lib/geo/projection/spherical-mercator';
// constructor(layer, z, x, y) { const r2d = 180 / Math.PI;
// this.layer = layer; const tileURLRegex = /\{([zxy])\}/g;
// this._tile = [ z, x, y ];
// } export class Tile {
// _createMesh() {} constructor(layer, z, x, y) {
// _createDebugMesh() {} this.layer = layer;
this._tile = [ x, y, z ];
this._tileLnglatBounds = this._tileLnglatBounds(this._tile);
// _getTileURL(urlParams) { this._tileBounds = this._tileBounds(this._tileLnglatBounds);
// if (!urlParams.s) {
// // Default to a random choice of a, b or c
// urlParams.s = String.fromCharCode(97 + Math.floor(Math.random() * 3));
// }
// tileURLRegex.lastIndex = 0; this._center = this._tileBounds.getCenter();
// return this._path.replace(tileURLRegex, function(value, key) {
// // Replace with paramter, otherwise keep existing value
// return urlParams[key];
// });
// }
// _tileBoundsFromWGS84(boundsWGS84) { this._centerLnglat = this._tileLnglatBounds.getCenter();
// const sw = this._layer._world.latLonToPoint(LatLon(boundsWGS84[1], boundsWGS84[0])); this.Object3D = new THREE.Object3D();
// const ne = this._layer._world.latLonToPoint(LatLon(boundsWGS84[3], boundsWGS84[2]));
// return [sw.x, sw.y, ne.x, ne.y];
// }
// // Get tile bounds in WGS84 coordinates }
// _tileBoundsWGS84(tile) { _createMesh() {}
// const e = this._tile2lon(tile[0] + 1, tile[2]); _getTileURL(urlParams) {
// const w = this._tile2lon(tile[0], tile[2]); if (!urlParams.s) {
// const s = this._tile2lat(tile[1] + 1, tile[2]); // Default to a random choice of a, b or c
// const n = this._tile2lat(tile[1], tile[2]); urlParams.s = String.fromCharCode(97 + Math.floor(Math.random() * 3));
// return [ w, s, e, n ]; }
// }
// _tile2lon(x, z) { tileURLRegex.lastIndex = 0;
// return x / Math.pow(2, z) * 360 - 180; return this._path.replace(tileURLRegex, function(value, key) {
// } return urlParams[key];
});
}
// 经纬度范围转瓦片范围
_tileBounds(lnglatBound) {
const nw = sphericalMercator.project(lnglatBound.getTopLeft());
const se = sphericalMercator.project(lnglatBound.getBottomRight());
// _tile2lat(y, z) { return toBounds(nw, se);
// const n = Math.PI - 2 * Math.PI * y / Math.pow(2, z); }
// return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
// }
// _boundsToCenter(bounds) { // Get tile bounds in WGS84 coordinates
// const x = bounds[0] + (bounds[2] - bounds[0]) / 2; _tileLnglatBounds(tile) {
// const y = bounds[1] + (bounds[3] - bounds[1]) / 2; const e = this._tile2lon(tile[0] + 1, tile[2]);
const w = this._tile2lon(tile[0], tile[2]);
const s = this._tile2lat(tile[1] + 1, tile[2]);
const n = this._tile2lat(tile[1], tile[2]);
return toLngLatBounds([ w, n ], [ e, s ]);
}
// return [ x, y ]; _tile2lng(x, z) {
// } return x / Math.pow(2, z) * 360 - 180;
// destory() { }
// } _tile2lat(y, z) {
// } const n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
}
destory() {
}
}

View File

@ -0,0 +1,8 @@
import Layer from '../core/layer';
export class TileLayer extends Layer {
draw() {
}
drawTile() {
}
}