var debug = true; var mapObj = false; var messageObj = false; var timer = false; var icons; var gpsX; var gpsY; var storeX_2050 = 124.243705509; var storeY_2050 = 24.3891857606; var dispStores = new Object(); var focusStoreId = -1; var iconLayer = (function(){ var stores = []; var result = null; function append(id, x, y, marker){ stores.push({id: id, x: x, y: y, marker: marker}); } function getAttributes(id){ stores.forEach((store) => { if(id == store.id){ result = store.marker; return; } }); return result; } // 外部からアクセス可能なプロパティとメソッドを返す return { getAttributes: getAttributes, append: append }; })(); if (typeof(defaultFocusStoreId) !="undefined" && defaultFocusStoreId > 0) { focusStoreId = defaultFocusStoreId; } var messageStoreId = focusStoreId; //メニューを開く数 if (typeof(listOpen) == "undefined" || listOpen == 0) { var listOpen = 10; } var dispStores = new Object(); if (typeof scl === "undefined") { var scl=16; } function _apiRequest(){ if (mapObj == false) { return false; } // GPS は初期表示時のみ動く if (gpsOn == 1 && menuOn == 0) { // 吹き出し位置の調整は行う _attachMessage(messageStoreId); return false; } // マップが表示されない場合は検索を行わない if (gpsOn !=1 && window.innerWidth < 600 && typeof(defaultFocusStoreId) =="undefined") { return false; } var url = location.href; parameters = url.split("?"); // 吹き出し位置の調整 _attachMessage(messageStoreId); } function _attachMessage(storeId){ var store = dispStores[storeId]; if(store && store["location"]){ // 石垣島店のみ離島補正 store.x = storeId != "2050" ? Number(store["location"].split(",")[1]) : storeX_2050; store.y = storeId != "2050" ? Number(store["location"].split(",")[0]) : storeY_2050; var position = new navitime.geo.LatLng(store.y, store.x); var center = mapObj.getCenter(); // 地図の中央からアイコンがどの位置にいるかで吹き出しの表示位置を調整 var messageLeft = 40; var messageTop = -20; var messageLength = store.name ? count_width(store.name) : 0; const tableWidth = messageLength * 11 + 26; // 店名が長いほど左によるので、調整する場合に使用する変数 const adjustLeft = tableWidth / 3 // 店名が長すぎる場合 if(tableWidth > 200) { // 店名を下に if (center.getLat() < position.getLat()) { messageTop = 90; } // 店名を左に if (center.getLng() < position.getLng()) { messageLeft = -adjustLeft } } else{ if (center.getLat() < position.getLat()) { messageTop = 70; } if (center.getLng() < position.getLng()) { messageLeft = -20 - tableWidth + adjustLeft } else{ messageLeft = 20 + adjustLeft } } var options = { map:mapObj, disableClose: true, backgroundColor: '#000000', borderColor: '#000000', margin: '10px', pixelOffset: { x: messageLeft, y: messageTop }, zIndex: 500, tailDirection: '', position: position, content:"
"+correct_store_name(store.name)+"
" }; if(!messageObj){ messageObj = new navitime.geo.overlay.InfoWindow(options); }else{ messageObj.setOptions(options); } messageStoreId = storeId; } } function setMarkerStores(dataItem){ var divList = ""; // 地図表示範囲内の店舗のみ抽出 for (var i = 0; i < dataItem.length; i++) { var _item = dataItem[i]["fields"]; var _storeId = _item.store_id; var detailFlg = 0; dispStores[_storeId] = _item; if ((focusStoreId == _storeId) || (focusStoreId == -1)) { focusStoreId = _storeId; $('.resultStores .item[data-store="'+_storeId+'"]').addClass('is-selected'); detailFlg = 1; } setMarker(_item, detailFlg); } if (typeof(menuOn) != "undefined" && menuOn == 1){ $("#list").prepend(divList); //メニューの初期表示 initList(listOpen); //初期に作ったメニューを変更しない menuOn = 0; } } function makeIcons() { var iconObj= {"storeOpen" : ASSET_PREFIX + '/common/images/storemap/img-icon-open-store.svg', "storeClose" : ASSET_PREFIX + '/common/images/storemap/img-icon-close-store.svg', "storeSelectedOpen" : ASSET_PREFIX + '/common/images/storemap/img-icon-selected-store.svg', "storeSelectedClose" : ASSET_PREFIX + '/common/images/storemap/img-icon-selected-store-close.svg', "storeYou" : ASSET_PREFIX + '/common/images/storemap/img-icon-you-store.png' }; return iconObj; } function isSp() { if (window.innerWidth < 600) { return true; } return false; } function isSpGps() { if (window.innerWidth < 600 && ($("body").hasClass("gps") || location.pathname.match("gps"))) { return true; } return false; } /* * マーカー作成 */ function setMarker(storeData, detailFlg) { if (mapObj == false) { return false; } if(!storeData) return false; //店舗ではない場合は抜ける if(!storeData.store_id) return false; if(Number(storeData.store_id) < 1) return false; var _options; var _zindex; var _icon; if(storeData.isOpen === undefined || storeData.isOpen === null){ storeData.isOpen = isOpen(storeData); } if (detailFlg == 1) { _zindex = 300; if(storeData.isOpen == true){ _icon = icons.storeSelectedOpen; }else{ _icon = icons.storeSelectedClose; } } else { _zindex = 100; if(storeData.isOpen == true){ _icon = icons.storeOpen; }else{ _icon = icons.storeClose; } } var marker = iconLayer.getAttributes(storeData.store_id); if(marker == null){ // 石垣島店のみ離島補正 var x = storeData.store_id != "2050" ? Number(storeData.location.split(",")[1]) : storeX_2050; var y = storeData.store_id != "2050" ? Number(storeData.location.split(",")[0]) : storeY_2050; _options = {icon: _icon, position: new navitime.geo.LatLng(y, x), draggable:false, zIndex: _zindex, map: mapObj, cursor: "pointer", iconPosition: navitime.geo.ControlPosition.CENTER }; marker = new navitime.geo.overlay.Pin(_options); navitime.geo.util.addListener(marker, 'click', function(){ if( typeof(defaultFocusStoreId) !="undefined" && defaultFocusStoreId > 0 && storeData.store_id == defaultFocusStoreId){ return false } location.href = '/detail-' + storeData.store_id + '/' }); navitime.geo.util.addListener(marker, 'mouseover', function(){ _attachMessage(storeData.store_id); }); iconLayer.append(storeData.store_id, x, y, marker); }else{ marker.setZIndex(_zindex); marker.setIcon(_icon); } } //開店中か判定 function isOpen(storeData){ //曜日の判定と24時以降を同日とみなすため、6時間引いて計算する //現在時刻-6時間 var now = new Date(); now.setHours(now.getHours() - 6); var now_week = getWeek(now.getDay()); var now_time = now.getHours() + now.getMinutes() / 60; //臨時休業 //休業日 if(!storeData[now_week+"_open"] || !storeData[now_week+"_close"]){ return false; } var store_open_time = changeStrTime2NumTime(storeData[now_week+"_open"]) - 6; var store_close_time = changeStrTime2NumTime(storeData[now_week+"_close"]) - 6; if(now_time < store_open_time) return false; if(now_time > store_close_time) return false; return true; } function getWeek(num){ var week =["sun", "mon", "tue", "wed", "thu", "fri", "sat"]; return week[parseInt(num)]; } function changeStrTime2NumTime(strTime){ return parseInt(strTime.slice(0,2)) + parseInt(strTime.slice(3,5)) / 60; } //あらかじめ開く数量を入れる。10個開くなら10。 function initList(listCount){ //もっと見るを置く閾値。11個で次を表示が出るのもみっともないから作ったが、とりあえずわかりやすく0としておく。 $(".detailInfo").hide(); var extraCount=0; var countExist = $("#list > li.item").length; if (countExist <= listCount + extraCount){ openList(listCount); }else{ $("#list > li").hide(); openList(listCount); } if(!isSp()){ $(".detailInfo:first").show(); } if (!isSpGps()) { $("#list > li:first").addClass("is-selected"); } //$("#list > li").click(function(e){ $(document).on("click", "#list .item", function(e){ if($(this).children(".detailInfo").is(':visible')){ //表示済み }else{ if ($('.is-selected.item').length == 1) { $(".item").removeClass("is-selected"); $(this).addClass("is-selected"); $(".detailInfo").hide().removeClass("is-selected"); if(!isSp()){ $(this).find(".detailInfo").show().addClass("is-selected"); } $(".storeSearchButtons").hide().removeClass("is-selected"); $(this).find(".storeSearchButtons").show().addClass("is-selected"); } } }); //遷移後のスクロール位置調整 defaultScroll(); } //遷移後のスクロール位置調整 function defaultScroll(){ var offsetTop = 0; var anchor = ''; var headerHeight = 0; if(location.search.match(/anchor_detail=(\d+)/)){ anchor = location.search.match(/anchor_detail=(\d+)/)[1]; } else if(location.search.match(/anchor_location=([\d\.,]+)/)){ anchor = location.search.match(/anchor_location=([\d\.,]+)/)[1]; } else{ $(window).scrollTop(0); return; } setTimeout(function(){ if($('li[data-anchor="'+anchor+'"]')[0]){ offsetTop = $('li[data-anchor="'+anchor+'"]')[0].offsetTop; } $('li[data-anchor="'+anchor+'"]').click(); //SP if(isSp()){ headerHeight = $('.titleArea').height() - $('#meganav2018').height() - $('.local').height() - 36; } else{ headerHeight = $('.local').height() + 33; } $(window).scrollTop(offsetTop - headerHeight); }, 200); } //------------▼店舗リストメニュー開く // listCount : 開くリストの数 function openList(listCount){ for(i=1;i <= listCount;i++ ){ if($("#list > li.item:hidden:first")[0]){ $("#list > li.item:hidden:first").show(); }else{ break; } } // 開き終わる if(!$("#list > li.item:hidden:first")[0]){ $("#moreList").hide(); } } // 店名を正す // (R)を®に変更 function correct_store_name(store_name){ if(!store_name || typeof store_name !== "string") return ""; return store_name.replace(/[\((][RR][\))]/, "®"); } function findRoute(storeId) { var _store = dispStores[storeId]; var device = 'pc'; if (window.innerWidth < 600) { device = 's'; } var x = _store["location_jp"].split(",")[1]*3600; var y = _store["location_jp"].split(",")[0]*3600; var _parameters = 'k1='+mappleKey1+'&k2='+mappleKey2+'&d='+device+'&tab='+text["mapple"]["tab"]+'&rdeco=E00000FF,3,6&rcnd=1,1&rap=55,20&x='+gpsX+'&y='+gpsY+'&rpt4='+gpsX+','+gpsY+','+ x+','+ y; if (isSpGps()) { $('.resultStores .item[data-store_id="'+storeId+'"]').removeClass('is-selected'); $('.overlayBG,.close').css('display','none'); $('.overlayBG,.next,.prev,.list .close,.iconBox').removeClass('on'); } } function count_width(str) { var count = 0; //特殊文字は1文字に変えてカウント str = str.replace(/&\w+;/, "〇"); for(var i=0; i= mapObj.ZOOM_MIN)){ mapObj.zoomTo(zoom, 0, 0); } }