Exemple #1
0
        /// <summary>
        /// Gets the pins in the specified bounding box.
        /// </summary>
        internal void GetPinsInView(
            MercatorBoundingBox mercatorBox,
            float levelOfDetail,
            ClusterMapPin clusterMapPinPrefab,
            Transform parentTransform,
            out List <MapPin> mapPins,
            out List <ClusterMapPin> clusterMapPins)
        {
            var box         = mercatorBox.ToGeoBoundingBox();
            var lod         = (short)Mathf.Min(Mathf.Round(levelOfDetail), _maxLod.Value);
            var tileLod     = new TileLevelOfDetail(lod);
            var tileLodData = _tiledSpatialIndex[lod - 1];
            var tiles       = TileOperations.GetCoveredTileIds(box, tileLod);

            mapPins        = new List <MapPin>();
            clusterMapPins = new List <ClusterMapPin>();

            foreach (var tile in tiles)
            {
                var tileBounds = tile.ToMercatorBoundingBox();
                var isTileCompletelyInsideMap = mercatorBox.Contains(tileBounds);

                if (tileLodData.TryGetValue(tile.Value, out var tileData))
                {
                    if (tileData.IsClustered())
                    {
                        var latLon = new LatLon(tileData.TotalLat / tileData.MapPinCount, tileData.TotalLon / tileData.MapPinCount);
                        if (isTileCompletelyInsideMap || box.Intersects(latLon))
                        {
                            // Use the ClusterMapPin.
                            if (tileData.ClusterMapPin == null)
                            {
                                // Deactivate the GO to start with. It will get activated once elevation has been sampled and it's in view.
                                clusterMapPinPrefab.gameObject.SetActive(false);
                                var newClusterMapPin = UnityEngine.Object.Instantiate(clusterMapPinPrefab);

                                if (parentTransform != null)
                                {
                                    newClusterMapPin.transform.SetParent(parentTransform, false);
                                }
                                newClusterMapPin.LevelOfDetail = tileLod.Value;
                                tileData.ClusterMapPin         = newClusterMapPin;

                                _clusterMapPins.Add(newClusterMapPin);
                            }

                            tileData.ClusterMapPin.Size     = tileData.MapPinCount;
                            tileData.ClusterMapPin.Location = new LatLon(latLon.LatitudeInDegrees, latLon.LongitudeInDegrees);
                            clusterMapPins.Add(tileData.ClusterMapPin);
                        }
                    }
                    else
                    {
                        // Add all of the MapPins in this tile to the list.
                        if (isTileCompletelyInsideMap)
                        {
                            foreach (var mapPin in tileData.MapPins)
                            {
                                mapPins.Add(mapPin);
                            }
                        }
                        else
                        {
                            foreach (var mapPin in tileData.MapPins)
                            {
                                if (box.Intersects(mapPin.Location))
                                {
                                    mapPins.Add(mapPin);
                                }
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Constructs a <see cref="MapSceneOfBoundingBox"/> from the specified <see cref="MercatorBoundingBox"/>.
 /// </summary>
 public MapSceneOfBoundingBox(MercatorBoundingBox boundingBox) :
     this(boundingBox.ToGeoBoundingBox())
 {
 }