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);
    }
    public static bool Contains(this AreaBounds bounds, OctTreeOccupant octTreeOccupant)
    {
        if (octTreeOccupant == null)
        {
            return(false);
        }

        Transform      sphereTransform = octTreeOccupant.Transform;
        SphereCollider sphere          = octTreeOccupant.SphereCollider;

        if (sphereTransform == null || sphere == null)
        {
            return(false);
        }

        Vector3 spherePosition = sphereTransform.position;

        spherePosition += sphere.center;
        float sphereRadius = sphere.radius;

        if (spherePosition.x - sphereRadius > bounds.MaxBounds.x ||
            spherePosition.y - sphereRadius > bounds.MaxBounds.y ||
            spherePosition.z - sphereRadius > bounds.MaxBounds.z ||
            spherePosition.x + sphereRadius < bounds.MinBounds.x ||
            spherePosition.y + sphereRadius < bounds.MinBounds.y ||
            spherePosition.z + sphereRadius < bounds.MinBounds.z)
        {
            return(false);
        }
        return(true);
    }
Ejemplo n.º 3
0
 public Site(string name, Site parent, AreaBounds bounds, List <DataLayer> dataLayers)
 {
     this.name       = name;
     this.bounds     = bounds;
     this.dataLayers = dataLayers;
     this.parent     = parent;
 }
Ejemplo n.º 4
0
    //
    // Public Methods
    //

    public AreaMapLayer Add(Site site, AreaBounds bounds)
    {
        AreaMapLayer layer = Instantiate(sitePrefab);

        layer.name = site.name;
        layer.Init(map, bounds.north, bounds.east, bounds.south, bounds.west);
        layer.transform.SetParent(transform, false);
        mapLayers.Add(layer);
        siteToMapLayer.Add(site, layer);
        return(layer);
    }
Ejemplo n.º 5
0
    //
    // Private Methods
    //

    private IEnumerator WaitForUI()
    {
        // Wait 2 frames for UI to be created
        yield return(null);

        yield return(null);

        AreaBounds bounds = new AreaBounds(GeoCalculator.MinLongitude, GeoCalculator.MaxLongitude, GeoCalculator.MaxLatitude, GeoCalculator.MinLatitude);

        ZoomToBounds(bounds, false);
    }
Ejemplo n.º 6
0
    //
    // Public Methods
    //

    public AreaMapLayer Add(Site site, AreaBounds bounds)
    {
        AreaMapLayer layer = Instantiate(sitePrefab);

        layer.name = site.Name;
        layer.Init(map, bounds.north, bounds.east, bounds.south, bounds.west);
        layer.transform.SetParent(transform, false);
        mapLayers.Add(layer);
        siteToMapLayer.Add(site, layer);

        if (!showBoundaries && site != highlightedSite)
        {
            layer.Show(false);
        }

        return(layer);
    }
Ejemplo n.º 7
0
        public bool Matches(SniperInfo sniperInfo)
        {
            var pokemonIds = PokemonFilterParser.ParseBinary(Pokemon);

            if (pokemonIds != null && !pokemonIds.Contains(sniperInfo.Id))
            {
                return(false);
            }
            if (AreaBounds != null && !AreaBounds.Intersects(sniperInfo.Latitude, sniperInfo.Longitude))
            {
                return(false);
            }
            if (MinimumIV > sniperInfo.IV)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// A Shapefile MultiPoint Shape
        /// </summary>
        /// <param name="shapeData">The shape record as a byte array</param>
        /// <exception cref="ArgumentNullException">Thrown if shapeData is null</exception>
        /// <exception cref="InvalidOperationException">Thrown if an error occurs parsing shapeData</exception>
        protected internal ShapeMultiPoint(byte[] shapeData)
            : base(ShapeType.MultiPoint)
        {
            // metadata is validated by the base class
            if (shapeData == null)
            {
                throw new ArgumentNullException("shapeData");
            }

            // Note, shapeData includes an 8 byte header so positions below are +8
            // Position     Field       Value       Type        Number      Order
            // Byte 0       Shape Type  8           Integer     1           Little
            // Byte 4       Box         Box         Double      4           Little
            // Byte 36      NumPoints   Num Points  Integer     1           Little
            // Byte 40      Points      Points      Point       NumPoints   Little

            // validation step 1 - must have at least 8 + 4 + (4*8) + 4 bytes = 48
            if (shapeData.Length < 48)
            {
                throw new InvalidOperationException("Invalid shape data");
            }

            // extract bounding box and points
            _boundingBox = ParseBoundingBox(shapeData, 12, ProvidedOrder.Little);
            Debug.Log($"Extents: {_boundingBox.west}, {_boundingBox.east}, {_boundingBox.north}, {_boundingBox.south}");
            int numPoints = EndianBitConverter.ToInt32(shapeData, 44, ProvidedOrder.Little);

            Debug.Log($"numPoints: {numPoints}");

            // validation step 2 - we're expecting 16 * numPoints + 48 bytes total
            if (shapeData.Length != 48 + (16 * numPoints))
            {
                throw new InvalidOperationException("Invalid shape data");
            }

            // now extract the points
            _points = new PointD[numPoints];
            for (int pointNum = 0; pointNum < numPoints; pointNum++)
            {
                _points[pointNum] = new PointD(EndianBitConverter.ToDouble(shapeData, 48 + (16 * pointNum), ProvidedOrder.Little),
                                               EndianBitConverter.ToDouble(shapeData, 56 + (16 * pointNum), ProvidedOrder.Little));
            }
        }
Ejemplo n.º 9
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));
        }
    }
