public override void UpdateContent()
    {
        bounds = map.MapCoordBounds;

        if (degrees)
        {
            UpdateProjectionValues();
        }
        else
        {
            // Convert Lon/Lat to meters
            var meters = GeoCalculator.LonLatToMeters(bounds.east, bounds.north);
            bounds.east  = meters.x;
            bounds.north = meters.y;
            meters       = GeoCalculator.LonLatToMeters(bounds.west, bounds.south);
            bounds.west  = meters.x;
            bounds.south = meters.y;
        }

        var invBoundsX = 1.0 / (bounds.east - bounds.west);
        var invBoundsY = 1.0 / (bounds.north - bounds.south);
        var interval   = new Vector4((float)(intervalX * invBoundsX), (float)(intervalY * invBoundsY), 0, 0);
        var offsetX    = (float)(((0.5f * (bounds.east + bounds.west)) % intervalX) * invBoundsX);
        var offsetY    = (float)(((0.5f * (bounds.north + bounds.south)) % intervalY) * invBoundsY);
        var offset     = new Vector4(offsetX, offsetY, 0, 0);

        if (degrees)
        {
            offset.y = -offset.y;
        }

        material.SetVector("Interval", interval);
        material.SetVector("Offset", offset);
    }
Example #2
0
    private void UpdateCenter(double lon, double lat)
    {
        // Wrap coordinate
        while (lon < GeoCalculator.MinLongitude)
        {
            lon += 2 * GeoCalculator.MaxLongitude;
        }
        while (lon > GeoCalculator.MaxLongitude)
        {
            lon += 2 * GeoCalculator.MinLongitude;
        }
        while (lat < GeoCalculator.MinLatitude)
        {
            lat += 2 * GeoCalculator.MaxLatitude;
        }
        while (lat > GeoCalculator.MaxLatitude)
        {
            lat += 2 * GeoCalculator.MinLatitude;
        }

        // Update lon/lat location
        longitude     = lon;
        latitude      = lat;
        currentMeters = GeoCalculator.LonLatToMeters(longitude, latitude);
    }
    private static Coordinate CalcActiveSiteCenter()
    {
        var bounds = GetActiveSiteAreaBounds();
        var max    = GeoCalculator.LonLatToMeters(bounds.east, bounds.north);
        var min    = GeoCalculator.LonLatToMeters(bounds.west, bounds.south);
        var center = GeoCalculator.MetersToLonLat((min.x + max.x) * 0.5, (min.y + max.y) * 0.5);

        return(center);
    }
Example #4
0
    //
    // Private/Protected Methods
    //

    protected void UpdateAreaCenterAndSize(double north, double east, double south, double west)
    {
        var max = GeoCalculator.LonLatToMeters(east, north);
        var min = GeoCalculator.LonLatToMeters(west, south);

        areaCenterInMeters = (min + max) * 0.5;
        areaSizeInMeters   = max - min;

        UpdateContent();
    }
Example #5
0
    void OnGUI()
    {
        GUILayout.Label("Absolute longitude/latitude to meters", EditorStyles.boldLabel);
        ShowLonLatFields(ref all2mX, ref all2mY);
        ShowResultMeters(GeoCalculator.LonLatToMeters(all2mX, all2mY));

        EditorGUILayout.Space();

        GUILayout.Label("Absolute meters to longitude/latitude", EditorStyles.boldLabel);
        m2llX = EditorGUILayout.FloatField("Meters X", m2llX);
        m2llY = EditorGUILayout.FloatField("Meters Y", m2llY);
        ShowResultLonLat(GeoCalculator.MetersToLonLat(m2llX, m2llX));

        EditorGUILayout.Space();

        GUILayout.Label("Absolute pixels to meters", EditorStyles.boldLabel);
        ShowPixelFields(ref ap2mX, ref ap2mY, ref ap2mZ);
        ShowResultMeters(GeoCalculator.AbsolutePixelsToMeters(ap2mX, ap2mY, ap2mZ));

        EditorGUILayout.Space();

        GUILayout.Label("Relative pixels to meters", EditorStyles.boldLabel);
        ShowPixelFields(ref rp2mX, ref rp2mY, ref rp2mZ);
        ShowResultMeters(GeoCalculator.RelativePixelsToMeters(rp2mX, rp2mY, rp2mZ));

        EditorGUILayout.Space();

        GUILayout.Label("Absolute meters to pixels", EditorStyles.boldLabel);
        ShowMeterFields(ref am2pX, ref am2pY, ref am2pZ);
        ShowResultPixels(GeoCalculator.AbsoluteMetersToPixels(am2pX, am2pY, am2pZ));

        EditorGUILayout.Space();

        GUILayout.Label("Relative meters to pixels", EditorStyles.boldLabel);
        ShowMeterFields(ref rm2pX, ref rm2pY, ref rm2pZ);
        ShowResultPixels(GeoCalculator.RelativeMetersToPixels(rm2pX, rm2pY, rm2pZ));

        EditorGUILayout.Space();

        GUILayout.Label("Absolute longitude/latitude to tile", EditorStyles.boldLabel);
        ShowLonLatFields(ref all2tX, ref all2tY, ref all2tZ);
        ShowResultTile(GeoCalculator.AbsoluteCoordinateToTile(all2tX, all2tY, all2tZ));

        EditorGUILayout.Space();

        GUILayout.Label("Absolute tile to longitude/latitude", EditorStyles.boldLabel);
        ShowTileFields(ref at2llX, ref at2llY, ref at2llZ);
        ShowResultLonLat(GeoCalculator.AbsoluteTileToCoordinate(at2llX, at2llY, at2llZ));
    }
