-
Notifications
You must be signed in to change notification settings - Fork 93
[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
[fix] Limit default max zoom level on mapOptions #188 #363
Conversation
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
There was a problem hiding this 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. 👍 👍
src/js/netjsongraph.render.js
Outdated
const maxZoom = self.leaflet.getMaxZoom(); | ||
const minZoom = self.leaflet.getMinZoom(); |
There was a problem hiding this comment.
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
.
src/js/netjsongraph.render.js
Outdated
const zoomOutBtn = document.querySelector(".leaflet-control-zoom-out"); | ||
|
||
if (currentZoom >= maxZoom) { | ||
zoomInBtn.style.cursor = "not-allowed"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
Updates
|
There was a problem hiding this 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?
src/js/netjsongraph.render.js
Outdated
const currentZoom = self.leaflet.getZoom(); | ||
const {maxZoom} = self.config.mapOptions; | ||
const {minZoom} = self.config.mapOptions; | ||
console.log(minZoom, maxZoom); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log(minZoom, maxZoom); |
src/js/netjsongraph.config.js
Outdated
@@ -238,7 +240,7 @@ const NetJSONGraphDefaultConfig = { | |||
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", | |||
options: { | |||
minZoom: 3, | |||
maxZoom: 32, | |||
maxZoom: 18, |
There was a problem hiding this comment.
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.
fee11d9
to
6533248
Compare
Updates:
|
61e2c40
to
eab3ca5
Compare
eab3ca5
to
186d52d
Compare
There was a problem hiding this 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?
57d3d8f
to
d6413f6
Compare
d6413f6
to
5291568
Compare
.github/workflows/ci.yml
Outdated
@@ -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 |
There was a problem hiding this 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?
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.
There was a problem hiding this 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.
…ged them" This reverts commit 5291568.
Co-Authored-By: Deepanshu Sahu <83969256+dee077@users.noreply.github.com>
Updates:
|
There was a problem hiding this 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?
I removed the custom JS that manually toggled zoom button states and instead used Leaflet’s native Since there's no custom logic anymore, coverage stays the same because we're just testing config now, not redundant JS. |
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. |
There was a problem hiding this 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
Screen.Recording.2025-05-15.at.4.29.30.AM.mov
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. 🙂 |
There was a problem hiding this 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.
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
Reference to Existing Issue
Closes #188.
Description of Changes
Demo
Screencast.from.2025-04-17.03-11-15.mp4