Ejemplo n.º 10
0
    private void UpdateLayerPanel(DataLayerPanel layerPanel, int level, AreaBounds bounds)
    {
        var dataLayer = layerPanel.DataLayer;

        var site = ComponentManager.Instance.Get <SiteBrowser>().ActiveSite;

        bool hasPatches;

        if (layerPanel.IsLayerToggleOn)
        {
            dataLayer.UpdatePatches(site, level, bounds);
            hasPatches = dataLayer.HasPatchesInView();

            if (hasPatches && !availableLayers.Contains(dataLayer))
            {
                availableLayers.Add(dataLayer);
                if (OnLayerAvailabilityChange != null)
                {
                    OnLayerAvailabilityChange(dataLayer, true);
                }
            }
            else if (!hasPatches && availableLayers.Contains(dataLayer))
            {
                availableLayers.Remove(dataLayer);
                if (OnLayerAvailabilityChange != null)
                {
                    OnLayerAvailabilityChange(dataLayer, false);
                }
            }
        }
        else
        {
            hasPatches = dataLayer.HasPatches(site, level, bounds.west, bounds.east, bounds.north, bounds.south);
        }

        // Show/hide a layer panel when only visible layers are allowed, otherwise enable/disable the layer panel
        EnableLayerPanel(layerPanel, hasPatches);
    }
