Skip to content

[change] Uniform geojson map rendering #396

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 27 commits into
base: master
Choose a base branch
from

Conversation

cestercian
Copy link
Member

@cestercian cestercian commented Jul 12, 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 #395 .

Description of Changes

Streamed line map rendering logic for GeoJSON and NetJSON map data type

Screenshot

Please include any relevant screenshots.

Updated the Echarts rendering logic to wrok with
Updated the Echarts rendering logic to wrok with
@nemesifier nemesifier changed the title Stramlining map rendering [change] Uniform geojson map rendering Jul 14, 2025
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.

Seems to be moving in the right direction, I guess we can remove marker cluster now, right?

QA checks and CI builds are failing, please fix.

See my comments below.

// clustering and ECharts overlays.
this.originalGeoJSON = JSON.parse(JSON.stringify(JSONData));
JSONData = this.utils.geojsonToNetjson(JSONData);
this.type = "netjson";
Copy link
Member

Choose a reason for hiding this comment

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

what's the point of keeping this stuff and keep all the if statements if the value is always netjson?

We should be able to simplify the code and remove the useless if statements. I wouldn't change the type of the object, it feels wrong to me.

Copy link
Member

Choose a reason for hiding this comment

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

I still see this.type = "netjson"; here, why?
Is it really necessary to change it?

Simplifies the data pipeline by converting GeoJSON input to NetJSON early and treating all data as NetJSON internally. Removes legacy GeoJSON-specific branches, updates appendData logic, and adjusts tests to match the unified approach. This improves maintainability and consistency in map rendering and data updates.
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.

Please squash the commits in this PR into one commit so that it will be easier to manage with #349.

Streamlines the map rendering logic for GeoJSON and NetJSON data types
and removes the marker-cluster dependency.

Closes #395.
@cestercian
Copy link
Member Author

Please squash the commits in this PR into one commit so that it will be easier to manage with #349.

Squashed in 48b36ae

@cestercian cestercian requested a review from nemesifier July 18, 2025 00:02
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 have some questions below.

self.originalGeoJSON = JSON.parse(JSON.stringify(JSONData));
JSONData = self.utils.geojsonToNetjson(JSONData);
// From this point forward we treat the data as NetJSON
self.type = "netjson";
Copy link
Member

Choose a reason for hiding this comment

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

I tried removing this and the geojson example continues working without errors, are you sure it's necessary? It feels wrong to me. You have already cleand up the code which was checking whether type is netjson, we assume there's only one way to load data now, why is this still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

the code is not only checking if type is NetJSON it also preserve the original GeoJSON via self.originalGeoJSON to still render polygons.

Copy link
Member

Choose a reason for hiding this comment

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

I am asking to avoid changing the type here, but change any other code that relies on type being netjson so that we assume the type is always netjson.

Extracted all GeoJSON-specific logic into src/js/netjsongraph.geojson.js for better maintainability and clarity. Updated the public API to forward geojsonToNetjson calls to the new helper. Refactored map rendering to use addPolygonOverlays for displaying Polygon and MultiPolygon features on Leaflet. Updated documentation to reflect these changes and improve clarity on GeoJSON support.
Copy link
Member Author

@cestercian cestercian left a comment

Choose a reason for hiding this comment

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

Addressed all the changes Kindly let me know if any other changes are required

@cestercian cestercian requested a review from nemesifier July 21, 2025 18:15
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 still see type being changed in a couple of places which I explained I feel it's wrong and we shouldn't do it, see my comments below.

// clustering and ECharts overlays.
this.originalGeoJSON = JSON.parse(JSON.stringify(JSONData));
JSONData = this.utils.geojsonToNetjson(JSONData);
this.type = "netjson";
Copy link
Member

Choose a reason for hiding this comment

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

I still see this.type = "netjson"; here, why?
Is it really necessary to change it?

self.originalGeoJSON = JSON.parse(JSON.stringify(JSONData));
JSONData = self.utils.geojsonToNetjson(JSONData);
// From this point forward we treat the data as NetJSON
self.type = "netjson";
Copy link
Member

Choose a reason for hiding this comment

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

I am asking to avoid changing the type here, but change any other code that relies on type being netjson so that we assume the type is always netjson.

Updates NetJSONGraph to retain 'geojson' as the public-facing type when loading GeoJSON data, instead of converting it to 'netjson'. Adjusts related rendering logic and tests to reflect this change.
@cestercian
Copy link
Member Author

I still see type being changed in a couple of places which I explained I feel it's wrong and we shouldn't do it, see my comments below.

Noted and addressed in 5d63609 now we don't explicitly change the type to netJSON from geoJSON we just assume it's netJSON.

@cestercian cestercian requested a review from nemesifier July 22, 2025 01:45
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.

On master:

Screenshot from 2025-07-22 09-16-14

On this branch:

Screenshot from 2025-07-22 09-14-43

The Polygon is drawn in a way that makes it look as if there were additional points drawn on the map, which shouldn't happen.

Can you please edit the sample data to make sure we have at least one geojson geometry of each type supported?

This way we can make sure they all look as they should. Use a geojson visualizer (like the one here on github) to see how each standard geojson geometry should look like.

Added MultiPoint, LineString, MultiLineString, and MultiPolygon features to the GeoJSON sample data for broader geometry coverage. Refactored geometry handling in netjsongraph.geojson.js by removing unused Polygon and MultiPolygon processing code.
@cestercian cestercian requested a review from nemesifier July 22, 2025 16:03
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.

It's almost there but I still see a few details to adjust, let's compare the output of the github visualizer and https://geojson.io.

This is the current sample data visualized with the current implementation:

Screenshot from 2025-07-22 16-22-56

This is the github visualizer:

Screenshot from 2025-07-22 16-21-51

Which can be viewed by opening: https://github.com/openwisp/netjsongraph.js/blob/7cdb431162dfed76c5dac3eb39429efbaebbb067/public/assets/data/geojson-sample.json

This is the geojson.io visualizer (copy/paste the example data):

Screenshot from 2025-07-22 16-23-48

Now let's Observe the key differences:

  • The other visualizers don't use circles to highlight the coordinates, shapes are just drawn
  • The visualizers automatically center the view based on the data being shown, bounds are calculated and map center and zoom are automatically calculated so that the view is able to show everything when the map is loaded. This is very important, please make sure the library is able to behave identically

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.

Screenshot from 2025-07-22 16-29-42
  • I noticed that some output values appear as [Object, Object]. Please add a few more sample properties and ensure all are shown correctly (please add an assertion in the tests for this).

  • Let's treat properties.name as a special case and convert it as netjson label (needs assertion in tests).

  • Can we convert lines and multi line strings as links in netjson? (needs assertion in tests)

  • Please add some id elements to the sample data and verify with an assertion that is converted in netjson format.

  • Where is the value Gjn_4 coming from? I don’t see any corresponding entry in the data sources. This random stuff shouldn't appear, make sure there's some test data which doesn't have any name, id or property defined and have an assertion to verify these random names are not shown.

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

Successfully merging this pull request may close these issues.

[change] StreamLining the map rendering logic
2 participants