Exemple #1
0
        [Route("/[controller]/AreaPlaceData/{code}/{styleSet}/{dataKey}")] //Draw an area using place data.
        public ActionResult DrawPlusCodeCustomElements(string code, string styleSet, string dataKey)
        {
            try
            {
                PerformanceTracker pt = new PerformanceTracker("DrawTilePlace");
                MapTileSupport.GetPlusCodeImagePixelSize(code, out var imgX, out var imgY);
                var info = new ImageStats(OpenLocationCode.DecodeValid(code), imgX, imgY);

                if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), info.area))
                {
                    pt.Stop("OOB");
                    return(StatusCode(500));
                }

                byte[] tileData = getExistingSlippyTile(code, styleSet);
                if (tileData != null)
                {
                    pt.Stop(code + "|" + styleSet);
                    return(File(tileData, "image/png"));
                }

                //Make tile
                var places   = GetPlacesForTile(info, null, styleSet, false);
                var paintOps = MapTileSupport.GetPaintOpsForCustomDataElements(dataKey, styleSet, info);
                tileData = FinishMapTile(info, paintOps, code, styleSet);

                pt.Stop(code + "|" + styleSet + "|" + Configuration.GetValue <string>("MapTilesEngine"));
                return(File(tileData, "image/png"));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex);
                return(StatusCode(500));
            }
        }
        public string GetPlusCodeTerrainDataFull(string plusCode)
        {
            //This function returns 1 line per Cell10 per intersecting element. For an app that needs to know all things in all points.
            PerformanceTracker pt  = new PerformanceTracker("GetPlusCodeTerrainDataFull");
            GeoArea            box = OpenLocationCode.DecodeValid(plusCode);

            if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), box))
            {
                return("");
            }
            var places = GetPlaces(box); //All the places in this Cell8

            places = places.Where(p => p.GameElementName != TagParser.defaultStyle.Name).ToList();

            StringBuilder sb = new StringBuilder();
            //pluscode|name|type|privacyID(named wrong but its the Guid)

            var data = AreaTypeInfo.SearchAreaFull(ref box, ref places);

            foreach (var d in data)
            {
                foreach (var v in d.Value)
                {
                    sb.Append(d.Key).Append("|").Append(v.Name).Append("|").Append(v.areaType).Append("|").Append(v.PrivacyId).Append("\r\n");
                }
            }
            var results = sb.ToString();

            pt.Stop(plusCode);
            return(results);
        }
