{% extends 'base.html.twig' %}
{% block title %}Hello AllTyreController!{% endblock %}
{% block body %}
<script>
let coordinat;
let xy;
function getPos() {
var loca = {{ product.location|json_encode|raw }};
fetch('https://geocode-maps.yandex.ru/1.x/?apikey=0b8c32a5-05a1-4b77-8b56-b0668e11d9e0&format=json&geocode='+loca)
.then(response => response.json())
.then(data => {
// console.log(data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos);
coordinat = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos;
xy = coordinat.split(' ');
let pos1 = xy[0];
let pos2 = xy[1];
main(pos1, pos2);
})
.catch(error => console.error(error));
}
getPos();
async function main(pos1, pos2) {
// Промис `ymaps3.ready` будет зарезолвлен, когда
// загрузятся все компоненты API.
await ymaps3.ready;
// Создание карты.
const map = new ymaps3.YMap(document.getElementById('map'), {
location: {
// Координаты центра карты.
// Порядок по умолчанию: «долгота, широта».
center: [pos1, pos2],
// Уровень масштабирования. Допустимые значения:
// от 0 (весь мир) до 19.
zoom: 17
}
},
[
// Добавляем слой для отображения схематической карты.
new ymaps3.YMapDefaultSchemeLayer()
]
)
map.addChild(new ymaps3.YMapDefaultFeaturesLayer()); // В этом слое будут маркеры.
// DOM-элемент должен быть создан заранее, но его содержимое можно задать в любой момент.
const content = document.createElement('section');
const marker = new ymaps3.YMapMarker({
coordinates: [pos1, pos2],
draggable: true
}, content);
map.addChild(marker);
content.innerHTML = '<h1>O</h1>';
}
</script>
<div class="container">
<h2 class="display-3">Автор - {{ product.name }}</h2>
<h2 class="display-5">{{ product.fstring }}</h2>
<h2 class="display-5">Цена - {{ product.price }}</h2>
<h2 class="display-5">Адресс - {{ product.location }}</h2>
<img style="height: 90px;" class="img-fluid" src="{{ asset('uploads/images/' ~ product.path) }}">
{% if is_granted('ROLE_USER') %}
<form action="{{ path('add_to_favorites', { 'productId': product.id }) }}" method="POST">
<input type="hidden" name="_csrf_token" value="{{ csrf_token('add_to_favorites') }}">
<button type="submit">
Добавить
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-bag-heart" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M10.5 3.5a2.5 2.5 0 0 0-5 0V4h5v-.5Zm1 0V4H15v10a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V4h3.5v-.5a3.5 3.5 0 1 1 7 0ZM14 14V5H2v9a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1ZM8 7.993c1.664-1.711 5.825 1.283 0 5.132-5.825-3.85-1.664-6.843 0-5.132Z"/>
</svg>
</button>
</form>
{% endif %}
{# {% if is_granted('ROLE_USER') %}
{% if product.isFavorite %}
<form action="{{ path('remove_from_favorites', { 'productId': product.id }) }}" method="POST"> <input type="hidden" name="_csrf_token" value="{{ csrf_token('remove_from_favorites') }}">
<button type="submit">Remove from Favorites</button>
</form>
{% else %}
<form action="{{ path('add_to_favorites', { 'productId': product.id }) }}" method="POST"> <input type="hidden" name="_csrf_token" value="{{ csrf_token('add_to_favorites') }}">
<button type="submit">Add to Favorites</button>
</form>
{% endif %}
{% endif %} #}
<div id="map" style="width: 600px; height: 400px"></div>
</div>
{% endblock %}