templates/all_tyre/inwidth.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Hello AllTyreController!{% endblock %}
  3. {% block body %}
  4. <script>
  5. let coordinat;
  6. let xy;
  7. function getPos() {
  8.     var loca = {{ product.location|json_encode|raw }};
  9.     fetch('https://geocode-maps.yandex.ru/1.x/?apikey=0b8c32a5-05a1-4b77-8b56-b0668e11d9e0&format=json&geocode='+loca)
  10.           .then(response => response.json())
  11.           .then(data => {
  12.             // console.log(data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos);
  13.             coordinat = data.response.GeoObjectCollection.featureMember[0].GeoObject.Point.pos;
  14.             xy = coordinat.split(' ');
  15.             let pos1 = xy[0];
  16.               let pos2 = xy[1];
  17.               main(pos1, pos2);
  18.         })
  19.           .catch(error => console.error(error));
  20. }
  21. getPos();
  22. async function main(pos1, pos2) {
  23.     // Промис `ymaps3.ready` будет зарезолвлен, когда
  24.     // загрузятся все компоненты API.
  25.     await ymaps3.ready;
  26.     // Создание карты.
  27.     const map = new ymaps3.YMap(document.getElementById('map'), {
  28.            location: {
  29.             // Координаты центра карты.
  30.             // Порядок по умолчанию: «долгота, широта».
  31.             center: [pos1, pos2],
  32.             // Уровень масштабирования. Допустимые значения:
  33.             // от 0 (весь мир) до 19.
  34.             zoom: 17
  35.            }
  36.     },
  37.     [
  38.         // Добавляем слой для отображения схематической карты.
  39.            new ymaps3.YMapDefaultSchemeLayer()
  40.     ]
  41.     )
  42.     map.addChild(new ymaps3.YMapDefaultFeaturesLayer()); // В этом слое будут маркеры.
  43.     // DOM-элемент должен быть создан заранее, но его содержимое можно задать в любой момент.
  44.     const content = document.createElement('section');
  45.     const marker = new ymaps3.YMapMarker({
  46.         coordinates: [pos1, pos2],
  47.         draggable: true
  48.     }, content);
  49.     map.addChild(marker);
  50.     content.innerHTML = '<h1>O</h1>';
  51. }
  52. </script>
  53. <div class="container">
  54.     <h2 class="display-3">Автор - {{ product.name }}</h2>
  55.     <h2 class="display-5">{{ product.fstring }}</h2>
  56.     <h2 class="display-5">Цена - {{ product.price }}</h2>
  57.     <h2 class="display-5">Адресс - {{ product.location }}</h2>
  58.     <img style="height: 90px;" class="img-fluid" src="{{ asset('uploads/images/' ~ product.path) }}">
  59.     {% if is_granted('ROLE_USER') %}
  60.     <form action="{{ path('add_to_favorites', { 'productId': product.id }) }}" method="POST">
  61.         <input type="hidden" name="_csrf_token" value="{{ csrf_token('add_to_favorites') }}">
  62.         <button type="submit">
  63.             Добавить 
  64.             <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-bag-heart" viewBox="0 0 16 16">
  65.                   <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"/>
  66.             </svg>
  67.         </button>
  68.     </form>
  69.     {% endif %}
  70. {#     {% if is_granted('ROLE_USER') %}
  71.         {% if product.isFavorite %}
  72.             <form action="{{ path('remove_from_favorites', { 'productId': product.id }) }}" method="POST"> <input type="hidden" name="_csrf_token" value="{{ csrf_token('remove_from_favorites') }}">
  73.                 <button type="submit">Remove from Favorites</button>
  74.             </form>
  75.         {% else %}
  76.             <form action="{{ path('add_to_favorites', { 'productId': product.id }) }}" method="POST"> <input type="hidden" name="_csrf_token" value="{{ csrf_token('add_to_favorites') }}">
  77.                 <button type="submit">Add to Favorites</button>
  78.                 </form>
  79.             {% endif %}
  80.         {% endif %} #}
  81.     <div id="map" style="width: 600px; height: 400px"></div>
  82. </div>
  83. {% endblock %}