Skip to content

Commit

Permalink
fix bitmap layer auto highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
Xintong Xia committed Mar 25, 2019
1 parent 4616d21 commit d45ec7e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 34 deletions.
40 changes: 12 additions & 28 deletions examples/website/openstreet-map/app.js
Expand Up @@ -7,15 +7,12 @@ export const INITIAL_VIEW_STATE = {
latitude: 47.65,
longitude: 7,
zoom: 4.5,
// https://wiki.openstreetmap.org/wiki/Zoom_levels
maxZoom: 20,
pitch: 50,
bearing: 0
};

// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_servers
// `s` represents sub-domain of tile servers
const s = 'c';
const tileServer = 'https://c.tile.openstreetmap.org/';

export class App extends PureComponent {
constructor(props) {
Expand All @@ -37,23 +34,7 @@ export class App extends PureComponent {
tile && (
<div className="tooltip" style={{left: x, top: y}}>
<div className="tooltip-item">
<div>tile:</div>
<div>
x: {tile.x}, y: {tile.y}, z: {tile.z}
</div>
</div>
<div className="tooltip-item">
<div>boundary:</div>
<div>
north: {sourceLayer.props.bounds[3].toFixed(4)}, west:{' '}
{sourceLayer.props.bounds[0].toFixed(4)}
</div>
</div>
<div className="tooltip-item">
<div>coordinates:</div>
<div>
x: {x.toFixed(4)}, y: {y.toFixed(4)}
</div>
tile: x: {tile.x}, y: {tile.y}, z: {tile.z}
</div>
</div>
)
Expand All @@ -65,17 +46,20 @@ export class App extends PureComponent {
new TileLayer({
pickable: true,
onHover: this._onHover,
autoHighlight: true,
highlightColor: [60, 60, 60, 40],
opacity: 1,
// https://wiki.openstreetmap.org/wiki/Zoom_levels
minZoom: 0,
maxZoom: 19,

renderSubLayers: props => {
const {x, y, z, bbox} = props.tile;
const {west, south, east, north} = bbox;

return new BitmapLayer({
id: `bitmap-${props.id}`,
image: `https://${s}.tile.openstreetmap.org/${z}/${x}/${y}.png`,
bounds: [west, south, east, north],

pickable: true,
tile: props.tile
return new BitmapLayer(props, {
image: `${tileServer}/${z}/${x}/${y}.png`,
bounds: [west, south, east, north]
});
}
})
Expand Down
2 changes: 2 additions & 0 deletions modules/core/src/lib/picking/pick-info.js
Expand Up @@ -114,6 +114,8 @@ export function processPickInfo({
layer.setModuleParameters({
pickingSelectedColor
});

layer.setNeedsRedraw();
});

return infos;
Expand Down
2 changes: 1 addition & 1 deletion modules/geo-layers/src/tile-layer/tile-layer.js
Expand Up @@ -91,7 +91,7 @@ export default class TileLayer extends CompositeLayer {
Object.assign({}, this.props, {
id: `${this.id}-${tile.x}-${tile.y}-${tile.z}`,
data: tile.data,
visible: visible && (this.state.isLoaded || tile.z === z),
visible: visible && (!this.state.isLoaded || tile.z === z),
tile
})
);
Expand Down
4 changes: 0 additions & 4 deletions modules/layers/src/bitmap-layer/bitmap-layer-fragment.js
Expand Up @@ -33,10 +33,6 @@ vec4 apply_opacity(vec3 color, float alpha) {
void main(void) {
vec4 bitmapColor = texture2D(bitmapTexture, vTexCoord);
if (bitmapColor == vec4(0., 0., 0., 1.)) {
discard;
}
gl_FragColor = apply_opacity(color_tint(color_desaturate(bitmapColor.rgb)), bitmapColor.a * opacity);
// use highlight color if this fragment belongs to the selected object.
Expand Down
3 changes: 2 additions & 1 deletion modules/layers/src/bitmap-layer/bitmap-layer-vertex.js
Expand Up @@ -4,6 +4,7 @@ export default `
attribute vec2 texCoords;
attribute vec3 positions;
attribute vec2 positions64xyLow;
attribute vec3 instancePickingColors;
varying vec2 vTexCoord;
Expand All @@ -12,6 +13,6 @@ void main(void) {
vTexCoord = texCoords;
picking_setPickingColor(vec3(0., 0., 1.));
picking_setPickingColor(instancePickingColors);
}
`;
2 changes: 2 additions & 0 deletions modules/layers/src/bitmap-layer/bitmap-layer.js
Expand Up @@ -81,6 +81,8 @@ export default class BitmapLayer extends Layer {
value: new Float32Array(positions)
}
});

this.setState({numInstances: 1});
}

updateState({props, oldProps, changeFlags}) {
Expand Down

0 comments on commit d45ec7e

Please sign in to comment.