Exemple #3
0
        [Route("/[controller]/SlippyAreaData/{styleSet}/{dataKey}/{zoom}/{x}/{y}.png")]                //slippy map conventions.
        public ActionResult DrawSlippyTileCustomPlusCodes(int x, int y, int zoom, string styleSet, string dataKey)
        {
            try
            {
                PerformanceTracker pt      = new PerformanceTracker("DrawSlippyTileCustomPlusCodes");
                string             tileKey = x.ToString() + "|" + y.ToString() + "|" + zoom.ToString();
                var info = new ImageStats(zoom, x, y, IMapTiles.SlippyTileSizeSquare);

                if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), info.area))
                {
                    pt.Stop("OOB");
                    return(StatusCode(500));
                }

                byte[] tileData = getExistingSlippyTile(tileKey, styleSet);
                if (tileData != null)
                {
                    pt.Stop(tileKey + "|" + styleSet);
                    return(File(tileData, "image/png"));
                }

                //Make tile
                var places   = GetPlacesForTile(info, null, styleSet);
                var paintOps = MapTileSupport.GetPaintOpsForCustomDataPlusCodes(dataKey, styleSet, info);
                tileData = FinishSlippyMapTile(info, paintOps, tileKey, styleSet);

                pt.Stop(tileKey + "|" + styleSet + "|" + Configuration.GetValue <string>("MapTilesEngine"));
                return(File(tileData, "image/png"));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex);
                return(StatusCode(500));
            }
        }
        public string GetPlusCodeTerrainData(string plusCode)
        {
            //This function returns 1 line per Cell10, the smallest (and therefore highest priority) item intersecting that cell10.
            PerformanceTracker pt  = new PerformanceTracker("GetPlusCodeTerrainData");
            GeoArea            box = OpenLocationCode.DecodeValid(plusCode);

            if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), box))
            {
                return("");
            }
            var places = GetPlaces(box);

            places = places.Where(p => p.GameElementName != TagParser.defaultStyle.Name).ToList();

            StringBuilder sb = new StringBuilder();
            //pluscode|name|type|PrivacyID

            var data = AreaTypeInfo.SearchArea(ref box, ref places);

            foreach (var d in data)
            {
                sb.Append(d.Key).Append("|").Append(d.Value.Name).Append("|").Append(d.Value.areaType).Append("|").Append(d.Value.PrivacyId).Append("\r\n");
            }
            var results = sb.ToString();

            pt.Stop(plusCode);
            return(results);
        }
        public void IncrementPlusCodeData(string plusCode, string key, double changeAmount, double?expirationTimer = null)
        {
            if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), OpenLocationCode.DecodeValid(plusCode)))
            {
                return;
            }

            PerformanceTracker pt      = new PerformanceTracker("IncrementPlusCodeData");
            string             lockKey = plusCode + key;

            locks.TryAdd(lockKey, new ReaderWriterLockSlim());
            var thisLock = locks[lockKey];

            thisLock.EnterWriteLock();
            var    data = GenericData.GetAreaData(plusCode, key);
            double val  = 0;

            Double.TryParse(data.ToString(), out val);
            val += changeAmount;
            GenericData.SetAreaData(plusCode, key, val.ToString(), expirationTimer);
            thisLock.ExitWriteLock();

            if (thisLock.WaitingWriteCount == 0)
            {
                locks.TryRemove(lockKey, out thisLock);
            }

            pt.Stop();
        }
 public bool SetPlusCodeData(string plusCode, string key, string value, double?expiresIn = null)
 {
     if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), OpenLocationCode.DecodeValid(plusCode)))
     {
         return(false);
     }
     return(GenericData.SetAreaData(plusCode, key, value, expiresIn));
 }
Exemple #7
0
        public void GetSecurePlusCodeData(string plusCode, string key, string password)
        {
            if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), OpenLocationCode.DecodeValid(plusCode)))
            {
                return;
            }

            byte[] rawData = GenericData.GetSecureAreaData(plusCode, key, password);
            Response.BodyWriter.Write(rawData);
            Response.CompleteAsync();
            return;
        }
        public void GetPlusCodeData(string plusCode, string key)
        {
            if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), OpenLocationCode.DecodeValid(plusCode)))
            {
                return;
            }

            var data = GenericData.GetAreaData(plusCode, key); //TODO: this requires writing bytes directly to Response.BodyWriter for all other, similar functions.

            Response.BodyWriter.WriteAsync(data);
            Response.CompleteAsync();
            return;
        }
Exemple #9
0
 public bool SetSecurePlusCodeData(string plusCode, string key, string value, string password, double?expiresIn = null)
 {
     if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), OpenLocationCode.DecodeValid(plusCode)))
     {
         return(false);
     }
     if (value == null)
     {
         var rr = Request.BodyReader.ReadAsync();
         var r2 = rr.Result.Buffer;
         return(GenericData.SetSecureAreaData(plusCode, key, r2.ToArray(), password, expiresIn));
     }
     return(GenericData.SetSecureAreaData(plusCode, key, value, password, expiresIn));
 }
        public string GetAllDataInPlusCode(string plusCode)
        {
            if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), OpenLocationCode.DecodeValid(plusCode)))
            {
                return("");
            }
            var           data = GenericData.GetAllDataInArea(plusCode);
            StringBuilder sb   = new StringBuilder();

            foreach (var d in data)
            {
                sb.Append(d.plusCode).Append("|").Append(d.key).Append("|").AppendLine(d.value);
            }

            return(sb.ToString());
        }