// POST api/<controller>
        //public dynamic Post([FromBody]JsonGetMarkersInput input)
        public dynamic Post([ModelBinder] JsonGetMarkersInput input)
        {
            // http://stackoverflow.com/questions/10863499/asp-net-web-api-model-binding-not-working-like-it-does-in-mvc-3
            var result = Map.MapService.GetMarkers(input);

            return(result);
        }
Beispiel #2
0
        public JsonMarkersReply GetMarkers(JsonGetMarkersInput input)
        {
            // Decorate with elapsed time
            var sw = new Stopwatch();

            sw.Start();
            var reply = GetMarkersHelper(input);

            sw.Stop();
            reply.Msec = sw.Elapsed.ToString();
            return(reply);
        }
Beispiel #3
0
 public ContentResult GetMarkers(JsonGetMarkersInput input)
 {
     return(JsonMin(_mapService.GetMarkers(input)));
 }
        // GET api/<controller>/
        public dynamic Get([ModelBinder] JsonGetMarkersInput input)
        {
            var result = Map.MapService.GetMarkers(input);

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Read Through Cache
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public JsonMarkersReply GetMarkersHelper(JsonGetMarkersInput input)
        {
            try
            {
                var nelat     = Math.Round(input.nelat.ToDouble(), Numbers.Round);
                var nelon     = Math.Round(input.nelon.ToDouble(), Numbers.Round);
                var swlat     = Math.Round(input.swlat.ToDouble(), Numbers.Round);
                var swlon     = Math.Round(input.swlon.ToDouble(), Numbers.Round);
                var zoomLevel = int.Parse(input.zoomLevel);
                var filter    = input.filter ?? "";

                // values are validated there
                var inputValidated = new JsonGetMarkersReceive(nelat, nelon, swlat, swlon, zoomLevel, filter);

                var grid           = GridCluster.GetBoundaryExtended(inputValidated);
                var cacheKeyHelper = string.Format("{0}_{1}_{2}", inputValidated.Zoomlevel, inputValidated.FilterHashCode(), grid.GetHashCode());
                var cacheKey       = CacheKeys.GetMarkers(cacheKeyHelper.GetHashCode());

                var reply = _memCache.Get <JsonMarkersReply>(cacheKey);
                if (reply != null)
                {
                    // return cached data
                    reply.Cache = true;
                    return(reply);
                }

                inputValidated.Viewport.ValidateLatLon();                 // Validate google map viewport input (should be always valid)
                inputValidated.Viewport.Normalize();

                // Get all points from memory
                IList <P> points = _pointsDatabase.GetPoints();

                #region fiter

                // Filter points
                points = FilterUtil.FilterByType(
                    points,
                    new FilterData {
                    TypeFilterExclude = inputValidated.TypeFilterExclude
                }
                    );

                #endregion filter


                // Create new instance for every ajax request with input all points and json data
                ICluster clusterAlgo = new GridCluster(points, inputValidated);

                var clusteringEnabled = inputValidated.IsClusteringEnabled ||
                                        GmcSettings.Get.AlwaysClusteringEnabledWhenZoomLevelLess > inputValidated.Zoomlevel;

                // Clustering
                if (clusteringEnabled && inputValidated.Zoomlevel < GmcSettings.Get.ZoomlevelClusterStop)
                {
                    #region cluster

                    IList <P> markers = clusterAlgo.RunCluster();

                    #endregion cluster

                    reply = new JsonMarkersReply
                    {
                        Markers   = markers,
                        Polylines = clusterAlgo.GetPolyLines(),
                    };
                }
                else
                {
                    // If we are here then there are no clustering
                    // The number of items returned is restricted to avoid json data overflow
                    IList <P> filteredDataset          = FilterUtil.FilterDataByViewport(points, inputValidated.Viewport);
                    IList <P> filteredDatasetMaxPoints = filteredDataset.Take(GmcSettings.Get.MaxMarkersReturned).ToList();

                    reply = new JsonMarkersReply
                    {
                        Markers   = filteredDatasetMaxPoints,
                        Polylines = clusterAlgo.GetPolyLines(),
                        Mia       = filteredDataset.Count - filteredDatasetMaxPoints.Count,
                    };
                }

                // if client ne and sw is inside a specific grid box then cache the grid box and the result
                // next time test if ne and sw is inside the grid box and return the cached result
                if (GmcSettings.Get.CacheServices)
                {
                    _memCache.Set(reply, cacheKey, TimeSpan.FromMinutes(10));                                               // cache data
                }
                return(reply);
            }
            catch (Exception ex)
            {
                return(new JsonMarkersReply
                {
                    Ok = "0",
                    EMsg = string.Format("MapService says: exception {0}", ex.Message)
                });
            }
        }
 public ContentResult GetMarkers(JsonGetMarkersInput input)
 {
     return JsonMin(_mapService.GetMarkers(input));
 }