Ejemplo n.º 11
0
        /// <summary>
        /// Function is basically the same as Shape.ParsePolyLineOrPolygon, it is just
        /// extended to handle the M extreme values
        /// </summary>
        /// <param name="shapeData">The shape record as a byte array</param>
        /// <param name="boundingBox">Returns the bounding box</param>
        /// <param name="parts">Returns the list of parts</param>
        private void ParsePolyLineM(byte[] shapeData, out RectangleD boundingBox, out List <PointD[]> parts)
        {
            boundingBox = new RectangleD();
            parts       = null;

            // metadata is validated by the base class
            if (shapeData == null)
            {
                throw new ArgumentNullException("shapeData");
            }

            // Note, shapeData includes an 8 byte header so positions below are +8
            // Position     Field       Value       Type        Number      Order
            // Byte 0       Shape Type  23          Integer     1           Little
            // Byte 4       Box         Box         Double      4           Little
            // Byte 36      NumParts    NumParts    Integer     1           Little
            // Byte 40      NumPoints   NumPoints   Integer     1           Little
            // Byte 44      Parts       Parts       Integer     NumParts    Little
            // Byte X       Points      Points      Point       NumPoints   Little
            // Byte Y*      Mmin        Mmin        Double      1           Little
            // Byte Y + 8*  Mmax        Mmax        Double      1           Little
            // Byte Y + 16* Marray      Marray      Double      NumPoints   Little

            //
            // *optional

            // validation step 1 - must have at least 8 + 4 + (4*8) + 4 + 4 bytes = 52
            if (shapeData.Length < 44)
            {
                throw new InvalidOperationException("Invalid shape data");
            }

            // extract bounding box, number of parts and number of points
            boundingBox = ParseBoundingBox(shapeData, 12, ProvidedOrder.Little);
            Debug.Log($"Extents: {boundingBox.west}, {boundingBox.east}, {boundingBox.north}, {boundingBox.south}");
            int numParts = EndianBitConverter.ToInt32(shapeData, 44, ProvidedOrder.Little);

            Debug.Log($"numParts: {numParts}");
            int numPoints = EndianBitConverter.ToInt32(shapeData, 48, ProvidedOrder.Little);

            Debug.Log($"numPoints: {numPoints}");

            // validation step 2 - we're expecting 4 * numParts + (16 + 8 * numPoints for m extremes and values) + 16 * numPoints + 52 bytes total
            if (shapeData.Length != 52 + (4 * numParts) + 16 + 8 * numPoints + (16 * numPoints))
            {
                throw new InvalidOperationException("Invalid shape data");
            }

            // now extract the parts
            int partsOffset = 52 + (4 * numParts);

            parts = new List <PointD[]>(numParts);
            for (int part = 0; part < numParts; part++)
            {
                // this is the index of the start of the part in the points array
                int startPart = (EndianBitConverter.ToInt32(shapeData, 52 + (4 * part), ProvidedOrder.Little) * 16) + partsOffset;

                int numBytes;
                if (part == numParts - 1)
                {
                    // it's the last part so we go to the end of the point array
                    numBytes = shapeData.Length - startPart;

                    // remove bytes for M extreme block
                    numBytes -= numPoints * 8 + 16;
                }
                else
                {
                    // we need to get the next part
                    int nextPart = (EndianBitConverter.ToInt32(shapeData, 52 + (4 * (part + 1)), ProvidedOrder.Little) * 16) + partsOffset;
                    numBytes = nextPart - startPart;
                }

                // the number of 16-byte points to read for this segment
                int numPointsInPart = (numBytes) / 16;

                PointD[] points = new PointD[numPointsInPart];
                for (int point = 0; point < numPointsInPart; point++)
                {
                    points[point] = new PointD(EndianBitConverter.ToDouble(shapeData, startPart + (16 * point), ProvidedOrder.Little),
                                               EndianBitConverter.ToDouble(shapeData, startPart + 8 + (16 * point), ProvidedOrder.Little));
                }

                parts.Add(points);
            }

            // parse M information
            Mmin = EndianBitConverter.ToDouble(shapeData, 52 + (4 * numParts) + (16 * numPoints), ProvidedOrder.Little);
            Mmax = EndianBitConverter.ToDouble(shapeData, 52 + 8 + (4 * numParts) + (16 * numPoints), ProvidedOrder.Little);

            M.Clear();
            for (int i = 0; i < numPoints; i++)
            {
                double _m = EndianBitConverter.ToDouble(shapeData, 52 + 16 + (4 * numParts) + (16 * numPoints) + i * 8, ProvidedOrder.Little);
                M.Add(_m);
            }
        }
Ejemplo n.º 12
0
    public void UpdatePatches(Site site, int levelIndex, AreaBounds bounds)
    {
        bool removedPatches = false;

        if (visibleYear == -1)
        {
            // Hide visible patches that don't meet the criteria
            for (int i = patchesInView.Count - 1; i >= 0; i--)
            {
                var patch = patchesInView[i];
                if (patch.Level != levelIndex ||
                    !patch.Data.Intersects(bounds.west, bounds.east, bounds.north, bounds.south) ||
                    patch.SiteRecord.layerSite.Site != site)
                {
                    RemovePatchInView(i);
                    removedPatches = true;
                }
            }

            // Show non-visible patches that meet the criteria
            foreach (var layerSite in levels[levelIndex].layerSites)
            {
                if (layerSite.Site == site)
                {
                    foreach (var patch in layerSite.LastRecord.patches)
                    {
                        var patchData = patch.Data;
                        if (!patch.IsVisible() &&
                            patchData.Intersects(bounds.west, bounds.east, bounds.north, bounds.south) &&
                            !dataManager.IsRequesting(patch))
                        {
                            AddPatchInView(patch);
                        }
                    }
                }
            }
        }
        else
        {
            // Hide visible patches that don't meet the criteria
            for (int i = patchesInView.Count - 1; i >= 0; i--)
            {
                var patch = patchesInView[i];
                if (patch.Level != levelIndex || !patch.Data.Intersects(bounds.west, bounds.east, bounds.north, bounds.south) ||
                    patch.Year != visibleYear ||
                    patch.SiteRecord.layerSite.Site != site)
                {
                    RemovePatchInView(i);
                    removedPatches = true;
                }
            }

            // Show non-visible sites that meet the criteria
            foreach (var layerSite in levels[levelIndex].layerSites)
            {
                if (layerSite.Site == site &&
                    layerSite.records.ContainsKey(visibleYear))
                {
                    foreach (var patch in layerSite.records[visibleYear].patches)
                    {
                        var patchData = patch.Data;
                        if (!patch.IsVisible() &&
                            patchData.Intersects(bounds.west, bounds.east, bounds.north, bounds.south) &&
                            !dataManager.IsRequesting(patch))
                        {
                            AddPatchInView(patch);
                        }
                    }
                }
            }
        }

        if (removedPatches)
        {
            UpdateLoadedVisibleRange();
        }
    }
