Beispiel #1
0
    public IPromise <List <Site> > GetSites(bool forceRefresh)
    {
        if (forceRefresh || _sitesPromise == null)
        {
            _sitesPromise = _steelConnect.GetSitesInOrg()
                            .Then(items => {
                _sites = new List <Site>(items.items);
                return(_sites);
            })
                            .ThenAll(sites => {
                // Get coordinates for each site.
                return(sites.Select(site => LatLongUtility.GetLatLongForAddress(site.street_address, site.city, site.country)));
            })
                            .Then(latLongs => {
                // We now have an IEnumerable called latLongs (think of it like a list) that has elements of LatLong.
                // Each element of latLongs corresponds to the site in _sites with the same index.
                // We use this fact to link sites to their LatLongs.
                for (int i = 0; i < _sites.Count; ++i)
                {
                    _sites[i].coordinates = latLongs.ElementAt(i);
                }

                return(_sites);
            });
        }

        return(_sitesPromise);
    }
Beispiel #2
0
    public SiteMarker placeSiteMarker(Site site, LatLong latLong)
    {
        Vector3 sitePosition = LatLongUtility.LatLongToCartesian(latLong, globeRadius);

        // We want the site marker's up to face outwards. If we just use Quaternion.LookRotation
        // directly and just specify the forward vector, the marker's forward will face outwards.
        // So we need to rotate it so its up faces forward first.
        Quaternion upToForward     = Quaternion.Euler(90.0f, 0.0f, 0.0f);
        Quaternion siteOrientation = Quaternion.LookRotation(sitePosition.normalized) * upToForward;

        Debug.Log($"GLOBE: Site {site.id} is at world position {sitePosition}");

        GameObject newSiteMarkerObject = Instantiate(siteMarkerPrefab, sitePosition, siteOrientation, this.transform);
        SiteMarker newSiteMarker       = newSiteMarkerObject.GetComponent <SiteMarker>();

        newSiteMarker.site = site;

        return(newSiteMarker);
    }