public ActionResult Get(string loc1, string loc2, string profile = "", bool instructions = false,
                                string lang = "en")
        {
            try
            {
                var from  = Utility.ParseCoordinate(loc1);
                var to    = Utility.ParseCoordinate(loc2);
                var route = RouterInstance.Calculate(profile, from, to);

                route.PruneColours();

                GeoJsonFeatureCollection instr = null;
                if (instructions)
                {
                    instr = RouterInstance.GenerateInstructions(route, lang);
                }

                RequestLogger.LogRequest(from, to);
                return(Json(new RouteResponse(route, instr)));
            }
            catch (ResolveException e)
            {
                Log.Error(e, "Getting a route failed (not found)");
                return(NotFound(e.Message));
            }
            catch (Exception e)
            {
                Log.Error(e, "Getting a route failed (other error)");
                return(BadRequest(e.Message));
            }
        }
Example #2
0
        /// <summary>
        /// Configure the services for the web api. Adds a CORS policy and initializes
        /// the router and languages.
        /// </summary>
        /// <param name="services">The services of the application.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();
            services.AddCors(options => {
                options.AddPolicy("AllowAnyOrigin",
                                  builder => builder.AllowAnyOrigin().AllowAnyHeader().WithMethods("GET"));
            });
            services.AddDirectoryBrowser();
            services.AddSingleton <IConfiguration> (Configuration);

            RouterInstance.Initialize(Configuration);
            Languages.initialize(Configuration);
            RequestLogger.initialize(Configuration);
        }
        public ActionResult Get(string loc1, string loc2, string profile = "", bool genInstructions = true, string lang = "en")
        {
            try {
                Coordinate from  = Utility.ParseCoordinate(loc1);
                Coordinate to    = Utility.ParseCoordinate(loc2);
                Route      route = RouterInstance.Calculate(profile, from, to);
                GeoJsonFeatureCollection instructions = null;
                if (genInstructions)
                {
                    try {
                        instructions = RouterInstance.GenerateInstructions(route, lang);
                    } catch {}
                }

                RequestLogger.LogRequest(from, to);
                return(Json(new RouteResponse(route, instructions)));
            } catch (ResolveException re) {
                return(NotFound(re.Message));
            } catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }
Example #4
0
        public void TestProgressiveResolve()
        {
            FixRouterDb();
            RouterInstance.Initialize(path, TimeSpan.FromMinutes(1));


            var profile = RouterInstance.GetRouter().Db.GetSupportedProfile("bicycle");
            var point   = RouterInstance.ResolvePointProgressive(profile,
                                                                 Utility.ParseCoordinate("50.96951708243853,5.482125931952595"));

            Assert.NotNull(point);

            // Middenin grote waterplas
            point = RouterInstance.ResolvePointProgressive(profile,
                                                           Utility.ParseCoordinate("51.22806105459313,2.9527336278404164"));
            Assert.NotNull(point);


            // Paar kilometer in zee
            point = RouterInstance.ResolvePointProgressive(profile,
                                                           Utility.ParseCoordinate("51.2905207937151,2.847190561776017"));
            Assert.NotNull(point);
        }