Example #6
0
    public override void InitializeValues(int layersCount, Vector2[] boundary)
    {
        var contourGrid = contoursMapLayer.Grid;
        int count       = contourGrid.countX * contourGrid.countY;

        if (contoursMapLayer.ValuesBuffer == null || contoursMapLayer.ValuesBuffer.count != count)
        {
            contoursMapLayer.CreateBuffer();
        }

        int kernelID = boundary == null ? Reset_KID : (excludeCellsWithNoData ? ClipViewArea_Exclude_KID : ClipViewArea_Include_KID);

        int initialValue = excludeCellsWithNoData ? 1 - layersCount : 1;

        // Get kernel thread count
        compute.GetKernelThreadGroupSizes(kernelID, out uint threadsX, out uint threadsY, out uint threadsZ);

        // Calculate threads & groups
        uint threads = threadsX * threadsY * threadsZ;
        int  groups  = (int)((count + threads - 1) / threads);

        // Assign shader variables
        compute.SetBuffer(kernelID, "contourValues", contoursMapLayer.ValuesBuffer);
        compute.SetInt("contourValueCount", count);
        compute.SetInt("initialValue", initialValue);

        if (boundary != null)
        {
            // Calculate scale and offset
            var    metersNW = GeoCalculator.LonLatToMeters(contourGrid.west, contourGrid.north);
            var    metersSE = GeoCalculator.LonLatToMeters(contourGrid.east, contourGrid.south);
            double scaleX   = (metersSE.x - metersNW.x) / contourGrid.countX;
            double scaleY   = (contourGrid.south - contourGrid.north) / contourGrid.countY;
            double offsetX  = metersNW.x + 0.5 * scaleX;
            double offsetY  = contourGrid.north + 0.5 * scaleY;

            compute.SetInt("contourCountX", contourGrid.countX);
            compute.SetVector("offset", new Vector2((float)offsetX, (float)offsetY));
            compute.SetVector("scale", new Vector2((float)scaleX, (float)scaleY));
            for (int i = 0; i < boundary.Length; i++)
            {
                compute.SetVector("pt" + i, boundary[i]);
            }
        }

        compute.Dispatch(kernelID, groups, 1, 1);
        contoursMapLayer.SetGpuChangedValues();
    }
Example #7
0
    private void GoToSite(Site site)
    {
        var bounds = site.bounds;

        if (bounds.east > bounds.west && bounds.north > bounds.south)
        {
            var max    = GeoCalculator.LonLatToMeters(bounds.east, bounds.north);
            var min    = GeoCalculator.LonLatToMeters(bounds.west, bounds.south);
            var center = GeoCalculator.MetersToLonLat((min.x + max.x) * 0.5, (min.y + max.y) * 0.5);

            map.SetCenter(center.Longitude, center.Latitude);
            map.ZoomToBounds(bounds, site != defaultSite);
        }
        else
        {
            map.SetCenter(0, 0);
            map.SetZoom(map.minZoomLevel);
        }
    }
