Skip to content

Commit

Permalink
fix(tilelayer): point pickup
Browse files Browse the repository at this point in the history
  • Loading branch information
lzxue committed May 27, 2019
1 parent b6d2109 commit cef72bc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
8 changes: 4 additions & 4 deletions demos/vectorTile.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@
// cylinder
.shape('hexagon')
.size(2)
.active(false)
.active({fill:'red'})
.color('total', ['#d53e4f','#f46d43','#fdae61','#fee08b','#ffffbf','#e6f598','#abdda4','#66c2a5','#3288bd'].reverse())
//.color('#0D408C')
.style({
opacity:1.0
})
.render(
);
//layer.on('mousemove',(feature)=>{
// console.log(feature);
// })
layer.on('mousemove',(feature)=>{
console.log(feature);
})
console.log(layer);
});
//OBJECTID',(id)=>{
Expand Down
1 change: 1 addition & 0 deletions src/core/engine/picking/picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Picking {
}
_update(point) {
const texture = this._pickingTexture;
// this._pickingTexture
this._renderer.render(this._pickingScene, this._camera, this._pickingTexture);
this.pixelBuffer = new Uint8Array(4);
this._renderer.readRenderTargetPixels(texture, point.x, this._height - point.y, 1, 1, this.pixelBuffer);
Expand Down
3 changes: 1 addition & 2 deletions src/core/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ export default class Layer extends Base {
} else {
scaleDefs[field] = cfg;
}
console.log(options);
return this;
}
shape(field, values) {
Expand Down Expand Up @@ -627,8 +626,8 @@ export default class Layer extends Base {
}
this._activeIds = featureId;
// TODO 瓦片图层获取选中数据信息
const { feature, style } = this.getSelectFeature(featureId);
const lnglat = this.scene.containerToLngLat(point2d);
const { feature, style } = this.getSelectFeature(featureId, lnglat);
// const style = this.layerData[featureId - 1];
const target = {
featureId,
Expand Down
1 change: 0 additions & 1 deletion src/layer/tile/imageTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import Tile from './tile';
import ImageBuffer from '../../geom/buffer/image';
import DrawImage from '../render/image/drawImage';
import * as THREE from '../../core/three';
export default class ImageTile extends Tile {
requestTileAsync() {
// Making this asynchronous really speeds up the LOD framerate
Expand Down
21 changes: 9 additions & 12 deletions src/layer/tile/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import source from '../../core/source';
import * as THREE from '../../core/three';
import Global from '../../global';
const { pointShape } = Global;
import { updateObjecteUniform } from '../../util/object3d-util';
import TileCache from './tileCache';
import pickingFragmentShader from '../../core/engine/picking/picking_frag.glsl';
import { throttle, deepMix } from '@antv/util';
Expand Down Expand Up @@ -208,17 +207,15 @@ export default class TileLayer extends Layer {
this._pickTiles.add(pickingMesh);

}
getSelectFeature(id) {
let feat = null;
this._tileKeys.forEach(key => {
const tile = this._tileCache.getTile(key);
const feature = tile ? tile.getSelectFeature(id) : null;
if (feature !== null) {
feat = feature;
return;
}
});
return { feature: feat };
// 根据距离优先级查找
getSelectFeature(id, lnglat) {
const zoom = Math.round(this.scene.getZoom()) - 1;
const tilePoint = this._crs.lngLatToPoint(toLngLat(lnglat.lng, lnglat.lat), zoom);
const tileXY = tilePoint.divideBy(256).round();
const key = [ tileXY.x, tileXY.y, zoom ].join('_');
const tile = this._tileCache.getTile(key);
const feature = tile ? tile.getSelectFeature(id) : null;
return { feature };
}
_pruneTiles() {
let tile;
Expand Down
22 changes: 11 additions & 11 deletions src/source/parser/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export default function geoJSON(data, cfg) {
turfMeta.flattenEach(data, (currentFeature, featureIndex) => { // 多个polygon 拆成一个
const coord = getCoords(currentFeature);
let id = featureIndex + 1;
// if (cfg.idField) {
// const value = currentFeature.properties[cfg.idField];
// // id = value;
// id = BKDRHash(value) % 1000019;
// if (featureKeys[id] && featureIndex !== featureKeys[id]) {
// // TODO 哈希冲突解决方法
// console.log('哈希冲突', value);
// }
// featureKeys[id] = featureIndex;
// }
if (cfg.idField && currentFeature.properties[cfg.idField]) {
const value = currentFeature.properties[cfg.idField];
// id = value;
id = BKDRHash(value) % 1000019;
// if (featureKeys[id] && featureIndex !== featureKeys[id]) {
// // TODO 哈希冲突解决方法
// console.log('哈希冲突', value);
// }
}
featureKeys[id] = featureIndex;
const dataItem = {
...currentFeature.properties,
coordinates: coord,
_id: currentFeature.properties[cfg.idField]
_id: id
};
resultData.push(dataItem);
});
Expand Down

0 comments on commit cef72bc

Please sign in to comment.