<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Zoom To Cluster]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1038&amp;type=atom" />
	<updated>2019-02-27T09:03:47Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1038</id>
		<entry>
			<title type="html"><![CDATA[Re: Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4595#p4595" />
			<content type="html"><![CDATA[<p>There can be many effects that are easy to implement.<br />For example, scale down / scale up markers.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2019-02-27T09:03:47Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4595#p4595</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4594#p4594" />
			<content type="html"><![CDATA[<p>Ok. Thought it might be too difficult. Any ideas for some kind of transition effect??</p>]]></content>
			<author>
				<name><![CDATA[adriantaylor]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=903</uri>
			</author>
			<updated>2019-02-26T20:10:25Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4594#p4594</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4593#p4593" />
			<content type="html"><![CDATA[<p>Unfortunately, with this script you cannot do this.<br />In this world, nothing is impossible, but it requires such changes that in fact it will be a new script.<br />Of course, you can try, but it will be very difficult. <br />So I recommend you to think about some other effect.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2019-02-26T20:03:08Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4593#p4593</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4590#p4590" />
			<content type="html"><![CDATA[<p>Awesome, thanks for that. </p><p>Another question: how would I go about animating the markers position as they transition from a marker into a cluster group? </p><p>For example if at zoom level 10 I have 2 markers on screen and at zoom level 11 I have one cluster group which contains the two markers, how can I animate the markers so they look like they are “flying” from their position into the cluster group’s position?</p><p>I would like to do the reverse too if that possible. </p><p>Any direction you can give me on that would be hugely appreciated!!</p><p>Thanks again for your help so far</p>]]></content>
			<author>
				<name><![CDATA[adriantaylor]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=903</uri>
			</author>
			<updated>2019-02-26T18:24:16Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4590#p4590</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4587#p4587" />
			<content type="html"><![CDATA[<p>This script is for Online Maps v2, so I thought that you are using the old version.<br />In this case, use:<br /></p><div class="codebox"><pre><code>OnlineMaps.instance.projection.TileToCoordinates(subCluster.mx.Value, subCluster.my.Value, 0, out lng, out lat);</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2019-02-26T09:14:55Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4587#p4587</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4586#p4586" />
			<content type="html"><![CDATA[<p>Thanks for the quick reply...</p><p>I&#039;m getting an error that theres no MercatToLatLong function in the Utils class... I just updated to latest stable release (3.0.0.33) but doesn&#039;t help</p>]]></content>
			<author>
				<name><![CDATA[adriantaylor]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=903</uri>
			</author>
			<updated>2019-02-26T01:23:04Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4586#p4586</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4585#p4585" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Out of the box, this script cannot do this.<br />But you can easily add it, for example like this:</p><div class="codebox"><pre><code>// ...
public class Clustering2DMarkers : MonoBehaviour
{
    public static Action&lt;Cluster, OnlineMapsMarker&gt; OnCreateInstance;
    // ...
    public class Cluster : ClusterItem
    {
        // ...
        private void TryGetMarkers(int z, double tlx, double tly, double brx, double bry, ref List&lt;OnlineMapsMarker&gt; markers)
        {
            if (zoom &lt; z)
            {
                for (int i = 0; i &lt; count; i++) childs[i].GetMarkers(z, tlx, tly, brx, bry, ref markers);
            }
            else
            {
                if (markerRef == null)
                {
                    UpdatePosition();

                    markerRef = new OnlineMapsMarker();
                    markerRef.SetPosition(longitude, latitude);
                    markerRef.texture = instance.groupTexture;
                    markerRef.label = &quot;Group (childs: &quot; + totalCount + &quot;)&quot;;

                    if (OnCreateInstance != null) OnCreateInstance(this, markerRef);

                    markerRef.Init();
                }

                markers.Add(markerRef);
            }
        }
        // ...
    }
    // ...
}</code></pre></div><div class="codebox"><pre><code>using UnityEngine;
using System.Collections.Generic;

public class ZoomOnCluster : MonoBehaviour
{
    public int countMarkers = 50000;
    public Texture2D texture;

    private void GenerateMarkers()
    {
        Clustering2DMarkers.OnCreateInstance += OnCreateInstance;

        for (int i = 0; i &lt; countMarkers; i++)
        {
            double longitude = Random.Range(-180f, 180f);
            double latitude = Random.Range(-90f, 90f);

            OnlineMapsMarker marker = new OnlineMapsMarker();
            marker.SetPosition(longitude, latitude);
            marker.label = &quot;Marker &quot; + i;
            marker.texture = texture;
            marker.Init();
            marker.OnPositionChanged += delegate (OnlineMapsMarkerBase m)
            {
                Debug.Log(&quot;Position Changed&quot;);
                Clustering2DMarkers.UpdateMarkerPosition(m as OnlineMapsMarker);
            };

            Clustering2DMarkers.Add(marker);
        }

        Clustering2DMarkers.UpdatePositions();
    }

    private void OnCreateInstance(Clustering2DMarkers.Cluster cluster, OnlineMapsMarker marker)
    {
        marker.OnClick += m =&gt;
        {
            var cc = cluster;
            while (cc.count == 1)
            {
                cc = cc.childs[0] as Clustering2DMarkers.Cluster;
            }

            List&lt;Vector2&gt; points = new List&lt;Vector2&gt;();
            for (int i = 0; i &lt; cc.count; i++)
            {
                var child = cc.childs[i];
                var subCluster = child as Clustering2DMarkers.Cluster;
                if (subCluster != null)
                {
                    double lng, lat;
                    OnlineMapsUtils.MercatToLatLong(subCluster.mx.Value, subCluster.my.Value, out lng, out lat);
                    points.Add(new Vector2((float)lng, (float)lat));
                }
                else points.Add(child.markerRef.position);
            }

            Vector2 center;
            int zoom;
            OnlineMapsUtils.GetCenterPointAndZoom(points.ToArray(), out center, out zoom);
            OnlineMaps.instance.SetPositionAndZoom(center.x, center.y, zoom - 1);
        };
    }

    private void Start()
    {
        GenerateMarkers();
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2019-02-25T23:27:44Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4585#p4585</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Zoom To Cluster]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4584#p4584" />
			<content type="html"><![CDATA[<p>Hi there, </p><p>I&#039;m using the Clustering2DMarkers script that was posted in another thread and it works great.</p><p>I&#039;m now trying to implement the following functionality:</p><p>-&gt; Click on a cluster marker<br />-&gt; Center and zoom the map to the ClusterItem&#039;s child markers</p><p>You can see an example of the effect that I&#039;m trying to achieve here:<br /><a href="https://developers.google.com/maps/documentation/javascript/marker-clustering">https://developers.google.com/maps/docu … clustering</a></p><p>When you click on a cluster, it zooms to the &quot;extents&quot; of the cluster&#039;s children.</p><p>I&#039;m having trouble getting the correct array of positions to calculate the zoom and center values... I can&#039;t figure out how to recursively get all the individual marker positions which make up a cluster.</p><p>Can anyone help??</p>]]></content>
			<author>
				<name><![CDATA[adriantaylor]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=903</uri>
			</author>
			<updated>2019-02-25T22:31:35Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4584#p4584</id>
		</entry>
</feed>
