Skip to content
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

Add support for MVCArray for polyline #169

Closed
lombardk opened this issue Jan 11, 2022 · 5 comments
Closed

Add support for MVCArray for polyline #169

lombardk opened this issue Jan 11, 2022 · 5 comments

Comments

@lombardk
Copy link

We use BlazorGoogleMaps in a vehicle tracking solution. New locations are thus periodically added to the polylines. Currently we set the whole path again which may impact on performance.

Google recommends to obtain the existing path and then just to push the new latLng points:
https://developers.google.com/maps/documentation/javascript/examples/polyline-complex
// Handles click events on a map, and adds a new point to the Polyline.
function addLatLng(event: google.maps.MapMouseEvent) {
const path = poly.getPath();

// Because path is an MVCArray, we can simply append a new coordinate
// and it will automatically appear.
path.push(event.latLng);
}

BlazorGoogleMaps polyline.GetPath() however returns an IENumerable and not a List, so the new latLng's cannot be added.
Please consider changing GetPath() to return the List of points so that new latLng's can be added.

Thank you.

@valentasm1
Copy link
Collaborator

It is a bit different story. If i return List adding to it wont appear to map automaticlly.
Maybe it would be reasanable to have custom methor where GetPath would create path, add to array and then it would return ObservableCollection, when addded/removed element would access that element from array and then would add/remove element in js from that array. Or even having c# element Path with events add/remove which would work out of the box with solution.
Probable second approuch would allign more with this library.
As you see it is not so simple. I will try to do it this month. If you wish faster you could make PR.

@lombardk
Copy link
Author

lombardk commented Jan 12, 2022 via email

@valentasm1
Copy link
Collaborator

Technically yes. Practically this solution isnt very clean. I try to avoid adding any extra method if possible.

@valentasm1 valentasm1 changed the title Add LatLng points to existing Polyline Add support for MVCArray for polyline Feb 7, 2022
@valentasm1
Copy link
Collaborator

Let me know if it suits you.
I know it is not fully support for MVCArray but good draft to continue futher.
https://github.com/rungwiroon/BlazorGoogleMaps/releases/tag/1.5.1

@valentasm1
Copy link
Collaborator

Call CreatePath for polyline and then use returned object as in JS

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

No branches or pull requests

2 participants