var/cache/review/twig/fe/fe6ae84e185bac133a8df8c62c15d6de.php line 39

Open in your IDE?
  1. <?php
  2. use Twig\Environment;
  3. use Twig\Error\LoaderError;
  4. use Twig\Error\RuntimeError;
  5. use Twig\Extension\SandboxExtension;
  6. use Twig\Markup;
  7. use Twig\Sandbox\SecurityError;
  8. use Twig\Sandbox\SecurityNotAllowedTagError;
  9. use Twig\Sandbox\SecurityNotAllowedFilterError;
  10. use Twig\Sandbox\SecurityNotAllowedFunctionError;
  11. use Twig\Source;
  12. use Twig\Template;
  13. /* Map/page.html.twig */
  14. class __TwigTemplate_a28a045d3be3f3299f645cdfe29370c8 extends Template
  15. {
  16.     private $source;
  17.     private $macros = [];
  18.     public function __construct(Environment $env)
  19.     {
  20.         parent::__construct($env);
  21.         $this->source $this->getSourceContext();
  22.         $this->blocks = [
  23.             'mainContainer' => [$this'block_mainContainer'],
  24.             'javascripts' => [$this'block_javascripts'],
  25.         ];
  26.     }
  27.     protected function doGetParent(array $context)
  28.     {
  29.         // line 1
  30.         return "grid.html.twig";
  31.     }
  32.     protected function doDisplay(array $context, array $blocks = [])
  33.     {
  34.         $macros $this->macros;
  35.         $__internal_b91a4435ea3baf1e2b6bfda56133dace $this->extensions["Sentry\\SentryBundle\\Tracing\\Twig\\TwigTracingExtension"];
  36.         $__internal_b91a4435ea3baf1e2b6bfda56133dace->enter($__internal_b91a4435ea3baf1e2b6bfda56133dace_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template""Map/page.html.twig"));
  37.         $__internal_5a27a8ba21ca79b61932376b2fa922d2 $this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"];
  38.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->enter($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template""Map/page.html.twig"));
  39.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
  40.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "template""Map/page.html.twig"));
  41.         $this->parent $this->loadTemplate("grid.html.twig""Map/page.html.twig"1);
  42.         $this->parent->display($contextarray_merge($this->blocks$blocks));
  43.         
  44.         $__internal_b91a4435ea3baf1e2b6bfda56133dace->leave($__internal_b91a4435ea3baf1e2b6bfda56133dace_prof);
  45.         
  46.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->leave($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof);
  47.         
  48.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);
  49.     }
  50.     // line 3
  51.     public function block_mainContainer($context, array $blocks = [])
  52.     {
  53.         $macros $this->macros;
  54.         $__internal_b91a4435ea3baf1e2b6bfda56133dace $this->extensions["Sentry\\SentryBundle\\Tracing\\Twig\\TwigTracingExtension"];
  55.         $__internal_b91a4435ea3baf1e2b6bfda56133dace->enter($__internal_b91a4435ea3baf1e2b6bfda56133dace_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""mainContainer"));
  56.         $__internal_5a27a8ba21ca79b61932376b2fa922d2 $this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"];
  57.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->enter($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""mainContainer"));
  58.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
  59.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""mainContainer"));
  60.         // line 4
  61.         echo "   ";
  62.         // line 5
  63.         echo "    <div id=\"map_form\"></div>
  64.     <img src=\"";
  65.         // line 6
  66.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("/static/preloader.gif"), "html"nulltrue);
  67.         echo "\" id=\"preloader\" style=\"display: none;\" />
  68.     <div id=\"map\"
  69.          data-city-uri-idenity=\"";
  70.         // line 8
  71.         echo twig_escape_filter($this->env, (isset($context["cityUriIdentity"]) || array_key_exists("cityUriIdentity"$context) ? $context["cityUriIdentity"] : (function () { throw new RuntimeError('Variable "cityUriIdentity" does not exist.'8$this->source); })()), "html"nulltrue);
  72.         echo "\"
  73.          data-city-latitude=\"";
  74.         // line 9
  75.         echo twig_escape_filter($this->env, (isset($context["cityLatitude"]) || array_key_exists("cityLatitude"$context) ? $context["cityLatitude"] : (function () { throw new RuntimeError('Variable "cityLatitude" does not exist.'9$this->source); })()), "html"nulltrue);
  76.         echo "\"
  77.          data-city-longitude=\"";
  78.         // line 10
  79.         echo twig_escape_filter($this->env, (isset($context["cityLongitude"]) || array_key_exists("cityLongitude"$context) ? $context["cityLongitude"] : (function () { throw new RuntimeError('Variable "cityLongitude" does not exist.'10$this->source); })()), "html"nulltrue);
  80.         echo "\"
  81.          style=\"width:100%; height:500px;\"></div>
  82. ";
  83.         
  84.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);
  85.         
  86.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->leave($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof);
  87.         
  88.         $__internal_b91a4435ea3baf1e2b6bfda56133dace->leave($__internal_b91a4435ea3baf1e2b6bfda56133dace_prof);
  89.     }
  90.     // line 14
  91.     public function block_javascripts($context, array $blocks = [])
  92.     {
  93.         $macros $this->macros;
  94.         $__internal_b91a4435ea3baf1e2b6bfda56133dace $this->extensions["Sentry\\SentryBundle\\Tracing\\Twig\\TwigTracingExtension"];
  95.         $__internal_b91a4435ea3baf1e2b6bfda56133dace->enter($__internal_b91a4435ea3baf1e2b6bfda56133dace_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""javascripts"));
  96.         $__internal_5a27a8ba21ca79b61932376b2fa922d2 $this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"];
  97.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->enter($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""javascripts"));
  98.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
  99.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block""javascripts"));
  100.         // line 15
  101.         echo "    <script src=\"";
  102.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("bundles/fosjsrouting/js/router.min.js"), "html"nulltrue);
  103.         echo "\"></script>
  104.     <script src=\"";
  105.         // line 16
  106.         echo $this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("fos_js_routing_js", ["callback" => "fos.Router.setData"]);
  107.         echo "\"></script>
  108.     <script src=\"https://code.jquery.com/jquery-3.4.1.min.js\"></script>
  109.     <script src=\"https://api-maps.yandex.ru/2.1/?lang=ru_RU\" type=\"text/javascript\"></script>
  110.     <script type=\"text/javascript\">
  111.         ;var RoutingDecorator = {
  112.             generate: function (name, params) {
  113.                 const orig_name = name;
  114.                 try {
  115.                     Routing.getRoute(name)
  116.                 } catch(error) {
  117.                     name = name + '.' + '";
  118.         // line 27
  119.         echo twig_escape_filter($this->envtwig_get_attribute($this->env$this->sourcetwig_get_attribute($this->env$this->source, (isset($context["app"]) || array_key_exists("app"$context) ? $context["app"] : (function () { throw new RuntimeError('Variable "app" does not exist.'27$this->source); })()), "request", [], "any"falsefalsefalse27), "locale", [], "any"falsefalsefalse27), "html"nulltrue);
  120.         echo "';
  121.                     try {
  122.                         Routing.getRoute(name)
  123.                     } catch(error) {
  124.                         name = orig_name;
  125.                     }
  126.                 }
  127.                 return Routing.generate(name, params);
  128.             }
  129.         };
  130.         ;(function () {
  131.             document.addEventListener('DOMContentLoaded', _ => {
  132.                 var avatarPath = '";
  133.         // line 42
  134.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("""profile_media_avatar"), "html"nulltrue);
  135.         echo "';
  136.                 var photoPath = '";
  137.         // line 43
  138.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("""profile_media"), "html"nulltrue);
  139.         echo "';
  140.                 var thumbPath = '";
  141.         // line 44
  142.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\AssetExtension']->getAssetUrl("""saloon_media_thumb"), "html"nulltrue);
  143.         echo "';
  144.                 var mapContainer = document.querySelector('#map');
  145.                 var preloader = document.querySelector('#preloader');
  146.                 var cityUriIdentity = mapContainer.getAttribute('data-city-uri-idenity');
  147.                 var cityLatitude = mapContainer.getAttribute('data-city-latitude');
  148.                 var cityLongitude = mapContainer.getAttribute('data-city-longitude');
  149.                 var formName = 'filter_map_form';
  150.                 var multipleCities = ";
  151.         // line 51
  152.         echo twig_escape_filter($this->env, (isset($context["multipleCities"]) || array_key_exists("multipleCities"$context) ? $context["multipleCities"] : (function () { throw new RuntimeError('Variable "multipleCities" does not exist.'51$this->source); })()), "html"nulltrue);
  153.         echo ";
  154.                 var routesUrl = '/js/fos_js_routes";
  155.         // line 52
  156.         echo (((isset($context["multipleCities"]) || array_key_exists("multipleCities"$context) ? $context["multipleCities"] : (function () { throw new RuntimeError('Variable "multipleCities" does not exist.'52$this->source); })())) ? ("_city_prefixed") : (""));
  157.         echo ".json';
  158.                 loadRoutes();
  159.                 var myMap, clusterer;
  160.                 ymaps.ready(function () {
  161.                     myMap = new ymaps.Map('map', {
  162.                             center: [cityLatitude, cityLongitude],
  163.                             zoom: 9,
  164.                             behaviors: ['default', 'scrollZoom']
  165.                         }, {
  166.                             searchControlProvider: 'yandex#search'
  167.                         });
  168.                     clusterer = new ymaps.Clusterer({
  169.                             preset: 'islands#invertedVioletClusterIcons',//Через кластеризатор можно указать только стили кластеров,стили для меток нужно назначать каждой метке отдельно.
  170.                             groupByCoordinates: false,//Ставим true, если хотим кластеризовать только точки с одинаковыми координатами.
  171.                             //Опции кластеров указываем в кластеризаторе с префиксом \"cluster\".
  172.                             clusterDisableClickZoom: true,
  173.                             clusterHideIconOnBalloonOpen: false,
  174.                             geoObjectHideIconOnBalloonOpen: false
  175.                     });
  176.                     // Можно менять опции кластеризатора после создания.
  177.                     clusterer.options.set({
  178.                         gridSize: 80,
  179.                         clusterDisableClickZoom: true
  180.                     });
  181.                     loadForm();
  182.                 });
  183.                 function loadRoutes() {
  184.                     \$.ajax({
  185.                         url:routesUrl,
  186.                         dataType: \"json\",
  187.                         async: false,
  188.                         success: function (routes) {
  189.                             Routing.setRoutingData(routes);
  190.                         },
  191.                         error: function (xhr, ajaxOptions, thrownError) {}
  192.                     });
  193.                 }
  194.                 function setFormSubmitListener() {
  195.                     document.querySelector(\"form[name=\"+formName+\"]\").addEventListener('submit', function(e){
  196.                         e.preventDefault();
  197.                         if(!clusterer)
  198.                             return;
  199.                         filterData();
  200.                         return false;
  201.                     });
  202.                 }
  203.                 function loadForm() {
  204.                     fetch('";
  205.         // line 108
  206.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("map.form", ["city" => (isset($context["cityUriIdentity"]) || array_key_exists("cityUriIdentity"$context) ? $context["cityUriIdentity"] : (function () { throw new RuntimeError('Variable "cityUriIdentity" does not exist.'108$this->source); })())]), "html"nulltrue);
  207.         echo "', {
  208.                         mode: \"cors\",
  209.                         importance: \"low\",
  210.                         method: \"POST\",
  211.                         headers: {
  212.                             \"Content-Type\": \"application/x-www-form-urlencoded\",
  213.                             \"X-Requested-With\": \"XMLHttpRequest\"
  214.                         },
  215.                     }).then(response => {
  216.                         if (response.status < 300) {
  217.                             return response.text();
  218.                         } else {
  219.                             console.warn(\"🤔\");
  220.                             return null;
  221.                         }
  222.                     }).then(response => {
  223.                         document.querySelector('#map_form').innerHTML = response;
  224.                         filterData();
  225.                         setFormSubmitListener();
  226.                     });
  227.                 }
  228.                 function filterData() {
  229.                     preloader.style.display = 'block';
  230.                     var data = {};
  231.                     \$(\"form[name=\"+formName+\"]\").serializeArray().forEach((object)=>{
  232.                         //\"подгоняем\" данные под формат, ожидаемый формой при сабмите
  233.                         var fieldName = object.name.toString().replace(formName + '[', '').replace(']', '');
  234.                         var clearFieldName = fieldName.substr(0, fieldName.indexOf('['));
  235.                         if(~fieldName.indexOf('[]')) {
  236.                             checkArrayIsInFormObject(clearFieldName, data);
  237.                             data[clearFieldName].push(object.value);
  238.                         } else if(~fieldName.indexOf('[m')) {
  239.                             if(!object.value)
  240.                                 return;
  241.                             checkObjectIsInFormObject(clearFieldName, data);
  242.                             if(~fieldName.indexOf('[min]'))
  243.                                 data[clearFieldName]['min'] = object.value;
  244.                             if(~fieldName.indexOf('[max]'))
  245.                                 data[clearFieldName]['max'] = object.value;
  246.                         } else {
  247.                             data[fieldName] = object.value;
  248.                         }
  249.                     });
  250.                     \$.ajax({
  251.                         url:'";
  252.         // line 158
  253.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("map.filter", ["city" => (isset($context["cityUriIdentity"]) || array_key_exists("cityUriIdentity"$context) ? $context["cityUriIdentity"] : (function () { throw new RuntimeError('Variable "cityUriIdentity" does not exist.'158$this->source); })())]), "html"nulltrue);
  254.         echo "',
  255.                         type: \"POST\",
  256.                         dataType: \"json\",
  257.                         data: {
  258.                             \"form\": JSON.stringify(data),
  259.                         },
  260.                         async: true,
  261.                         success: function (return_data) {
  262.                             // console.log(return_data);
  263.                             updateMap(return_data);
  264.                             preloader.style.display = 'none';
  265.                         },
  266.                         error: function (xhr, ajaxOptions, thrownError) {}
  267.                     });
  268.                 }
  269.                 function checkArrayIsInFormObject(name, formObject) {
  270.                     if(false == formObject.hasOwnProperty(name))
  271.                         formObject[name] = [];
  272.                 }
  273.                 function checkObjectIsInFormObject(name, formObject) {
  274.                     if(false == formObject.hasOwnProperty(name))
  275.                         formObject[name] = {};
  276.                 }
  277.                 function updateMap(points) {
  278.                     clusterer.removeAll();
  279.                     if(!points || !points.length)
  280.                         return;
  281.                     var getImgUrl = function(path, imgType) {
  282.                         if(path[0] == '/')
  283.                             return path;
  284.                         var assetPackagePath = '';
  285.                         if(imgType == 'avatar')
  286.                             assetPackagePath = avatarPath;
  287.                         else if(imgType == 'photo')
  288.                             assetPackagePath = photoPath;
  289.                         if(imgType == 'thumb')
  290.                             assetPackagePath = thumbPath;
  291.                         return assetPackagePath + path;
  292.                     };
  293.                     var getPointData = function (index) {
  294.                         const data = points[index];
  295.                         const isProfile = data[0] == 1;
  296.                         const isSaloon = data[0] == 2;
  297.                         let url = '';
  298.                         const uri = data[3];
  299.                         if(isProfile) {
  300.                             url = RoutingDecorator.generate(
  301.                                 'profile_preview.page',
  302.                                 multipleCities ? {city: cityUriIdentity, profile: uri} : {profile: uri}
  303.                             );
  304.                         } else if(isSaloon) {
  305.                             url = RoutingDecorator.generate(
  306.                                 'saloon_preview.page',
  307.                                 multipleCities ? {city: cityUriIdentity, saloon: uri} : {saloon: uri}
  308.                             );
  309.                         }
  310.                         var processProfileShowsUrl = '";
  311.         // line 224
  312.         echo twig_escape_filter($this->env$this->extensions['Symfony\Bridge\Twig\Extension\RoutingExtension']->getPath("map.increment_profile_shows", (((isset($context["multipleCities"]) || array_key_exists("multipleCities"$context) ? $context["multipleCities"] : (function () { throw new RuntimeError('Variable "multipleCities" does not exist.'224$this->source); })())) ? (["city" => (isset($context["cityUriIdentity"]) || array_key_exists("cityUriIdentity"$context) ? $context["cityUriIdentity"] : (function () { throw new RuntimeError('Variable "cityUriIdentity" does not exist.'224$this->source); })())]) : ([]))), "html"nulltrue);
  313.         echo "';
  314.                         return {
  315.                             balloonContentHeader: '',
  316.                             balloonContentBody: '<p><img src=\"' + getImgUrl(data[5], isProfile ? 'avatar' : 'thumb') + '\" width=\"100\" /></p>' + '<font size=3><b><a target=\"_blank\" href=\"' + url + '\">Профиль</a></b></font>'
  317.                                 + '<img style=\"display:none;\" width=\"0\" height=\"0\" src=\"' + processProfileShowsUrl + '?id=' + (isProfile ? data[9] : null)+'\" />', //не убирать, функционально важно
  318.                             balloonContentFooter: '<font size=1>' + data[8] + ',' + data[9] + ',' + data[10] + '</strong>',
  319.                             clusterCaption: '<strong>' + (isSaloon ? 'Салон ' : '') + data[4] + '</strong>'
  320.                         };
  321.                     };
  322.                     var getPointOptions = function (index, type) {
  323.                         return {
  324.                             preset: type == 'profile' ? 'islands#violetIcon' : 'islands#redIcon'
  325.                         };
  326.                     };
  327.                     var geoObjects = [];
  328.                     for(var i = 0, len = points.length; i < len; i++)
  329.                         geoObjects[i] = new ymaps.Placemark([points[i][1], points[i][2]], getPointData(i), getPointOptions(i, points[i][0] == 1));
  330.                     //В кластеризатор можно добавить javascript-массив меток (не геоколлекцию) или одну метку.
  331.                     clusterer.add(geoObjects);
  332.                     myMap.geoObjects.add(clusterer);
  333.                     // Спозиционируем карту так, чтобы на ней были видны все объекты.
  334.                     myMap.setBounds(clusterer.getBounds(), {
  335.                         checkZoomRange: true
  336.                     });
  337.                 }
  338.             });
  339.         })();
  340.     </script>
  341. ";
  342.         
  343.         $__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);
  344.         
  345.         $__internal_5a27a8ba21ca79b61932376b2fa922d2->leave($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof);
  346.         
  347.         $__internal_b91a4435ea3baf1e2b6bfda56133dace->leave($__internal_b91a4435ea3baf1e2b6bfda56133dace_prof);
  348.     }
  349.     /**
  350.      * @codeCoverageIgnore
  351.      */
  352.     public function getTemplateName()
  353.     {
  354.         return "Map/page.html.twig";
  355.     }
  356.     /**
  357.      * @codeCoverageIgnore
  358.      */
  359.     public function isTraitable()
  360.     {
  361.         return false;
  362.     }
  363.     /**
  364.      * @codeCoverageIgnore
  365.      */
  366.     public function getDebugInfo()
  367.     {
  368.         return array (  365 => 224,  296 => 158,  243 => 108,  184 => 52,  180 => 51,  170 => 44,  166 => 43,  162 => 42,  144 => 27,  130 => 16,  125 => 15,  112 => 14,  96 => 10,  92 => 9,  88 => 8,  83 => 6,  80 => 5,  78 => 4,  65 => 3,  36 => 1,);
  369.     }
  370.     public function getSourceContext()
  371.     {
  372.         return new Source("{% extends 'grid.html.twig' %}
  373. {% block mainContainer %}
  374.    {# {{ form(form) }}#}
  375.     <div id=\"map_form\"></div>
  376.     <img src=\"{{ asset('/static/preloader.gif') }}\" id=\"preloader\" style=\"display: none;\" />
  377.     <div id=\"map\"
  378.          data-city-uri-idenity=\"{{ cityUriIdentity }}\"
  379.          data-city-latitude=\"{{ cityLatitude }}\"
  380.          data-city-longitude=\"{{ cityLongitude }}\"
  381.          style=\"width:100%; height:500px;\"></div>
  382. {% endblock %}
  383. {% block javascripts %}
  384.     <script src=\"{{ asset('bundles/fosjsrouting/js/router.min.js') }}\"></script>
  385.     <script src=\"{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}\"></script>
  386.     <script src=\"https://code.jquery.com/jquery-3.4.1.min.js\"></script>
  387.     <script src=\"https://api-maps.yandex.ru/2.1/?lang=ru_RU\" type=\"text/javascript\"></script>
  388.     <script type=\"text/javascript\">
  389.         ;var RoutingDecorator = {
  390.             generate: function (name, params) {
  391.                 const orig_name = name;
  392.                 try {
  393.                     Routing.getRoute(name)
  394.                 } catch(error) {
  395.                     name = name + '.' + '{{ app.request.locale }}';
  396.                     try {
  397.                         Routing.getRoute(name)
  398.                     } catch(error) {
  399.                         name = orig_name;
  400.                     }
  401.                 }
  402.                 return Routing.generate(name, params);
  403.             }
  404.         };
  405.         ;(function () {
  406.             document.addEventListener('DOMContentLoaded', _ => {
  407.                 var avatarPath = '{{ asset('', 'profile_media_avatar') }}';
  408.                 var photoPath = '{{ asset('', 'profile_media') }}';
  409.                 var thumbPath = '{{ asset('', 'saloon_media_thumb') }}';
  410.                 var mapContainer = document.querySelector('#map');
  411.                 var preloader = document.querySelector('#preloader');
  412.                 var cityUriIdentity = mapContainer.getAttribute('data-city-uri-idenity');
  413.                 var cityLatitude = mapContainer.getAttribute('data-city-latitude');
  414.                 var cityLongitude = mapContainer.getAttribute('data-city-longitude');
  415.                 var formName = 'filter_map_form';
  416.                 var multipleCities = {{ multipleCities }};
  417.                 var routesUrl = '/js/fos_js_routes{{ multipleCities ? '_city_prefixed' }}.json';
  418.                 loadRoutes();
  419.                 var myMap, clusterer;
  420.                 ymaps.ready(function () {
  421.                     myMap = new ymaps.Map('map', {
  422.                             center: [cityLatitude, cityLongitude],
  423.                             zoom: 9,
  424.                             behaviors: ['default', 'scrollZoom']
  425.                         }, {
  426.                             searchControlProvider: 'yandex#search'
  427.                         });
  428.                     clusterer = new ymaps.Clusterer({
  429.                             preset: 'islands#invertedVioletClusterIcons',//Через кластеризатор можно указать только стили кластеров,стили для меток нужно назначать каждой метке отдельно.
  430.                             groupByCoordinates: false,//Ставим true, если хотим кластеризовать только точки с одинаковыми координатами.
  431.                             //Опции кластеров указываем в кластеризаторе с префиксом \"cluster\".
  432.                             clusterDisableClickZoom: true,
  433.                             clusterHideIconOnBalloonOpen: false,
  434.                             geoObjectHideIconOnBalloonOpen: false
  435.                     });
  436.                     // Можно менять опции кластеризатора после создания.
  437.                     clusterer.options.set({
  438.                         gridSize: 80,
  439.                         clusterDisableClickZoom: true
  440.                     });
  441.                     loadForm();
  442.                 });
  443.                 function loadRoutes() {
  444.                     \$.ajax({
  445.                         url:routesUrl,
  446.                         dataType: \"json\",
  447.                         async: false,
  448.                         success: function (routes) {
  449.                             Routing.setRoutingData(routes);
  450.                         },
  451.                         error: function (xhr, ajaxOptions, thrownError) {}
  452.                     });
  453.                 }
  454.                 function setFormSubmitListener() {
  455.                     document.querySelector(\"form[name=\"+formName+\"]\").addEventListener('submit', function(e){
  456.                         e.preventDefault();
  457.                         if(!clusterer)
  458.                             return;
  459.                         filterData();
  460.                         return false;
  461.                     });
  462.                 }
  463.                 function loadForm() {
  464.                     fetch('{{ path('map.form', {city: cityUriIdentity}) }}', {
  465.                         mode: \"cors\",
  466.                         importance: \"low\",
  467.                         method: \"POST\",
  468.                         headers: {
  469.                             \"Content-Type\": \"application/x-www-form-urlencoded\",
  470.                             \"X-Requested-With\": \"XMLHttpRequest\"
  471.                         },
  472.                     }).then(response => {
  473.                         if (response.status < 300) {
  474.                             return response.text();
  475.                         } else {
  476.                             console.warn(\"🤔\");
  477.                             return null;
  478.                         }
  479.                     }).then(response => {
  480.                         document.querySelector('#map_form').innerHTML = response;
  481.                         filterData();
  482.                         setFormSubmitListener();
  483.                     });
  484.                 }
  485.                 function filterData() {
  486.                     preloader.style.display = 'block';
  487.                     var data = {};
  488.                     \$(\"form[name=\"+formName+\"]\").serializeArray().forEach((object)=>{
  489.                         //\"подгоняем\" данные под формат, ожидаемый формой при сабмите
  490.                         var fieldName = object.name.toString().replace(formName + '[', '').replace(']', '');
  491.                         var clearFieldName = fieldName.substr(0, fieldName.indexOf('['));
  492.                         if(~fieldName.indexOf('[]')) {
  493.                             checkArrayIsInFormObject(clearFieldName, data);
  494.                             data[clearFieldName].push(object.value);
  495.                         } else if(~fieldName.indexOf('[m')) {
  496.                             if(!object.value)
  497.                                 return;
  498.                             checkObjectIsInFormObject(clearFieldName, data);
  499.                             if(~fieldName.indexOf('[min]'))
  500.                                 data[clearFieldName]['min'] = object.value;
  501.                             if(~fieldName.indexOf('[max]'))
  502.                                 data[clearFieldName]['max'] = object.value;
  503.                         } else {
  504.                             data[fieldName] = object.value;
  505.                         }
  506.                     });
  507.                     \$.ajax({
  508.                         url:'{{ path('map.filter', {city:cityUriIdentity}) }}',
  509.                         type: \"POST\",
  510.                         dataType: \"json\",
  511.                         data: {
  512.                             \"form\": JSON.stringify(data),
  513.                         },
  514.                         async: true,
  515.                         success: function (return_data) {
  516.                             // console.log(return_data);
  517.                             updateMap(return_data);
  518.                             preloader.style.display = 'none';
  519.                         },
  520.                         error: function (xhr, ajaxOptions, thrownError) {}
  521.                     });
  522.                 }
  523.                 function checkArrayIsInFormObject(name, formObject) {
  524.                     if(false == formObject.hasOwnProperty(name))
  525.                         formObject[name] = [];
  526.                 }
  527.                 function checkObjectIsInFormObject(name, formObject) {
  528.                     if(false == formObject.hasOwnProperty(name))
  529.                         formObject[name] = {};
  530.                 }
  531.                 function updateMap(points) {
  532.                     clusterer.removeAll();
  533.                     if(!points || !points.length)
  534.                         return;
  535.                     var getImgUrl = function(path, imgType) {
  536.                         if(path[0] == '/')
  537.                             return path;
  538.                         var assetPackagePath = '';
  539.                         if(imgType == 'avatar')
  540.                             assetPackagePath = avatarPath;
  541.                         else if(imgType == 'photo')
  542.                             assetPackagePath = photoPath;
  543.                         if(imgType == 'thumb')
  544.                             assetPackagePath = thumbPath;
  545.                         return assetPackagePath + path;
  546.                     };
  547.                     var getPointData = function (index) {
  548.                         const data = points[index];
  549.                         const isProfile = data[0] == 1;
  550.                         const isSaloon = data[0] == 2;
  551.                         let url = '';
  552.                         const uri = data[3];
  553.                         if(isProfile) {
  554.                             url = RoutingDecorator.generate(
  555.                                 'profile_preview.page',
  556.                                 multipleCities ? {city: cityUriIdentity, profile: uri} : {profile: uri}
  557.                             );
  558.                         } else if(isSaloon) {
  559.                             url = RoutingDecorator.generate(
  560.                                 'saloon_preview.page',
  561.                                 multipleCities ? {city: cityUriIdentity, saloon: uri} : {saloon: uri}
  562.                             );
  563.                         }
  564.                         var processProfileShowsUrl = '{{ path('map.increment_profile_shows', multipleCities ? {city:cityUriIdentity} : {}) }}';
  565.                         return {
  566.                             balloonContentHeader: '',
  567.                             balloonContentBody: '<p><img src=\"' + getImgUrl(data[5], isProfile ? 'avatar' : 'thumb') + '\" width=\"100\" /></p>' + '<font size=3><b><a target=\"_blank\" href=\"' + url + '\">Профиль</a></b></font>'
  568.                                 + '<img style=\"display:none;\" width=\"0\" height=\"0\" src=\"' + processProfileShowsUrl + '?id=' + (isProfile ? data[9] : null)+'\" />', //не убирать, функционально важно
  569.                             balloonContentFooter: '<font size=1>' + data[8] + ',' + data[9] + ',' + data[10] + '</strong>',
  570.                             clusterCaption: '<strong>' + (isSaloon ? 'Салон ' : '') + data[4] + '</strong>'
  571.                         };
  572.                     };
  573.                     var getPointOptions = function (index, type) {
  574.                         return {
  575.                             preset: type == 'profile' ? 'islands#violetIcon' : 'islands#redIcon'
  576.                         };
  577.                     };
  578.                     var geoObjects = [];
  579.                     for(var i = 0, len = points.length; i < len; i++)
  580.                         geoObjects[i] = new ymaps.Placemark([points[i][1], points[i][2]], getPointData(i), getPointOptions(i, points[i][0] == 1));
  581.                     //В кластеризатор можно добавить javascript-массив меток (не геоколлекцию) или одну метку.
  582.                     clusterer.add(geoObjects);
  583.                     myMap.geoObjects.add(clusterer);
  584.                     // Спозиционируем карту так, чтобы на ней были видны все объекты.
  585.                     myMap.setBounds(clusterer.getBounds(), {
  586.                         checkZoomRange: true
  587.                     });
  588.                 }
  589.             });
  590.         })();
  591.     </script>
  592. {% endblock %}""Map/page.html.twig""/app/templates/Map/page.html.twig");
  593.     }
  594. }