diff --git a/demos/vectorTile.html b/demos/vectorTile.html index b420dca765..720922f3aa 100644 --- a/demos/vectorTile.html +++ b/demos/vectorTile.html @@ -60,7 +60,7 @@ // 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({ @@ -68,9 +68,9 @@ }) .render( ); - //layer.on('mousemove',(feature)=>{ - // console.log(feature); - // }) + layer.on('mousemove',(feature)=>{ + console.log(feature); + }) console.log(layer); }); //OBJECTID',(id)=>{ diff --git a/src/core/engine/picking/picking.js b/src/core/engine/picking/picking.js index 2dc17399e4..a332d1ea51 100755 --- a/src/core/engine/picking/picking.js +++ b/src/core/engine/picking/picking.js @@ -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); diff --git a/src/core/layer.js b/src/core/layer.js index d3f3d489e4..c8714d232d 100644 --- a/src/core/layer.js +++ b/src/core/layer.js @@ -168,7 +168,6 @@ export default class Layer extends Base { } else { scaleDefs[field] = cfg; } - console.log(options); return this; } shape(field, values) { @@ -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, diff --git a/src/layer/tile/imageTile.js b/src/layer/tile/imageTile.js index b552c0d37c..1a16b19c7d 100644 --- a/src/layer/tile/imageTile.js +++ b/src/layer/tile/imageTile.js @@ -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 diff --git a/src/layer/tile/tileLayer.js b/src/layer/tile/tileLayer.js index 624a237984..ca82093dc5 100644 --- a/src/layer/tile/tileLayer.js +++ b/src/layer/tile/tileLayer.js @@ -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'; @@ -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; diff --git a/src/source/parser/geojson.js b/src/source/parser/geojson.js index 7636ec95a9..79e49bd68d 100644 --- a/src/source/parser/geojson.js +++ b/src/source/parser/geojson.js @@ -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); });