{% extends 'index/layout.html.twig' %}
{% block title %}地図から探す{% endblock %}
{% block stylesheet %}
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css"/>
<link rel="stylesheet" href="/css/map.css">
{% endblock %}
{% block header %}
<header>
<div class="back">
<a href="{{ path('index') }}"><img src="img/detail/arrow.png" alt="戻る"></a>
</div>
<a href="#navi" class="navi-trigger drawer-toggle">
<span class="navi-icon">
<svg x="0px" y="0px" width="54px" height="54px" viewBox="0 0 54 54"></svg>
</span>
</a>
<button id="geolocation" style="" class="btn-location">
<svg height="20px" version="1.1" viewBox="0 0 16 16" width="20px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title/><defs/><g fill="none" fill-rule="evenodd" id="Icons with numbers" stroke="none" stroke-width="1"><g fill="#000000" id="Group" transform="translate(-144.000000, -192.000000)"><path d="M144.017456,200 L160.019653,192.043091 L152,208.088623 L152,200 L144.017456,200 Z M144.017456,200" id="Path 221"/></g></g></svg>
</button>
</header>
{% endblock %}
{% block main %}
<main>
<div id="map-container"></div>
<section>
<div id="map-footer-container" class="footer-panel" style="max-height:300px;">
{# {% for shop in shops %}#}
{# <div class="shop_wr" id="shop-{{ shop.id }}" data-shop="{{ shop.id }}" data-lat="{{ shop.coordinate.latitude }}" data-lng="{{ shop.coordinate.longitude }}">#}
{# <div class="food_wr">#}
{# <ul class="clearfix slick-carousel">#}
{# {% for menu in shop.menus %}#}
{# <li>#}
{# <a href="{{ path('shop', {id: shop.id} )}}" class="shadow"> </a>#}
{# <div class="food_img" style="border-radius: 5px;" data-img="{{ menu.image|default('/img/no-image.jpeg') }}"></div>#}
{# {% if not shop.acceptable %}#}
{# <a href="{{ path('shop', {id: shop.id} )}}" class="shop_unacceptable">受付時間外です</a>#}
{# {% endif %}#}
{# <h3>{{ menu.name }}</h3>#}
{# <div class="price">¥ {{ menu.price|number_format }} -</div>#}
{# </li>#}
{# {% endfor %}#}
{# </ul>#}
{# </div>#}
{# <div class="info_wr">#}
{# <a href="{{ path('shop', {id: shop.id} )}}" class="details_wr">#}
{# <h2>{{ shop.name }}</h2>#}
{# <div class="categories">{{ shop.categories|join(' / ') }}</div>#}
{# <ul class="provide">#}
{# {% if shop.toGo %}<li>テイクアウト</li>{% endif %}#}
{# {% if shop.delivery %}<li>デリバリー</li>{% endif %}#}
{# <li class="indication">提供時間目安 <span>{{ shop.estimatedMinutes|default('-') }}分</span></li>#}
{# </ul>#}
{# </a>#}
{# </div>#}
{# </div>#}
{# {% endfor %}#}
</div>
</section>
</main>
{% endblock %}
{% block js %}
<script async defer src="https://maps.googleapis.com/maps/api/js?language=ja®ion=JP&key=AIzaSyACq30V5WAPj9fOOALRSbMp-sgnuY3N2I4&callback=initMap"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
<script>
var map;
var position = {lat: 36.69084630695481, lng: 137.21299807365202};
var slickOptions = {
variableWidth: true,
arrows: false,
dots: false
};
var bounds;
var pinCache = {};
var currentMarkers = [];
var fetchTimer;
$(function () {
// $('.slick-carousel').slick({
// variableWidth: true,
// arrows: false,
// dots: false
// });
$('#geolocation').click(function () {
if (!navigator.geolocation) {
return false;
}
navigator.geolocation.getCurrentPosition(function (result) {
position = {lat: result.coords.latitude, lng: result.coords.longitude};
map.panTo(position);
});
});
});
// $.ajax({
// url: 'https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyDxtlmq6i3t7yKHPlFdgvRLZh2dN4XnEok',
// method: 'post',
// contentType: 'application/json',
// data: {
//
// },
// crossDomain: true
// }).done(function(data) {
// position = data.location;
// if (map) {
// map.setCenter(position);
// }
// });
function loadPins() {
$.ajax({
url: '/pins?lat1=' + bounds.getSouthWest().lat() + '&lng1=' + bounds.getSouthWest().lng() + '&lat2=' + bounds.getNorthEast().lat() + '&lng2=' + bounds.getNorthEast().lng(),
type: 'json'
}).done(function (json) {
$.each(json, function (key, shop) {
if (!pinCache[shop.id]) {
pinCache[shop.id] = shop;
// Insert HTML
var $html = $(shop.html);
var marker = new google.maps.Marker({
position: {lat: parseFloat(shop.latitude), lng: parseFloat(shop.longitude)},
map: map,
draggable: false,
icon: {
url: '/img/map-marker.png',
scaledSize: new google.maps.Size(40, 40),
size: new google.maps.Size(80, 80),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(20, 38)
}
});
marker.addListener('click', function() {
map.panTo(marker.getPosition());
$('.shop_wr').hide();
$html.show();
$('.footer-panel').toggleClass('open', true);
});
$html.appendTo($('#map-footer-container'));
// $('.slick-carousel').each(function () {
// if (!$(this).is('.slick-initialized')) {
// $(this).find('.food_img').each(function () {
// $(this).css({
// 'background-image': 'url(' + $(this).data('img') + ')'
// })
// });
// $(this).slick(slickOptions);
// }
// });
}
});
});
}
function initMap() {
$(function () {
map = new google.maps.Map($('#map-container').get(0), {
center: position,
zoom: 16,
disableDefaultUI: true
});
map.addListener('click', function () {
$('.footer-panel').toggleClass('open', false);
});
// setTimeout(function () {
// $('[data-shop]').each(function () {
// var markerPosition = {lat: parseFloat($(this).data('lat')), lng: parseFloat($(this).data('lng'))};
//
// var $panel = $(this);
//
// var marker = new google.maps.Marker({
// position: markerPosition,
// map: map,
// draggable: false,
// icon: {
// url: '/img/map-marker.png',
// scaledSize: new google.maps.Size(40, 40),
// size: new google.maps.Size(80, 80),
// origin: new google.maps.Point(0, 0),
// anchor: new google.maps.Point(20, 38)
// }
// });
//
// marker.addListener('click', function() {
// //console.log($panel);
// var $carousel = $panel.find('.slick-carousel');
// map.panTo(marker.getPosition());
// $('.shop_wr').hide();
// if (!$carousel.is('.slick-initialized')) {
// $carousel.find('.food_img').each(function () {
// $(this).css({
// 'background-image': 'url(' + $(this).data('img') + ')'
// })
// });
// $carousel.slick(slickOptions);
// }
// $panel.show();
// $('.footer-panel').toggleClass('open', true);
// });
//
// });
// }, 100);
bounds = map.getBounds();
map.addListener('bounds_changed', function () {
bounds = map.getBounds();
console.log(bounds.getCenter().toString());
//console.log(bounds.getNorthEast().toString(), bounds.getSouthWest().toString());
//loadPins();
if (fetchTimer) {
clearTimeout(fetchTimer);
}
fetchTimer = setTimeout(loadPins, 200);
});
});
}
</script>
{% endblock %}