Skip to content

[feature] Support custom CRS in default config #380 #381

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dee077
Copy link
Contributor

@dee077 dee077 commented Jun 19, 2025

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 #380.

Description of Changes

  • Added the crs field in the default config
  • Used L.CRS.Simple for the indoor map example and updated the location field accordingly
  • Added selenium test for the indoor map as well.

dee077 added 2 commits June 19, 2025 23:29
Added support for custom CRS and used L.CRS.Simple for the indoormap and added selenium test for the indoor map as well.

Fixes #380
@dee077 dee077 force-pushed the feature/380-add-support-for-custom-crs branch from bd80351 to 253ada2 Compare June 19, 2025 18:21
Make manual enforce of leaflet disable class

Fixes #188
@dee077 dee077 force-pushed the feature/380-add-support-for-custom-crs branch from 253ada2 to 34618e5 Compare June 19, 2025 18:25
Comment on lines +470 to +487
const minZoom = self.leaflet.getMinZoom();
const maxZoom = self.leaflet.getMaxZoom();
const zoomIn = document.querySelector(".leaflet-control-zoom-in");
const zoomOut = document.querySelector(".leaflet-control-zoom-out");

if (zoomIn && zoomOut) {
if (Math.round(currentZoom) >= maxZoom) {
zoomIn.classList.add("leaflet-disabled");
} else {
zoomIn.classList.remove("leaflet-disabled");
}

if (Math.round(currentZoom) <= minZoom) {
zoomOut.classList.add("leaflet-disabled");
} else {
zoomOut.classList.remove("leaflet-disabled");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Add some comments in the code why this logic is needed.

In my testing, this scenario only occurs when the min/max zoom level is not a multiple of zoomSnap.

Copy link
Member

@pandafy pandafy left a comment

Choose a reason for hiding this comment

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

Good work @dee077!

Let's add some code comments to improve maintainability.

Comment on lines 884 to 892
document
.querySelectorAll(".leaflet-control-zoom-in, .leaflet-control-zoom-out")
.forEach((el) => el.remove());
zoomInBtn = document.createElement("a");
zoomInBtn.className = "leaflet-control-zoom-in";
zoomOutBtn = document.createElement("a");
zoomOutBtn.className = "leaflet-control-zoom-out";
document.body.appendChild(zoomInBtn);
document.body.appendChild(zoomOutBtn);
Copy link
Member

Choose a reason for hiding this comment

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

Why is it required to remove the existing buttons in DOM and create new buttons?

Comment on lines 909 to 910
disableClusteringAtLevel: 0,
clusterRadius: 80,
Copy link
Member

Choose a reason for hiding this comment

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

If clustering is set to false, do these options make sense?

Comment on lines 1032 to 1035
expect(document.querySelector(".leaflet-control-zoom-in")).toBe(zoomInBtn);
expect(document.querySelector(".leaflet-control-zoom-out")).toBe(
zoomOutBtn,
);
Copy link
Member

Choose a reason for hiding this comment

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

Why both these elements should have "leaflet-control-zoom-out" class at the beginning?

Copy link
Member

Choose a reason for hiding this comment

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

Can you add code comments to state the objective of the test (and helper functions)? It is a bit confusing right now.

// set map initial state.
mapOptions: {
center: [48.577, 18.539],
zoom: 5.5,
zoom: 1,
Copy link
Member

Choose a reason for hiding this comment

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

Let's make it 0

@@ -120,37 +121,31 @@
},

onReady: function presentIndoormap() {
const netjsonmap = this.leaflet;
const netjsonmap = this.leaflet;
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
const netjsonmap = this.leaflet;
const netjsonmap = this.leaflet;

There was a blank space at the end of line. You can configure your code editor to automatically remove them upon save.

Comment on lines 134 to 135
const bottomRight = netjsonmap.unproject([0, h * 2], zoom);
const upperLeft = netjsonmap.unproject([w * 2, 0], zoom);
Copy link
Member

Choose a reason for hiding this comment

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

I plotted these points on the cartesian plane

Screenshot from 2025-06-23 17-02-20
Screenshot from 2025-06-23 17-04-21

I believe the name of the variables is misleading.

@dee077
Copy link
Contributor Author

dee077 commented Jun 23, 2025

Updates

  • Added comments above the zoom controls.
  • Simplified the unit tests using the leaflet map render instead of mocking everything.

@dee077 dee077 force-pushed the feature/380-add-support-for-custom-crs branch from 8fc3608 to 82fc8b8 Compare June 24, 2025 17:07
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.

Looks good to me.

One favour @dee077, there's a red label appearing when hovering the mouse over the nodes which is redundant, can you remove that please?

Screenshot from 2025-06-24 14-31-35

@pandafy @niteshsinha17 let me know once you think this is ready to merge.

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.

[feature] Add Support for custom CRS (coordinate reference system)
3 participants