From: zharkovstas Date: Sun, 19 May 2019 04:48:09 +0000 (+0500) Subject: Add marker and polylines. Decrease max score X-Git-Url: https://git.xn--bdkaa.com/?a=commitdiff_plain;h=f4aeb18ad70fd5dcbc38fcba25aa10c057d19b96;p=where-are-you.py.git Add marker and polylines. Decrease max score --- diff --git a/app.py b/app.py index 2e67f91..7f38e92 100644 --- a/app.py +++ b/app.py @@ -215,7 +215,7 @@ def enable_cors(fn): def count_score(game): dist = distance(game.current_coordinates, game.answer_coordinates) - return 100_000_000 / (1 + dist) + return 100_000 / (1 + dist) @get('/api/games') diff --git a/src/Game.js b/src/Game.js index 5ddf95e..df7f4da 100644 --- a/src/Game.js +++ b/src/Game.js @@ -3,10 +3,12 @@ import React, { Component } from 'react'; import { AppLayout } from './AppLayout'; import logo from './img/cat.png'; import varlamov from './img/varlamov.png'; +import truePlaceIcon from './img/true-place-icon.png'; import { createMap } from './createMap'; import { GameController } from './GameController'; import { Notification } from './Notification'; import Button from '@skbkontur/react-ui/Button'; +import * as L from 'leaflet'; export class Game extends Component { constructor(props) { @@ -104,11 +106,25 @@ export class Game extends Component { }); }; - onMapClick = (e) => { + onMapClick = (e, map) => { this.gameController.tryFinish(`${e.latlng.lat}/${e.latlng.lng}`).then(json => { + + var greenIcon = L.icon({ + iconUrl: truePlaceIcon, + + iconSize: [25, 41], + iconAnchor: [13, 41] + }); + + + L.marker([e.latlng.lat, e.latlng.lng]).addTo(map); + L.polyline([[e.latlng.lat, e.latlng.lng], [json.data.right_coordinates[0], json.data.right_coordinates[1]]], {color: 'green'}).addTo(map); + L.polyline(json.data.route, {color: 'red'}).addTo(map); + L.marker([json.data.right_coordinates[0], json.data.right_coordinates[1]], {icon: greenIcon}).addTo(map); + this.notification.show( 'Игра закончена.', - `Неплохая попытка! Вы оказались по адресу: ${json.data.address}, а промахнулись на ${Math.round(json.data.distance)} метров.`, + `Неплохая попытка! Вы оказались по адресу: ${json.data.address}, промахнулись на ${Math.round(json.data.distance)} метров и заработали ${Math.round(json.data.score)} очков.`, () => { window.location = '/'; } diff --git a/src/createMap.js b/src/createMap.js index 068a557..dac78e4 100644 --- a/src/createMap.js +++ b/src/createMap.js @@ -13,7 +13,7 @@ export function createMap(elementId, onMapClick) { const map = new L.Map(elementId); - map.on('click', onMapClick); + map.on('click', (e) => {onMapClick(e, map)}); const service = new L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', diff --git a/src/img/true-place-icon.png b/src/img/true-place-icon.png new file mode 100644 index 0000000..1ff4659 Binary files /dev/null and b/src/img/true-place-icon.png differ