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 polygoncomplete event in Drawing Manager #148

Closed
Mr-Technician opened this issue Sep 16, 2021 · 11 comments
Closed

Add support for polygoncomplete event in Drawing Manager #148

Mr-Technician opened this issue Sep 16, 2021 · 11 comments

Comments

@Mr-Technician
Copy link

Currently, the only supported event for the DrawingManager is overlaycomplete.

I am proposing that polygoncomplete support be added to DrawingManager:
https://developers.google.com/maps/documentation/javascript/reference/drawing#DrawingManager.polygoncomplete

This would be useful as it would allow users to directly manipulate the Polygon instead of only getting the lat/lng list. I think support is mostly there, only there is no public constructor for Polygon:

private Polygon(JsObjectRef jsObjectRef, PolygonOptions opts = null)

This leads to this error when using the polygoncomplete event:
image

@Mr-Technician
Copy link
Author

It looks like this would entail saving the resulting Polygon to the array of maps objects and then returning its Guid index. This would allow interacting with drawing manager polygons like they were created manually.

@valentasm1
Copy link
Collaborator

I will take a look on sunday.

@valentasm1
Copy link
Collaborator

It is not that simple. Polygon is like proxy for js object and dont have ANY properties. In this case it return polygon with it properties, so deserialise to polygon it is impossible since first it dont existist in _blazorGoogleMapsObjects and second Polygon object dont have any propertys, so it would need other object.
So solution would be have some local Polygon with properties and the pass it like this and it should serialize automatically.

await drawingManager.AddListener<MyPolygon>("polygoncomplete", (arg) =>
{	
	Console.WriteLine(arg);
});

@valentasm1
Copy link
Collaborator

For this library maybe it would make sense have PolygonDto with properties in such case, but then having MyPolygon wont have abilities to have add path or change properties on map.
So other option would have action just to add Polygon to _blazorGoogleMapsObjects. Dont know how to do it since i would need to experiment and find working solution.
So will take a look next weekend. If i will be lucky maybe in middle of the week

@valentasm1
Copy link
Collaborator

I think you could create protected constructor, then create custom js even where it set object to _blazorGoogleMapsObjects and returns id (guid), then create JsObjectRef and pass it to new Polygon class via custom factory method and then to constructor.
It is kinda note for me or guidelines for you (if you wish create PR by yourself)

@Mr-Technician
Copy link
Author

Thanks for looking at this! I may PR if I have the time, possibly this week, otherwise if you are able to add this it would be much appreciated!

@Mr-Technician
Copy link
Author

Looking more closely at what you said above, I think we're on the same page. The Polygon object is a proxy, like you said, and you need to call into JS to get any of its properties. Since the polygoncomplete event returns a polygon, you could save that to the _blazorGoogleMapsObjects list and then return a Polygon from the event. Easy enough in theory. I'd need to study the JS further to be more confident.

@valentasm1
Copy link
Collaborator

No. You dont need to return polygon. You need to add and return id. Then create polygon with that in via Polygon constructor on C# side with that Id (JsObjectRef ). Just looks how polygon is created via private constructor. I think issue here how call c# from js side. Not sure if same event pattern will work

@Mr-Technician
Copy link
Author

By return I mean the event would return polygon on the C# side. I realize that the event would just return the ID on the JS side.

@valentasm1
Copy link
Collaborator

https://www.nuget.org/packages/BlazorGoogleMaps/1.1.7

@Mr-Technician
Copy link
Author

You're a legend!

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