Ejemplo n.º 13
0
 public void Show(int levelIndex, AreaBounds bounds)
 {
     InitVisibleRange();
     UpdatePatches(dataManager.ActiveSite, levelIndex, bounds);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Create a new Shapefile object and open a Shapefile. Note that three files are required -
        /// the main file (.shp), the index file (.shx) and the dBASE table (.dbf). The three files
        /// must all have the same filename (i.e. shapes.shp, shapes.shx and shapes.dbf). Set path
        /// to any one of these three files to open the Shapefile.
        /// </summary>
        /// <param name="path">Path to the .shp, .shx or .dbf file for this Shapefile</param>
        /// <exception cref="ObjectDisposedException">Thrown if the Shapefile has been disposed</exception>
        /// <exception cref="ArgumentNullException">Thrown if the path parameter is null</exception>
        /// <exception cref="ArgumentException">Thrown if the path parameter is empty</exception>
        /// <exception cref="FileNotFoundException">Thrown if one of the three required files is not found</exception>
        /// <exception cref="InvalidOperationException">Thrown if an error occurs parsing file headers</exception>
        public void Open(string path)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("Shapefile");
            }

            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (path.Length <= 0)
            {
                throw new ArgumentException("path parameter is empty", "path");
            }

            _shapefileMainPath  = Path.ChangeExtension(path, MainPathExtension);
            _shapefileIndexPath = Path.ChangeExtension(path, IndexPathExtension);
            _shapefileDbasePath = Path.ChangeExtension(path, DbasePathExtension);

            if (!File.Exists(_shapefileMainPath))
            {
                throw new FileNotFoundException("Shapefile main file not found", _shapefileMainPath);
            }
            if (!File.Exists(_shapefileIndexPath))
            {
                throw new FileNotFoundException("Shapefile index file not found", _shapefileIndexPath);
            }
            if (!File.Exists(_shapefileDbasePath))
            {
                throw new FileNotFoundException("Shapefile dBase file not found", _shapefileDbasePath);
            }

            _mainStream  = File.Open(_shapefileMainPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            _indexStream = File.Open(_shapefileIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read);

            if (_mainStream.Length < Header.HeaderLength)
            {
                throw new InvalidOperationException("Shapefile main file does not contain a valid header");
            }

            if (_indexStream.Length < Header.HeaderLength)
            {
                throw new InvalidOperationException("Shapefile index file does not contain a valid header");
            }

            // read in and parse the headers
            byte[] headerBytes = new byte[Header.HeaderLength];
            _mainStream.Read(headerBytes, 0, Header.HeaderLength);
            _mainHeader = new Header(headerBytes);
            _indexStream.Read(headerBytes, 0, Header.HeaderLength);
            _indexHeader = new Header(headerBytes);

            // set properties from the main header
            _type        = _mainHeader.ShapeType;
            _boundingBox = new RectangleD(_mainHeader.XMin, _mainHeader.XMax, _mainHeader.YMin, _mainHeader.YMax);

            // index header length is in 16-bit words, including the header - number of
            // shapes is the number of records (each 4 workds long) after subtracting the header bytes
            _count = (_indexHeader.FileLength - (Header.HeaderLength / 2)) / 4;

            // Read .dbf file
            _dbfFile = new DbfFile(_shapefileDbasePath, out _dbfStream);
            if (_dbfStream.Length < Header.HeaderLength)
            {
                throw new InvalidOperationException("Shapefile dbf file does not contain a valid header");
            }
            _dbfFile.Load();

            // Initialize shapes
            Shapes = new List <Shape>();
            foreach (var shape in this)
            {
                Shapes.Add(shape);
            }

            _opened = true;
        }
Ejemplo n.º 15
0
 public void Show(int levelIndex, AreaBounds bounds)
 {
     InitVisibleRange();
     UpdatePatches(levelIndex, bounds);
 }
Ejemplo n.º 16
0
 public AreaBounds(AreaBounds other) : this(other.west, other.east, other.north, other.south)
 {
 }
Ejemplo n.º 17
0
        // ----------------------------------------------------------------------------

        public OctTree(OctTree parent, AreaBounds bounds)
        {
            m_parent = parent;
            m_bounds = bounds;
        }