Example #8
0
    public void ZoomToBounds(AreaBounds bounds, bool fit = true)
    {
        Distance meters = GeoCalculator.LonLatToMeters(bounds.east, bounds.north) - GeoCalculator.LonLatToMeters(bounds.west, bounds.south);
        var      rect   = ComponentManager.Instance.Get <MapViewArea>().GetComponent <RectTransform>().rect;

        var    canvas = FindObjectOfType <Canvas>();
        double zoomX  = Math.Log(rect.width * canvas.scaleFactor * GeoCalculator.InitialResolution / meters.x) * InvLogTwo;
        double zoomY  = Math.Log(rect.height * canvas.scaleFactor * GeoCalculator.InitialResolution / meters.y) * InvLogTwo;

        if (fit)
        {
            float zoom = (float)Math.Min(zoomX, zoomY);
            SetZoom(0.1f * Mathf.Floor(zoom * 10));
        }
        else
        {
            float zoom = (float)Math.Max(zoomX, zoomY);
            SetZoom(0.1f * Mathf.Ceil(zoom * 10));
        }
    }
Example #9
0
    public void ShowData(DataLayer dataLayer, RectTransform rt)
    {
        if (delayedHideCoroutine != null)
        {
            StopCoroutine(delayedHideCoroutine);
            delayedHideCoroutine = null;
        }

        transform.position = rt.position;

        currentRow = 0;

        bool allPatchesHaveSameValue = true;

        var patchCount = dataLayer.loadedPatchesInView.Count;

        if (patchCount == 0)
        {
            Add(translator.Get("No Info"), "");
        }
        else
        {
            var firstPatch     = dataLayer.loadedPatchesInView[0];
            var firstPatchData = firstPatch.Data;

            // Size
            double north = firstPatchData.north;
            double south = firstPatchData.south;
            double east  = firstPatchData.east;
            double west  = firstPatchData.west;
            for (int i = 1; i < patchCount; i++)
            {
                var data = dataLayer.loadedPatchesInView[i].Data;
                north = Math.Max(north, data.north);
                south = Math.Min(south, data.south);
                east  = Math.Max(east, data.east);
                west  = Math.Min(west, data.west);
            }
            Add(translator.Get("Extents"), "N  " + north.ToString("0.0000") +
                "\nS  " + south.ToString("0.0000") +
                "\nE  " + east.ToString("0.0000") +
                "\nW  " + west.ToString("0.0000"));

            var size = GeoCalculator.LonLatToMeters(east, north) - GeoCalculator.LonLatToMeters(west, south);
            var unit = "m";
            if (size.x >= 1000 && size.y >= 1000)
            {
                size *= 0.001;
                unit  = "km";
            }
            Add(translator.Get("Size"), size.x.ToString("0.#") + " x " + size.y.ToString("0.#") + " " + unit);

            if (firstPatchData is GridData)
            {
                var firstGridData = firstPatchData as GridData;

                // Resolution
                allPatchesHaveSameValue = true;
                var cellWidth = firstGridData.GetCellWidth();
                for (int i = 1; i < patchCount; i++)
                {
                    var otherCellWidth = (dataLayer.loadedPatchesInView[i].Data as GridData).GetCellWidth();
                    if (Math.Abs(otherCellWidth - cellWidth) > 0.000001f)
                    {
                        allPatchesHaveSameValue = false;
                        break;
                    }
                }
                if (allPatchesHaveSameValue)
                {
                    var resolution = (float)(GeoCalculator.Deg2Meters * cellWidth);
                    unit = "m";
                    if (resolution > 1000)
                    {
                        unit        = "km";
                        resolution *= 0.001f;
                    }

                    int number = Mathf.RoundToInt(resolution);
                    Add(translator.Get("Resolution"), number + " x " + number + " " + unit);
                }
                else
                {
                    AddMultiValue(translator.Get("Resolution"));
                }

                // Units
                if (!firstGridData.IsCategorized)
                {
                    allPatchesHaveSameValue = true;
                    var units = firstGridData.units;
                    for (int i = 1; i < patchCount; i++)
                    {
                        var otherUnits = (dataLayer.loadedPatchesInView[i].Data as GridData).units;
                        if (otherUnits != units)
                        {
                            allPatchesHaveSameValue = false;
                            break;
                        }
                    }
                    if (allPatchesHaveSameValue)
                    {
                        Add(translator.Get("Units"), units);
                    }
                    else
                    {
                        AddMultiValue(translator.Get("Units"));
                    }
                }
            }

            // Year
            allPatchesHaveSameValue = true;
            var year = firstPatch.Year;
            for (int i = 1; i < patchCount; i++)
            {
                var otherYear = dataLayer.loadedPatchesInView[i].Year;
                if (otherYear != year)
                {
                    allPatchesHaveSameValue = false;
                    break;
                }
            }
            if (allPatchesHaveSameValue)
            {
                Add(translator.Get("Year"), year.ToString());
            }
            else
            {
                AddMultiValue(translator.Get("Year"));
            }

            // Records
            HashSet <int> years = new HashSet <int>();
            foreach (var patch in dataLayer.loadedPatchesInView)
            {
                foreach (var recordYear in patch.SiteRecord.layerSite.records.Keys)
                {
                    if (!years.Contains(recordYear))
                    {
                        years.Add(recordYear);
                    }
                }
            }
            if (years.Count > 1)
            {
                List <int> sortedYears = new List <int>(years);
                sortedYears.Sort();

                var records = "";
                foreach (var recordYear in sortedYears)
                {
                    records += recordYear + ", ";
                }
                Add(translator.Get("Records"), records.Remove(records.Length - 2));
            }

            string citationStr = null;

            // Add metadata
            if (firstPatchData.metadata != null)
            {
                foreach (var row in firstPatchData.metadata)
                {
                    allPatchesHaveSameValue = true;
                    var value = row.Value;
                    for (int i = 1; i < patchCount; i++)
                    {
                        var otherValue = dataLayer.loadedPatchesInView[i].Data.metadata.Get(row.Key);
                        if (!otherValue.Equals(value))
                        {
                            allPatchesHaveSameValue = false;
                            break;
                        }
                    }

                    if (row.Key != "Citation" && row.Key != "MandatoryCitation")
                    {
                        if (allPatchesHaveSameValue)
                        {
                            Add(translator.Get(row.Key, false), row.Value);
                        }
                        else
                        {
                            AddMultiValue(translator.Get(row.Key, false));
                        }
                    }

                    // Source/Citation
                    if (row.Key == "Source" && citationStr == null)
                    {
                        if (allPatchesHaveSameValue)
                        {
                            if (citationsManager.TryGet(firstPatch, out Citation citation))
                            {
                                citationStr = citation.text;
                            }
                        }
                        else
                        {
                            AddMultiValue(translator.Get("Citation"));
                        }
                    }
                    else if (row.Key == "Citation")
                    {
                        if (allPatchesHaveSameValue)
                        {
                            citationStr = value;
                        }
                        else
                        {
                            citationStr = AddAllValues(dataLayer, row.Key, value);
                        }
                    }
                    else if (row.Key == "MandatoryCitation" && citationStr == null)
                    {
                        if (allPatchesHaveSameValue)
                        {
                            citationStr = value;
                        }
                        else
                        {
                            citationStr = AddAllValues(dataLayer, row.Key, value);
                        }
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(citationStr))
            {
                Add(translator.Get("Citation"), citationStr);
            }
        }

        // DO NOT DELETE OR CHANGE THIS COMMENT BLOCK
        // The following lines will force the LocalizationManager to export the quoted text:
        // "Source"/*translatable*/
        // "Layer Name"/*translatable*/

        // Hide remaining rows
        for (int i = infoRows.Count - 1; i >= currentRow; i--)
        {
            infoRows[i].key.gameObject.SetActive(false);
            infoRows[i].value.gameObject.SetActive(false);
            infoRows[i].key.text = infoRows[i].value.text = "";
        }

        neck.gameObject.SetActive(true);
        panel.gameObject.SetActive(true);

        // Hide previous anchor image
        if (anchor != null)
        {
            SetImageTransparency(anchor, 0);
        }

        // Show new anchor image
        anchor = rt.GetComponent <Image>();
        if (anchor != null)
        {
            SetImageTransparency(anchor, 1);
        }

        panelHeight = panel.rect.height;
        AdjustPanel();
    }
Example #10
0
    public Vector3 GetUnitsFromCoordinates(Coordinate coords)
    {
        var distance = GeoCalculator.LonLatToMeters(coords.Longitude, coords.Latitude) - currentMeters;

        return(new Vector3((float)distance.x * metersToUnits, (float)distance.y * metersToUnits, 0));
    }