Skip to content

Commit

Permalink
Remove unnecessary if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
matths committed Feb 1, 2025
1 parent f04108c commit 1290c3b
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions test/examples/popup-on-hover.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,26 @@
// and use mousemove instead of mouseenter event
let currentFeatureCoordinates = undefined;
map.on('mousemove', 'places', (e) => {
if (e.features && e.features.length > 0) {
const featureCoordinates = e.features[0].geometry.coordinates.toString();
if (currentFeatureCoordinates !== featureCoordinates) {
currentFeatureCoordinates = featureCoordinates;
const featureCoordinates = e.features[0].geometry.coordinates.toString();
if (currentFeatureCoordinates !== featureCoordinates) {
currentFeatureCoordinates = featureCoordinates;

// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';

const coordinates = e.features[0].geometry.coordinates.slice();
const description = e.features[0].properties.description;
const coordinates = e.features[0].geometry.coordinates.slice();
const description = e.features[0].properties.description;

// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}

// Populate the popup and set its coordinates
// based on the feature found.
popup.setLngLat(coordinates).setHTML(description).addTo(map);
// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
// over the copy being pointed to.
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}

// Populate the popup and set its coordinates
// based on the feature found.
popup.setLngLat(coordinates).setHTML(description).addTo(map);
}
});

Expand Down

0 comments on commit 1290c3b

Please sign in to comment.