/* global ZDC */
if (typeof (itsmo) == 'undefined') {
var itsmo = {};
}
if (typeof (itsmo.map.suggest) == 'undefined') {
itsmo.map.suggest = {};
}
itsmo.map.suggest.templateSuggestItem =
"
\
\
\
[suggestName]\
\
\
";
// /map内のサジェストプルダウン
itsmo.map.suggest.getSuggestion = function () {
var word = $.trim($('div #freewd').val());
if (word.length > 0) {
itsmo.suggest.requestSgtData(word, itsmo.map.suggest.setSuggestResult);
} else {
var strHtml = '';
var eSuggestBox = $('div div.suggestion');
eSuggestBox.html(strHtml);
$('div div.suggestion').fadeIn('fast');
}
};
itsmo.map.suggest.setSuggestResult = function (data) {
itsmo.suggest.response = data.result;
var strHtml = '';
var valInput = $.trim($('div #freewd').val());
if (valInput.length > 0) {
let sort = ['genre' , 'station' , 'address' , 'poi'];
for (var i in sort) {
let key = sort[i];
var objKey = data.result[key];
if (data.status.count[key] > 0) {
for (var i = 0; i < objKey.length; i++) {
if (i >= 3) {
break;
}
var html = itsmo.map.suggest.templateSuggestItem;
var suggestFunc = '';
if (key == 'genre') {
suggestFunc = 'itsmo.map.suggest.clickGenreSuggestItem(\'' + key + '\',\'' + i + '\');return false;';
}
if (key == 'station' || key == 'poi' ) {
suggestFunc = 'itsmo.map.suggest.clickSuggestItem(\'' + key + '\',\'' + i + '\');';
} else if (key == 'address'){
suggestFunc = 'itsmo.map.suggest.clickAddrSuggestItem(\'' + i + '\');';
}
html = html.replace(/\[suggestFunc\]/g, suggestFunc);
html = html.replace(/\[classIcon\]/g, 'icon-suggest-' + key);
html = html.replace(/\[suggestName\]/g, objKey[i].nm);
strHtml += html;
}
}
}
}
if (valInput.length > 0) {
strHtml += '- "' + valInput + '"で検索
';
} else {
itsmo.map.history.setHistorySearch($('div form div.suggestion'));
return false;
}
strHtml += '
';
var eSuggestBox = $('div div.suggestion');
eSuggestBox.html(strHtml);
if ($('div #freewd').is(":focus") == true) {
eSuggestBox.fadeIn('fast');
}
};
//座標に遷移し、ログを残す。ほかは調査
itsmo.map.suggest.clickSuggestItem = function (key , i) {
resp = itsmo.suggest.response[key][i];
name = $.trim(resp.nm);
$('#freewd').val(name);
let url ="";
if (key == 'station') {
var index = name.lastIndexOf('駅');
if (index == (name.length - 1)) {
name = name.substring(0, name.length - 1);
}
}
itsmo.lib.localstorage_set(resp , key);
itsmo.range.range_tipclear();
itsmo.spot_range.detail_spot(resp.id, name, 'detail_spot');
itsmo.map.suggest.moveSpot = true;
$('#ajax_leftmenu_result').one("ajaxComplete", function () {
$('#ajax_leftmenu_result').one("ajaxComplete", function () {
var lat = ZDC.msTodeg(itsmo.vars.g_map_setcursor_lat);
var lon = ZDC.msTodeg(itsmo.vars.g_map_setcursor_lon);
var latlon = new ZDC.LatLon(lat, lon);
itsmo.vars.g_map_obj.moveLatLon(latlon);
itsmo.vars.g_map_tab_mode = '';
});
});
};
itsmo.map.suggest.clickGenreSuggestItem = function (key, i) {
resp = itsmo.suggest.response["genre"][i];
$('#freewd').val(resp.nm);
itsmo.lib.localstorage_set(resp , 'genre');
itsmo.range.range_tipclear();
itsmo.range.range(resp.id, '', resp.nm);
$('#ajax_leftmenu_result').one("ajaxComplete", function () {
itsmo.vars.g_map_tab_mode = 'range';
});
};
//住所用 キーのみ
itsmo.map.suggest.clickAddrSuggestItem = function (i){
resp = itsmo.suggest.response["address"][i];
$('#freewd').val(resp.nm);
let url = '/search/addr/' + resp.cd.substr(0,2) + '/' + resp.cd.substr(2,3) + '/' + resp.cd.substr(5,3) + '/';
itsmo.lib.localstorage_set(resp , 'address');
itsmo.addrlist.showPage('detail',resp.cd);
};
//map内、フリーワード、住所はこちら。
itsmo.map.suggest.clickTextSearch = function (word) {
itsmo.lib.localstorage_set(word, "type", "");
$('#freewd').val(word);
itsmo.freeword.freeword_submit();
};