From 3d3d57813175e61d08e60cb61c25f55db8e8ba0d Mon Sep 17 00:00:00 2001 From: zharkovstas Date: Sun, 19 May 2019 11:08:32 +0500 Subject: [PATCH] Set correct map boundaries --- app.py | 22 ++++++---------------- config/webpackDevServer.config.js | 4 +++- src/Game.js | 4 ++-- src/GameController.js | 12 ++++++++++-- src/api.js | 4 ++-- src/createMap.js | 10 +++++----- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app.py b/app.py index 52cf996..a6dad3f 100644 --- a/app.py +++ b/app.py @@ -100,7 +100,8 @@ def add_tips(game): type = convert_sightseeing_type(s['type']) direction = get_direction(coordinate, (s['lat'], s['lon'])) game.tips.append( - f'Кстати, неподалеку на {convert_direction(direction)}е есть ' + (type if type else 'интересный туристический объект') + ': ' + s["name"]) + f'Кстати, неподалеку на {convert_direction(direction)}е есть ' + ( + type if type else 'интересный туристический объект') + ': ' + s["name"]) shuffle(game.tips) @@ -228,8 +229,10 @@ def get_games(): } -def handle_post_game(city_id): +@post('/api/games') +def post_game(): game_id = str(uuid.uuid4()) + city_id = request.json['city'] or 'Екатеринбург' if city_id not in cities: return bottle.HTTPResponse(status=404, body='city not found') @@ -253,18 +256,6 @@ def handle_post_game(city_id): } -@post('/api/games') -@enable_cors -def post_game_without_city(): - return handle_post_game('Екатеринбург') - - -@post('/api/games/') -@enable_cors -def post_game(city): - return handle_post_game(city) - - @get('/api/games/') @enable_cors def get_game(game_id): @@ -326,7 +317,6 @@ def move(game_id, direction): has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0 - return {'tips': game.shown_tips, 'hasMore': has_more} @@ -392,10 +382,10 @@ def static_media(staticFile): def index(whatever): return static_file('index.html', "build") + application = bottle.default_app() from paste import httpserver - if os.environ.get('APP_LOCATION') == 'heroku': httpserver.serve(application, host='0.0.0.0', port=int(os.environ.get("PORT", 5000))) else: diff --git a/config/webpackDevServer.config.js b/config/webpackDevServer.config.js index 33ab8d3..8afbb31 100644 --- a/config/webpackDevServer.config.js +++ b/config/webpackDevServer.config.js @@ -81,7 +81,9 @@ module.exports = function(proxy, allowedHost) { disableDotRule: true, }, public: allowedHost, - proxy, + proxy: { + '/api': {target: 'http://localhost:8080/'} + }, before(app, server) { if (fs.existsSync(paths.proxySetup)) { // This registers user provided middleware for proxy reasons diff --git a/src/Game.js b/src/Game.js index 49f4a45..e1eb68b 100644 --- a/src/Game.js +++ b/src/Game.js @@ -27,14 +27,14 @@ export class Game extends Component { } componentDidMount() { - this.gameController.createGame().then(() => this.gameController.loadTips()).then(() => { + this.gameController.createGame('Екатеринбург').then(() => this.gameController.loadTips()).then(() => { this.setState({ tips: this.handleVarlamov(this.gameController.tips()), hasMoreTips: this.gameController.hasMoreTips(), loading: false, inProcess: false }, () => { - createMap('map', this.onMapClick); + createMap('map', this.onMapClick, this.gameController.getBoundaries()); }) }).catch(error => { this.notification.show( diff --git a/src/GameController.js b/src/GameController.js index ad44d75..6452382 100644 --- a/src/GameController.js +++ b/src/GameController.js @@ -6,9 +6,13 @@ export class GameController { this.notification = notification; } - createGame() { - return api.post('/games').then(json => { + createGame(city) { + return api.post('/games', {city: city}).then(json => { this.gameId = json.data.game_id; + this.minLat = json.data.min_lat; + this.maxLat = json.data.max_lat; + this.minLon = json.data.min_lon; + this.maxLon = json.data.max_lon; }); } @@ -75,4 +79,8 @@ export class GameController { tryFinish(ltLng) { return api.post(`/games/${this.gameId}/finish/${ltLng}`); } + + getBoundaries() { + return [[this.minLat, this.minLon], [this.maxLat, this.maxLon]]; + } } diff --git a/src/api.js b/src/api.js index 5c21ea7..ba0ad0e 100644 --- a/src/api.js +++ b/src/api.js @@ -1,6 +1,6 @@ import * as axios from 'axios'; export const api = axios.create({ - baseURL: process.env.NODE_ENV === 'production' ? '/api/': 'http://localhost:8080/api/', - timeout: 30000 + baseURL: process.env.NODE_ENV === 'production' ? '/api/': '/api/', + timeout: 60000 }); \ No newline at end of file diff --git a/src/createMap.js b/src/createMap.js index dac78e4..5d8ca59 100644 --- a/src/createMap.js +++ b/src/createMap.js @@ -5,11 +5,11 @@ const ekb = { SW: ['56.768982', '60.491112'] }; -export function createMap(elementId, onMapClick) { - const neLat = ekb.NE[0]; - const neLng = ekb.NE[1]; - const swLat = ekb.SW[0]; - const swLng = ekb.SW[1]; +export function createMap(elementId, onMapClick, boundaries) { + const neLat = boundaries[0][0]; + const neLng = boundaries[0][1]; + const swLat = boundaries[1][0]; + const swLng = boundaries[1][1]; const map = new L.Map(elementId); -- 2.50.1