Skip to content

Commit

Permalink
fix: only visible features are selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
hbruch committed Sep 24, 2024
1 parent 2f4614a commit 4095527
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
16 changes: 13 additions & 3 deletions app/component/map/tile-layer/BikeRentalStations.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const query = graphql`
const REALTIME_REFETCH_FREQUENCY = 60000; // 60 seconds

// TODO rename to VehicleRentalStation
// TODO this is a Layer without saying so. If they had an explicit interface,
// they could share some common logic
class BikeRentalStations {
constructor(tile, config, mapLayers, relayEnvironment) {
this.tile = tile;
Expand Down Expand Up @@ -124,12 +126,13 @@ class BikeRentalStations {
};

draw = (feature, zoomedIn) => {
if (!this.shouldShowFeature(feature)) {
return;
}

const { id, network, formFactors, formFactor } = feature.properties;
// stations have formFactors (comma separeted list), vehicles formFactor, or bicycle if non...
const formFactorsOrDefault = formFactors || formFactor || 'bicycle';
if (!this.shouldShowStation(id, network, formFactorsOrDefault)) {
return;
}

const { iconName, bgColor, fgColor } = getRentalNetworkIconAndColors(
network,
Expand Down Expand Up @@ -233,6 +236,13 @@ class BikeRentalStations {
this.isAnyFormFactorEnabled(formFactors) &&
showCitybikeNetwork(this.config.cityBike.networks[network]);

shouldShowFeature = feature => {
const { id, network, formFactors, formFactor } = feature.properties;
// stations have formFactors (comma separeted list), vehicles formFactor, or bicycle if non...
const formFactorsOrDefault = formFactors || formFactor || 'bicycle';
return this.shouldShowStation(id, network, formFactorsOrDefault);
};

static getName = () => 'citybike';
}

Expand Down
5 changes: 5 additions & 0 deletions app/component/map/tile-layer/ParkAndRideForBikes.bbnavi.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ class ParkAndRideForBikes {
}
};

shouldShowFeature = feature => {
const type = ParkAndRideForBikes.getBikeParkType(feature.properties?.tags);
return this.tile.coords.z >= (type.minZoom || 0);
};

static getName = () => 'parkAndRideForBikes';
}

Expand Down
20 changes: 13 additions & 7 deletions app/component/map/tile-layer/TileContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,19 @@ class TileContainer {

features = flatMap(this.layers, layer =>
layer.features
? layer.features.map(feature => ({
layer: layer.constructor.getName(),
// todo: this is really ugly!
layerConfig: layer.constructor.layerConfig,
feature,
coords: this.project(feature.geom),
}))
? layer.features
.filter(feature => {
return layer.shouldShowFeature
? layer.shouldShowFeature(feature)
: true;
})
.map(feature => ({
layer: layer.constructor.getName(),
// todo: this is really ugly!
layerConfig: layer.constructor.layerConfig,
feature,
coords: this.project(feature.geom),
}))
: [],
);
features = projectedVehicles.concat(features);
Expand Down

0 comments on commit 4095527

Please sign in to comment.