pubnub / eon-map

Realtime maps with PubNub and MapBox.
https://www.pubnub.com/developers/eon/
MIT License
135 stars 51 forks source link

Change marker (pop-up / color) based on event #17

Closed matthijsphilip closed 7 years ago

matthijsphilip commented 7 years ago

Hi,

I have the following use case:

So far I've succesfully got the map up, and get the markers to show / remove themselves whenever someone logs in or out. The markers also have a little pop-up displaying information about the remote source. All is well here.

What I can't get to work though, is updating properties other than the latlng / position of a marker. I would love to be able to change things like the pop-up, and optionally the marker color or icon.

It appears that the "message" function of the map is called each time an event is published from a remote source, but the "marker" function is not. And it appears that I can only set a custom icon and pop-up in the "marker" function. I don't know how to access the markers properties itself such as the icon, color and pop-up from within the "message" function.

How can I access the properties of the marker that the "message" belongs to so I can customise the marker based on data in the event that I receive? Is that possible?

Lastly it would also be nice if I could somehow "timeout" markers when they don't receive events for e.g. 10 minutes or longer.

Hope you guys are still developing on the EON map and could provide me some pointers here! Thanks a bunch.

Matthijs

ianjennings commented 7 years ago

Hey Matthijs. The markers are powered by Leaflet wrapped around Mapbox. You can access the markers in the marker callback exposed by eon.

https://github.com/pubnub/eon-map#marker-customization

This example shows how to change a marker color on click.

https://www.mapbox.com/mapbox.js/example/v1.0.0/change-marker-color-click/

matthijsphilip commented 7 years ago

Hi Ian,

Thanks for the reply; probably to insufficient programming skills I'm still unable to change a marker's color based on incoming pubnub messages for markers that are already there on a map.

What I can do is publish markers with different colors, but I would like to change an already present marker's color based on a remote event.

Is there a way to access the markers already rendered on the eon map from the message callback function, or can I somehow access the MapBox featureLayer the eon map uses so I can iterate over the markers that are already there? The mapbox example you send doesn't help me much; the layer being added is from local code and not from a distributed (remote) event.

The use case is as follows:

I have a TV screen displaying the EON map in my office.

A remote worker opens a webpage on a tablet that publishes / broadcasts its location: this results in a blue marker on the map. I of course got this to work; that's simple.

The remote worker submits a form, I than publish another event with a different status. I would like that event to change the marker's color (already on my map) from blue to green.

Finally the remote worker logs out: its marker is then removed: I can get this to work too.

Is there some example somewhere that changes a L.marker property based on code in the "message" callback? I tried supplying code in the "marker" callback, but that doesn't re-render the markers when I broadcast a different status.

Hope you can follow me and in your kindness can help me again.. :-D I wish there was more documentation or examples out there, but can't seem to find many others using the eon-map in this way.