Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Conversation

andrewgryan
Copy link
Contributor

@andrewgryan andrewgryan commented Mar 2, 2024

Add support for second positional argument to L.polygon via the data-options attribute.

Summary by CodeRabbit

  • New Features
    • Enhanced handling of geometry data attributes and options in mapping functionalities.
  • Bug Fixes
    • Fixed data attribute access in geometry handling functions.
  • Tests
    • Added tests for creating and modifying Leaflet polygon and polyline objects with options.
  • Documentation
    • Updated usage.md with information on adding icons for Point geometries.

Copy link

coderabbitai bot commented Mar 2, 2024

Walkthrough

The updates revolve around refining geometry handling in a mapping application, focusing on streamlining node changes and options management within hyperleaflet objects. Functions have been fine-tuned to enhance data access and processing, while new features and tests bolster the versatility of creating and modifying leaflet geometries. The expanded testing coverage ensures the reliability and resilience of geometry operations.

Changes

Files Change Summary
.../hyperleaflet-geometry-handler.js & .../test/hyperleaflet-geometry-handler.test.js Directly access changes and handle arrays efficiently. Added tests for creating/modifying Leaflet objects with options.
.../index.js Modified hyperleafletDataToMap to include 'data-options' in attributeFilter.
.../leaflet-geometry.js Introduced support for custom icons in leaflet markers via icon property. Enhanced createPointGeometry, createLineGeometry, createPolygonGeometry functions with new options. Updated createLeafletObject to pass options and icon properties.
.../test/geometry-object-handler.test.js Reformatted LineString coordinates for better readability in tests.
.../test/hyperleaflet-geometry-handler.test.js Added tests for creating and modifying Leaflet polygon and polyline objects with specific options.

🐰✨
In the realm of code, where leaflets dance,
A rabbit hopped, giving maps a chance.
With tweaks and twists, it weaved its spell,
Geometry transformed, in a digital dell.
"To polygons and lines," it cheerily said,
"I bring you options, fear not to tread!"
🌍📐✨


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0319474 and b0dd7b0.
Files selected for processing (6)
  • docs/docs/usage.md (1 hunks)
  • src/Geometry/hyperleaflet-geometry-handler.js (2 hunks)
  • src/Geometry/index.js (1 hunks)
  • src/Geometry/leaflet-geometry.js (4 hunks)
  • src/Geometry/test/geometry-object-handler.test.js (1 hunks)
  • src/Geometry/test/hyperleaflet-geometry-handler.test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/Geometry/test/geometry-object-handler.test.js
Additional comments not posted (8)
src/Geometry/index.js (1)

40-40: Ensure that the addition of 'data-options' to attributeFilter is handled appropriately in downstream functions.

src/Geometry/hyperleaflet-geometry-handler.js (2)

30-30: Verify that the change to directly use change['data-id'] correctly fetches the ID from the change object.

Verification successful

The search results confirm the presence of the function changeNodeInHyperleaflet in the file src/Geometry/hyperleaflet-geometry-handler.js. The function indeed uses change['data-id'] to fetch the ID from the change object, as shown in the snippet:

function changeNodeInHyperleaflet(change, map) {
  const rowId = change['data-id'];
  ...
}

This matches the change described in the review comment, verifying that the code correctly fetches the ID using change['data-id']. Additionally, the context in which this function is called (changeNodeInHyperleaflet({ ...partialChange, dataset }, map)) suggests that the data-id is expected to be part of the change object, supporting the direct usage of change['data-id'] in the function.

Based on this information, the review comment is consistent with the codebase, and the implementation appears correct as per the provided context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Ensure that 'data-id' is always present in the change object when `changeNodeInHyperleaflet` is called.
ast-grep --lang javascript --pattern $'changeNodeInHyperleaflet($_, $_) {
  $$$
  $_["data-id"]
  $$$
}'

Length of output: 592



Script:

#!/bin/bash
# Correcting the pattern to ensure it matches the structure of the function and checks for the presence of 'data-id'
ast-grep --lang javascript --pattern $'function changeNodeInHyperleaflet($$$) {
  $$$
  $_["data-id"]
  $$$
}'

Length of output: 111



Script:

