Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Attaching GameObjects to the map

Brian Kircher edited this page Apr 9, 2019 · 8 revisions

The MapPin component can be added to GameObjects which you want to attach to the MapRenderer at a specific lat-lon. When attached, the MapRenderer will take over management of the MapPin GameObject's transform.

There are two approaches that can be used to attach a MapPin to a MapRenderer. Both approaches are used in the demo scene.

Adding a child MapPin to the MapRenderer

The first approach is simply adding a child GameObject to the MapRenderer where this GameObject has a MapPin component. The MapRenderer detects any immediate child MapPin component and will takeover positioning the GameObject based on it's lat long.

This approach is good if you just have a few unique objects that need to be pinned to the map.

Using the MapPinLayer

This approach is better suited for large data sets where clustering may be required:

  • Add a MapPinLayer component to the MapRenderer's GameObject. If clustering is enabled, check this setting on the layer and attach a prefab that has a ClusterMapPin component.

  • In a script, get a reference to the MapPinLayer and add MapPin instances to the the layer's MapPins collection.

Clustering

An advantage to using the MapPinLayer is that it supports clustering. If a ClusterMapPin prefab is specified on the layer, MapPins will be clustered automatically. When MapPins are clustered, the ClusterMapPin is shown in the place of the many MapPins that associate to it.

Clustering is highly recommended for large datasets as this will reduce the number of MapPin instances that need to be rendered for zoomed out views. Besides this rendering performance benefit, it is often preferable to cluster MapPins from a usability perspective since dense, cluttered views will make it more difficult for the user to interact with individual MapPins.

Clusters are created at every zoom level, so as the zoom level of the MapRenderer changes, the visible clusters and MapPins may change as well.

A note on performance

Creating and adding many MapPins at once, either to a MapPinLayer or as children of the MapRenderer, could be time consuming and thus cause a frame hitch. If the MapPins can be initialized and added all at startup, this may be an acceptable one time hit. However, if data is being streamed and converted to MapPins throughout the app's lifetime, consider spreading out the MapPin creation and addition over multiple frames, i.e. time slice the additions. This will help to maintain render performance.


Clone this wiki locally