j20mc / Nativescript-Danem-Google-Maps-Utils

Nativescript Google-maps-utils android & IOS
The Unlicense
6 stars 6 forks source link

Cluster click event #1

Closed OniQ closed 4 years ago

OniQ commented 4 years ago

Is would be great to have an event on cluster click. And have data of all markers it contains, if possible.

j20mc commented 4 years ago

Hi, I'm looking at what I can do.

j20mc commented 4 years ago

Version 1.0.10 which will arrive tomorrow will implement the click event on the cluster. To listen to it, you have to go to the onMarkerSelect (). Be careful, if you tap on a marker it returns a marker, if you tap on a cluster it returns an array of markers.

OniQ commented 4 years ago

I tried and it works fine. Thank you!

However there is seems to be no userData from the original marker. My workaround is to get original marker by position. But it would be nice to have this data directly in this event.

j20mc commented 4 years ago

Hi, now it should have userData in the marker array (android & iOS). (version : 1.0.11)

OniQ commented 4 years ago

Hi, I've tested it and it seems to work only for strings. I can't access my assigned object.

j20mc commented 4 years ago

By parsing it at the exit it does not work? Is this a javascript object?

OniQ commented 4 years ago

I was not able to parse it, because I get object of type NSString. I use typescript and assign data to original marker like this:

const marker: Marker = new Marker();

marker.userData = {
    id: m.id,
    icon: m.iconCode
 };
j20mc commented 4 years ago

Ok, I'll look, is the iOS side more the problem?

OniQ commented 4 years ago

I've tested only on iOS for now.

j20mc commented 4 years ago

Ok i would look to see what's wrong.

j20mc commented 4 years ago

The problem is that on the iOS part, apparently the marshalling ios is not done correctly, normally we should have a string [] but instead we have NSString[]. For now, to find a string done:

JSON.stringify ("" + marker.userData)

it is not ideal but at least you have the possibility of working on the data. I will see later for the problem.

j20mc commented 4 years ago

Did this workaround help you?

OniQ commented 4 years ago

No, it's not. Data from marker.userData is not a valid json. But I have my own workaround for now. It was enough to pass single id field.

j20mc commented 4 years ago

Precisely I had taken your code

{ id: m.id, icon: m.iconCode }

and with this : JSON.stringify ("" + marker.userData) do not forget the "" +which allows to have a valid json after a parse. I was able to access the json with the values ​​id and icons

OniQ commented 3 years ago

Hello. Can you make this. feature NS7 compatible? Now I get following error: NativeScript encountered a fatal error: Uncaught TypeError: Cannot read property 'collections' of undefined