Skip to content

[fix] Limit default max zoom level on mapOptions #188 #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dee077
Copy link
Contributor

@dee077 dee077 commented Apr 16, 2025

Prevent map from exceeding supported zoom levels of tile providers and added cursor not allowed on hitting min or max zoom level

Fixes #188

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #188.

Description of Changes

  • Added minZoom:3 and maxZoom:18 to mapOptions
  • Reduced maxZoom to 18 in mapTileConfig
  • Added cursor not allowed on hitting max or min zoom level
  • Updated the same zoom levels in tests

Demo

Screencast.from.2025-04-17.03-11-15.mp4

dee077 and others added 2 commits April 17, 2025 03:01
Prevent map from exceeding supported zoom levels of tile providers and added cursor not allowed on hitting min or max zoom level

Fixes openwisp#188
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dee077 thanks for adding the recording! It looks very promising!
I will test and look closer into this asap. 👍 👍

Comment on lines 460 to 461
const maxZoom = self.leaflet.getMaxZoom();
const minZoom = self.leaflet.getMinZoom();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dee077 How you figured out that getMaxZoom function is present on leaflet. We could use self.config.

const zoomOutBtn = document.querySelector(".leaflet-control-zoom-out");

if (currentZoom >= maxZoom) {
zoomInBtn.style.cursor = "not-allowed";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of cursor not allowed, let's reduce its opacity and set pointer event to none.

Copy link
Member

@niteshsinha17 niteshsinha17 Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a class for this.

Copy link
Contributor Author

@dee077 dee077 Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

@dee077
Copy link
Contributor Author

dee077 commented Apr 27, 2025

Updates

  • Take zoom values from self.config
  • Toggle zoom button state via classes instead of directly changing styles
  • Set floorplan default zoom to 4 (to avoid decimal value conflicts in <= comparison)

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dee077 looks almost ready but please see my comments below.

Can you add 1 browser test for testing maxZoom and minZoom?

const currentZoom = self.leaflet.getZoom();
const {maxZoom} = self.config.mapOptions;
const {minZoom} = self.config.mapOptions;
console.log(minZoom, maxZoom);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(minZoom, maxZoom);

@@ -238,7 +240,7 @@ const NetJSONGraphDefaultConfig = {
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
options: {
minZoom: 3,
maxZoom: 32,
maxZoom: 18,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need minZoom and maxZoom to be defined both here and above in mapOptions?

Can we avoid this redundancy? Maybe the mapTileConfig logic can take these settings from mapOptions?
Or would it be possible in each mapTileConfig to override what is in mapOptions? If so, a few code comments would help understanding this more quickly.

I see the minZoom and maxZoom properties of mapTileConfig are already documented in the README, please review the text there to ensure it's up to date.

@dee077 dee077 force-pushed the issues/188-limit-max-zoom-tile-support branch 2 times, most recently from fee11d9 to 6533248 Compare May 5, 2025 12:07
@dee077
Copy link
Contributor Author

dee077 commented May 5, 2025

Updates:

  • Removed min max zoom from mapTileConfig.
  • Added selenium test to check the max zoom. The the tile error coming on console is coming late after in between 5s to 10s. That's why added a sleep time of 15s to catch these errors.
  • Sometimes the test runs slower in ci, should I increase the sleep time to more?

@dee077 dee077 force-pushed the issues/188-limit-max-zoom-tile-support branch 3 times, most recently from 61e2c40 to eab3ca5 Compare May 5, 2025 12:39
@dee077 dee077 force-pushed the issues/188-limit-max-zoom-tile-support branch from eab3ca5 to 186d52d Compare May 5, 2025 12:46
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dee077 @niteshsinha17 this looks good to me now, the only issue is the coverage going down, the browser tests now are excluded from the coverage calculation, do you know if there's a way to include them?

@dee077 dee077 force-pushed the issues/188-limit-max-zoom-tile-support branch 3 times, most recently from 57d3d8f to d6413f6 Compare May 6, 2025 11:14
@dee077 dee077 force-pushed the issues/188-limit-max-zoom-tile-support branch from d6413f6 to 5291568 Compare May 6, 2025 11:19
@@ -85,11 +85,15 @@ jobs:
which chromedriver

- name: Unit tests
run: yarn coverage --testPathIgnorePatterns=test/netjsongraph.browser.test.js

run: npx nyc --silent yarn coverage --testPathIgnorePatterns=test/netjsongraph.browser.test.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dee077 @niteshsinha17 this looks good to me now, the only issue is the coverage going down, the browser tests now are excluded from the coverage calculation, do you know if there's a way to include them?

Looks good to me too.

@dee077 @nemesifier I think netjsongraph.browser.test.js is being ignored while running tests and generating coverage. May be need to change this line.

niteshsinha17

This comment was marked as duplicate.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I think this is part of the GSoC project of @cestercian.

I would let @cestercian step in on this. Yash, please review and test.
Can you find a solution for the test coverage?

@dee077 please give write permissions to your repo to @cestercian so he can push to this branch if needed.

In the coming weeks I'll set you up to be able to create branches in the openwisp repositories.

@cestercian cestercian assigned cestercian and unassigned cestercian May 10, 2025
cestercian and others added 2 commits May 10, 2025 21:52
Co-Authored-By: Deepanshu Sahu <83969256+dee077@users.noreply.github.com>
@cestercian
Copy link
Contributor

Updates:

  • Removed enabled disabled class addition using js as there's already a class leaflet disabled and leaflet enabled enforced on enabled disabled state

  • Updated test cases for the same

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help me understand what's going on, the test coverage now doesn't suffer due to the removal of the custom code?

@cestercian
Copy link
Contributor

I removed the custom JS that manually toggled zoom button states and instead used Leaflet’s native .leaflet-disabled class (which I discovered while going through the Leaflet docs).

Since there's no custom logic anymore, coverage stays the same because we're just testing config now, not redundant JS.

@dee077
Copy link
Contributor Author

dee077 commented May 11, 2025

I have also refactored the code to assign values conditionally instead of using separate if-else blocks in render.js. This reduced the number of uncovered lines in the file, while keeping the tests unchanged. As a result, we observed a slight increase in the coverage percentage.

Previously, when we added custom classes for enabled and disabled states, it introduced additional uncovered lines, which led to a drop in coverage.

But still the selenium tests are not included in the coverage.

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an issue while testing: clicking on the disabled button seems to move the map, as if the button became transparent with respect to its behavior.

Is that intended? Can it be prevented? Ideally nothing should happen.

max-zoom.webm

removed pointer-event property in src/css
@cestercian
Copy link
Contributor

Screen.Recording.2025-05-15.at.4.29.30.AM.mov

pointer-events: none makes the element transparent to pointer interactions — including allowing clicks to pass through to elements underneath. At the time, we actually thought that behavior was beneficial for our use case.

That said, it turned out to cause unintended side effects (like interacting with the map beneath a disabled button), so I’ve removed the property to keep things working as expected. 🙂

@cestercian cestercian requested a review from nemesifier May 14, 2025 23:23
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @dee077 @cestercian! 👍

I am assuming the mapTileConfig line in the README is still valid also after these changes, right? If not, please update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

[bug] Map default zoom levels seem to allow for more zoom than supported
4 participants