#!/bin/bash
# Use ripgrep to search for the function 'changeNodeInHyperleaflet' and any usage of 'change["data-id"]' in the codebase
rg 'changeNodeInHyperleaflet' -A 10 -B 10
rg 'change\["data-id"\]' -A 10 -B 10

Length of output: 3368


53-63: Review the handling of partial changes to ensure that all expected properties are correctly processed and applied to the Leaflet object.

src/Geometry/leaflet-geometry.js (3)

1-1: Ensure that all necessary Leaflet imports are present for the new features.

Verification successful

Given the repeated failures of the scripts to detect the specified import statement, despite the initial snippet clearly showing the import of icon and polyline from 'leaflet', it appears there might be an issue with the script execution or file access rather than the content itself. The initial code snippet provided in the review context already confirms the presence of the necessary imports:

import { GeoJSON, icon, marker, polygon, polyline } from 'leaflet';

This line includes both icon and polyline, which are necessary for the features mentioned in the review comment. Therefore, based on the initial snippet provided, the imports for handling icons and polyline options are correctly included in the file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check if all necessary Leaflet components are imported for handling icons and polyline options.
rg --type js 'import {.*icon.*polyline.*} from "leaflet"' src/Geometry/leaflet-geometry.js

Length of output: 225



Script:

#!/bin/bash
# Corrected script to check if all necessary Leaflet components are imported for handling icons and polyline options.
rg --type js 'import {[^}]*icon[^}]*polyline[^}]*} from "leaflet"' src/Geometry/leaflet-geometry.js

Length of output: 243



Script:

#!/bin/bash
# Simplified script to check if 'icon' and 'polyline' are present in the import statement from 'leaflet'.
rg --type js 'import {.*} from "leaflet"' src/Geometry/leaflet-geometry.js | grep -E 'icon|polyline'

Length of output: 219



Script:

#!/bin/bash
# Further simplified script to directly check the import statement from 'leaflet' in the file.
cat src/Geometry/leaflet-geometry.js | grep 'import {.*} from "leaflet"'

Length of output: 74


6-14: Review the implementation of custom icons in markers to ensure that the icon settings are correctly parsed and applied.


57-60: Ensure that polyline options are correctly applied to polygon geometries.

src/Geometry/test/hyperleaflet-geometry-handler.test.js (1)

124-174: Ensure that the new test cases adequately cover the creation and modification of Leaflet objects with polyline options.

docs/docs/usage.md (1)

171-176: Consider providing an example of how to use the data-icon attribute in practice.

While the documentation for the data-icon attribute is clear, including a practical example of how to use this attribute in a real-world scenario could greatly enhance understanding for users. This could be a simple code snippet showing a map with a custom icon.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ef4733a and b08ac00.
Files selected for processing (3)
  • src/Geometry/leaflet-geometry.js (2 hunks)
  • src/Geometry/test/geometry-object-handler.test.js (1 hunks)
  • src/Geometry/test/hyperleaflet-geometry-handler.test.js (1 hunks)
Additional comments: 4
src/Geometry/test/geometry-object-handler.test.js (1)
  • 82-86: The change to reformat the coordinates array for the LineString type by splitting the coordinates into individual arrays for each point is correctly implemented. This adjustment ensures that the coordinates are structured in a way that is consistent with the expected format for LineString geometries in Leaflet. This change is crucial for the correct handling of LineString geometries and aligns with the PR's objective to enhance geometry handling capabilities.
src/Geometry/leaflet-geometry.js (2)
  • 52-55: The addition of the polylineOptions parameter in the createPolygonGeometry function is correctly implemented. This change allows for more flexible and detailed configuration of polygons by enabling the specification of polyline options directly when creating a polygon. It's important to ensure that the polylineOptions are properly validated and sanitized before use to prevent potential security issues.
  • 109-121: The modification in the createLeafletObject function to include an options field in the dataset parameter, which is parsed and passed along to the geometry creation function, is correctly implemented. This change supports the PR's objective by enabling the specification of polyline options for polygons directly through the data-options attribute. It's crucial to ensure that the parsedOptions are properly validated and sanitized to prevent potential security issues related to the parsing of user-supplied data.
