Beispiel #1
0
        /// <summary>
        /// Gets a map tile with geofences drawn on it.
        /// </summary>
        /// <param name="parameters">Map parameters such as bounding box, tile size, zoom level etc.</param>
        /// <param name="sites">List of geofences for the customer</param>
        /// <returns>A bitmap</returns>
        private byte[] GetGeofencesBitmap(MapParameters parameters, IEnumerable <GeofenceData> sites, bool isSites)
        {
            log.LogInformation("GetGeofencesBitmap");

            const int DEFAULT_SITE_COLOR = 0x0055FF;

            byte[] sitesImage = null;

            if (sites != null && sites.Any())
            {
                // Exclude sites that are too small to be displayed in the current viewport.
                double viewPortArea = Math.Abs(parameters.bbox.minLatDegrees - parameters.bbox.maxLatDegrees) * Math.Abs(parameters.bbox.minLngDegrees - parameters.bbox.maxLngDegrees);
                double minArea      = viewPortArea / 10000;

                using (Image <Rgba32> bitmap = new Image <Rgba32>(parameters.mapWidth, parameters.mapHeight))
                {
                    foreach (var site in sites)
                    {
                        log.LogDebug($"GetGeofencesBitmap examining site {site.GeofenceUID}");
                        //Old geofences may not have AreaSqMeters set.
                        if (site.AreaSqMeters > 0 && site.AreaSqMeters < minArea)
                        {
                            log.LogDebug($"GetGeofencesBitmap excluding site {site.GeofenceUID} due to area");
                            continue;
                        }

                        var sitePoints = site.GeometryWKT.GeometryToPoints().ToList();

                        //Exclude site if outside bbox
                        bool outside = TileServiceUtils.Outside(parameters.bbox, sitePoints);

                        if (outside)
                        {
                            log.LogDebug($"GetGeofencesBitmap excluding site {site.GeofenceUID} outside bbox");
                        }
                        else
                        {
                            int  siteColor   = site.FillColor > 0 ? site.FillColor : (isSites ? DEFAULT_SITE_COLOR : DEFAULT_CUSTOM_BOUNDARY_COLOR);
                            bool transparent = isSites ? site.IsTransparent : true;
                            DrawGeofence(parameters, bitmap, site.GeofenceUID.ToString(), sitePoints, siteColor, transparent);
                        }
                    }

                    sitesImage = bitmap.BitmapToByteArray();
                }
            }

            return(sitesImage);
        }
Beispiel #2
0
        public void PolygonOutsideBoundingBox()
        {
            var bbox = new MapBoundingBox
            {
                minLat = 36.0, minLng = -115.9, maxLat = 36.5, maxLng = -115.0
            };
            var points = new List <WGSPoint>
            {
                new WGSPoint(35.0, -116.0),
                new WGSPoint(35.5, -116.0),
                new WGSPoint(35.5, -116.5),
                new WGSPoint(35.0, -116.5),
                new WGSPoint(35.0, -116.0),
            };

            Assert.True(TileServiceUtils.Outside(bbox, points));
        }
Beispiel #3
0
        public void PolygonIntersectsBoundingBox()
        {
            var bbox = new MapBoundingBox
            {
                minLat = 36.0,
                minLng = -115.9,
                maxLat = 36.5,
                maxLng = -115.0
            };
            var points = new List <WGSPoint>
            {
                new WGSPoint(35.9, -115.5),
                new WGSPoint(36.3, -115.5),
                new WGSPoint(36.3, -115.7),
                new WGSPoint(35.9, -115.7),
                new WGSPoint(35.9, -115.5),
            };

            Assert.False(TileServiceUtils.Outside(bbox, points));
        }