src/Geometry/test/hyperleaflet-geometry-handler.test.js (1)
  • 124-139: The addition of a test case to verify the creation of a Leaflet polygon object with polyline options is correctly implemented. This test case effectively validates the new functionality introduced by the PR, ensuring that polyline options are correctly applied to the created polygon. It's important to ensure comprehensive coverage by including tests for various polyline options and edge cases to guarantee robustness.

@andrewgryan andrewgryan changed the title Wire up polyline options for polygon using data-options Wire up polyline options for polygon and linestring using data-options Mar 2, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b08ac00 and 8c7092c.
Files selected for processing (2)
  • src/Geometry/leaflet-geometry.js (3 hunks)
  • src/Geometry/test/hyperleaflet-geometry-handler.test.js (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/Geometry/leaflet-geometry.js
  • src/Geometry/test/hyperleaflet-geometry-handler.test.js

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8c7092c and 8b558a2.
Files selected for processing (4)
  • src/Geometry/hyperleaflet-geometry-handler.js (2 hunks)
  • src/Geometry/index.js (1 hunks)
  • src/Geometry/leaflet-geometry.js (3 hunks)
  • src/Geometry/test/hyperleaflet-geometry-handler.test.js (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/Geometry/leaflet-geometry.js
  • src/Geometry/test/hyperleaflet-geometry-handler.test.js
Additional comments: 3
src/Geometry/index.js (1)
  • 40-40: The addition of 'data-options' to the attributeFilter parameter is a positive change that aligns with the PR's objectives to enhance polygon configuration capabilities. Ensure that the rest of the system, particularly the components that consume the attributeFilter parameter, is updated to handle the new 'data-options' attribute effectively.
src/Geometry/hyperleaflet-geometry-handler.js (2)
  • 30-30: The update to access change['data-id'] directly in the changeNodeInHyperleaflet function simplifies the code and makes it more readable. Ensure that all callers of this function are updated to pass the correct change object structure.
  • 53-58: The refactoring of changeNodesInHyperleaflet to handle an array of changes and a dataset, iterating over partial changes, is a thoughtful improvement. It's crucial to verify the integration and testing of these changes to ensure they work as expected within the broader system context.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8b558a2 and 2be91b1.
Files selected for processing (1)
  • src/Geometry/hyperleaflet-geometry-handler.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/Geometry/hyperleaflet-geometry-handler.js

@andrewgryan
Copy link
Contributor Author

This is ready for a review, some manual testing was performed to understand the shape of the data when updating geometry and options, add/remove and change events were triggered using a simple HTMX app. If I have time I'll add tests to cover them 😄

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2be91b1 and b140408.
Files selected for processing (1)
  • src/Geometry/leaflet-geometry.js (4 hunks)
Additional comments: 1
src/Geometry/leaflet-geometry.js (1)
  • 119-132: The createLeafletObject function parses the options from the dataset and passes them to the createGeometryFn function. While this approach is generally correct, it's important to ensure that the options JSON string is always well-formed and that there's a fallback or error handling mechanism in case of parsing errors. Additionally, the function could benefit from more explicit documentation or type checks to ensure that the dataset parameter conforms to expected structures, especially since it directly influences geometry creation.
  • Verify that the options JSON string is always well-formed across all usages of createLeafletObject.
  • Consider adding error handling for JSON parsing and documenting the expected structure of the dataset parameter.


const createLineGeometry = (parsedGeometry, options) => {
const { reverseOrderAll, reverseOrder } = options;
const { reverseOrderAll, reverseOrder, options: polylineOptions } = options;
Copy link

Choose a reason for hiding this comment

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

The destructuring of options to extract polylineOptions is repeated in both createLineGeometry and createPolygonGeometry. This repetition could be reduced by refactoring the common logic into a utility function or by ensuring that the options object is structured appropriately before being passed to these functions.

Consider refactoring the common logic for handling options to improve code maintainability and reduce repetition.

Comment on lines 136 to 142
console.log(change);
switch (change.attribute) {
case 'data-geometry': {
return changeGeometry(leafletObject, change);
}
case 'data-options': {
return changeOptions(leafletObject, change);
}
Copy link

Choose a reason for hiding this comment

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

The changeLeafletObject function uses a console.log statement to log the change parameter. While logging can be useful for debugging, it's generally not advisable to leave such statements in production code, as it can clutter the console output and potentially leak sensitive information.

  • Remove the console.log(change); statement or replace it with a more controlled logging mechanism that can be enabled or disabled based on the environment.
- console.log(change);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
console.log(change);
switch (change.attribute) {
case 'data-geometry': {
return changeGeometry(leafletObject, change);
}
case 'data-options': {
return changeOptions(leafletObject, change);
}
switch (change.attribute) {
case 'data-geometry': {
return changeGeometry(leafletObject, change);
}
case 'data-options': {
return changeOptions(leafletObject, change);
}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b140408 and 0cdca3d.
Files selected for processing (1)
  • src/Geometry/leaflet-geometry.js (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/Geometry/leaflet-geometry.js

@andrewgryan
Copy link
Contributor Author

@cemrehancavdar have you got time to review this? I drafted it during a recent hack session but I think it patches in some missing functionality in a reasonable system JS way. But because it was a hastily developed patch there may be design patterns that I've overlooked.

@cemrehancavdar
Copy link
Owner

cemrehancavdar commented Mar 23, 2024

Thank you for this PR!
It was crazy busy month for me in a good way tho :)
I think it is okay to have options like this, can you document this behaviour? After it i'll merge it 🪴
@andrewgryan

@andrewgryan
Copy link
Contributor Author

Also having a crazy busy month, will tidy this one up soon hopefully!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0319474 and 67890a3.
Files selected for processing (5)
  • src/Geometry/hyperleaflet-geometry-handler.js (2 hunks)
  • src/Geometry/index.js (1 hunks)
  • src/Geometry/leaflet-geometry.js (4 hunks)
  • src/Geometry/test/geometry-object-handler.test.js (1 hunks)
  • src/Geometry/test/hyperleaflet-geometry-handler.test.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/Geometry/test/geometry-object-handler.test.js
Additional comments not posted (4)
src/Geometry/index.js (1)

40-40: Ensure that downstream functions properly handle the 'data-options' attribute.

Verification successful

The addition of 'data-options' to the attributeFilter in src/Geometry/index.js is supported by the codebase, with evidence of handling and testing for this attribute in both src/Geometry/leaflet-geometry.js and src/Geometry/test/hyperleaflet-geometry-handler.test.js. This suggests that downstream functions are prepared to properly handle the 'data-options' attribute.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that 'data-options' is correctly processed in downstream functions.
rg --type js "data-options"

Length of output: 254

src/Geometry/hyperleaflet-geometry-handler.js (2)

30-30: Verify that the new method of accessing rowId directly from change is compatible with all expected change formats.

Verification successful

The method of accessing rowId directly from change using change['data-id'] is compatible with all expected change formats, as evidenced by the widespread use of 'data-id' across the project, including in test cases. This suggests that the change is consistent with the project's data handling practices and does not introduce compatibility issues.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the new access method for `rowId` does not break existing functionality.
rg --type js "data-id"

Length of output: 12946


53-63: Ensure that the structured handling of changes in changeNodesInHyperleaflet is thoroughly tested with various change formats.

src/Geometry/test/hyperleaflet-geometry-handler.test.js (1)

124-174: Ensure the new test cases for handling options in polygon and polyline objects are comprehensive and cover edge cases.

Consider adding more tests to cover edge cases and ensure robustness of the new functionalities.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 67890a3 and a9ba3ee.
Files selected for processing (1)
  • docs/docs/usage.md (1 hunks)
Files not reviewed due to errors (1)
  • docs/usage.md (no review received)

@andrewgryan
Copy link
Contributor Author

@cemrehancavdar I've added in some docs to cover the extension to allow data-options and data-icon support. Let me know if that matches your vision for this library. My brief experience with it, is it's an excellent idea which makes simple map applications hypermedia compatible 😄

Copy link

Quality Gate Passed Quality Gate passed

Issues
2 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Comment on lines +178 to +183
`#!css data-options`
: Specifies Polyline and Polygon options. See Leaflet documentation for [Polyline options](https://leafletjs.com/reference.html#polyline-option) and [Polygon options](https://leafletjs.com/reference.html#polygon). <br>
```html
<span ... data-options='{"color": "red", "weight": 1, "opacity": 0.8}'></span>
```
Valid format: JSON representing options compatible with L.polyline and L.polygon leaflet methods.
Copy link

Choose a reason for hiding this comment

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

Ensure consistency in the presentation of JSON data in documentation.

The JSON data in the data-options attribute example is not formatted consistently with other similar examples in the document. Consider formatting it with proper indentation to improve readability and maintain consistency across the documentation.

- <span ... data-options='{"color": "red", "weight": 1, "opacity": 0.8}'></span>
+ <span ... data-options='{ "color": "red", "weight": 1, "opacity": 0.8 }'></span>

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
`#!css data-options`
: Specifies Polyline and Polygon options. See Leaflet documentation for [Polyline options](https://leafletjs.com/reference.html#polyline-option) and [Polygon options](https://leafletjs.com/reference.html#polygon). <br>
```html
<span ... data-options='{"color": "red", "weight": 1, "opacity": 0.8}'></span>
```
Valid format: JSON representing options compatible with L.polyline and L.polygon leaflet methods.
`#!css data-options`
: Specifies Polyline and Polygon options. See Leaflet documentation for [Polyline options](https://leafletjs.com/reference.html#polyline-option) and [Polygon options](https://leafletjs.com/reference.html#polygon). <br>
```html
<span ... data-options='{ "color": "red", "weight": 1, "opacity": 0.8 }'></span>

Valid format: JSON representing options compatible with L.polyline and L.polygon leaflet methods.


</details>
<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

Comment on lines +34 to +37
const { reverseOrderAll, reverseOrder, options: polylineOptions } = options;
const isLonLat = reverseOrderAll || reverseOrder !== undefined;
const geometry = isLonLat ? GeoJSON.coordsToLatLngs(parsedGeometry, 0) : parsedGeometry;
const leafletGeometry = polyline(geometry);
const leafletGeometry = polyline(geometry, polylineOptions);
Copy link

Choose a reason for hiding this comment

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

Refactor the handling of polyline options to reduce code duplication between line and polygon geometries.

- const { reverseOrderAll, reverseOrder, options: polylineOptions } = options;
+ const { reverseOrderAll, reverseOrder, polylineOptions } = extractPolylineOptions(options);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const { reverseOrderAll, reverseOrder, options: polylineOptions } = options;
const isLonLat = reverseOrderAll || reverseOrder !== undefined;
const geometry = isLonLat ? GeoJSON.coordsToLatLngs(parsedGeometry, 0) : parsedGeometry;
const leafletGeometry = polyline(geometry);
const leafletGeometry = polyline(geometry, polylineOptions);
const { reverseOrderAll, reverseOrder, polylineOptions } = extractPolylineOptions(options);
const isLonLat = reverseOrderAll || reverseOrder !== undefined;
const geometry = isLonLat ? GeoJSON.coordsToLatLngs(parsedGeometry, 0) : parsedGeometry;
const leafletGeometry = polyline(geometry, polylineOptions);

Comment on lines +113 to +116
function changeOptions(leafletObject, change) {
const { to: options } = change;
return leafletObject.setStyle(JSON.parse(options));
}
Copy link

Choose a reason for hiding this comment

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

Refine the implementation of changeOptions to include error handling for JSON parsing and ensure compatibility of options with setStyle.

function changeOptions(leafletObject, change) {
  const { to: options } = change;
+ try {
+   const parsedOptions = JSON.parse(options);
+   return leafletObject.setStyle(parsedOptions);
+ } catch (error) {
+   console.error('Failed to parse options:', error);
+   return leafletObject; // Or handle the error as appropriate
+ }
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
function changeOptions(leafletObject, change) {
const { to: options } = change;
return leafletObject.setStyle(JSON.parse(options));
}
function changeOptions(leafletObject, change) {
const { to: options } = change;
try {
const parsedOptions = JSON.parse(options);
return leafletObject.setStyle(parsedOptions);
} catch (error) {
console.error('Failed to parse options:', error);
return leafletObject; // Or handle the error as appropriate
}
}

@cemrehancavdar
Copy link
Owner

It seems tracking coordinate and options change won't work right now. I'll dig in to it

@andrewgryan
Copy link
Contributor Author

I may have broken the update handler to support swapping out a DOM element with the same data-id. I reckon a few tests to cover the various combinations of updates might help isolate the problem.

At the moment I'm writing index.html files elsewhere on my file system to check the behaviour, which isn't ideal.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants