eval('/*#start#*/'); (function() { var ZDC = window['ZDC']; var gl = {}; // このスコープ内で共通で使う変数を格納する gl._f = Boolean(0); gl._t = Boolean(1); ZDC.Moyori = ZDC['Moyori'] = function(latlon, opt, callback){ this._center = latlon; this._opt = opt || {}; //add 2019/09/12 MLAB PhongTrinh - add options move map to moyori icon center. this._opt.movemap = (typeof this._opt.movemap == "undefined") ? true : this._opt.movemap; this._marker = gl._marker = new ZDC['Marker'](this._center, this._opt['icon']); this._isSearching = gl._f; this._isDragging = gl._f; this._mrks = []; this._lines = []; this._diffLatLon; this._ov; this._msg; this._genreResultList = {}; this._latlons = []; this._iconContainer = {}; this.map = opt['map']; this.callback = callback; this._checkInitOption(); if (opt['map']) { this._setEventListeners() } else { this._addListeners(); } }; /* 継承 */ //ZDC.Moyori.prototype = _pp(_WidgetCore); function _deleteArrayContents(arr) { if (!arr) { return; } if (arr._remove) { arr._remove(); } if (!arr.length) { this.map['removeWidget'](arr); } else { for (var i = 0; i < arr.length; i++) { this.map['removeWidget'](arr[i]); } } } ZDC.Moyori.prototype['_add'] = function() { if (this._isSearching) { return; } this.map = this.manager.map; ZDC['trigger'](this, ZDC['ADD_MAP']); }; ZDC.Moyori.prototype['_remove'] = function() { if (this._isSearching) { return; } _deleteArrayContents(this._marker) _deleteArrayContents(this._lines) _deleteArrayContents(this._mrks) _deleteArrayContents(this._ov) _deleteArrayContents(this._msg) }; ZDC.Moyori.prototype._checkInitOption = function() { var opt = this._opt; this.genre = {}; var size = 0; if (opt['genre']) { size = (opt['genre'].length > 3) ? 3 : opt['genre'].length; } this._genreSize = size; for (var i = 0; i < size; i++) { if (opt['genre'][i]) { this.genre[opt['genre'][i].code] = opt['genre'][i]; } } _checkParam(opt, 'radius', 500, 3000); _checkParam(opt, 'maxdisp', 3, 10); opt.searchlimit = opt['maxdisp'] + 2; }; function _checkParam(opt, key, defaultVal, max) { if (!opt[key]) { opt[key] = defaultVal; } else if (max && opt[key] > max) { opt[key] = max; } } ZDC.Moyori.prototype._setEventListeners = function() { this._marker['setZindex'](9999); this.map['addWidget'](this._marker); //mod 2019/09/12 MLAB PhongTrinh - add options move map to moyori icon center. if (this._opt.movemap) { this.map['moveLatLon'](this._marker['getLatLon']()); } //mod 2019/09/12 MLAB PhongTrinh - add options move map to moyori icon center. /* 地図にイベントを追加 */ ZDC['bind'](this.map, ZDC['MAP_MOUSEMOVE'], this, this.onMouseMove); ZDC['bind'](this.map, ZDC['MAP_MOUSEUP'], this, this.onMouseUp); /* マーカにイベントを追加 */ ZDC['bind'](this._marker, ZDC['MARKER_MOUSEMOVE'], this, this.onMouseMove); ZDC['bind'](this._marker, ZDC['MARKER_MOUSEDOWN'], this, this.onMouseDown); ZDC['bind'](this._marker, ZDC['MARKER_MOUSEUP'], this, this.onMouseUp); /* documentにイベントを追加 */ ZDC['bind'](document, 'mouseup', this, this.onMouseUp); this._msg = new ZDC['MsgInfo'](this.map['getLatLon'](), {'offset': ZDC['Pixel'](0, -20)}); this.map['addWidget'](this._msg); this['refresh'](); } ZDC.Moyori.prototype._addListeners = function() { ZDC['addListener'](this, ZDC['ADD_MAP'], function() { this._setEventListeners(); }); }; ZDC.Moyori.prototype._clearWidgets = function() { if (this.map) { this._msg.close(); } this._genreResultList = {}; this._latlons = []; this._iconContainer = {}; while(this._mrks.length > 0){ this.map['removeWidget'](this._mrks.shift()); } while(this._lines.length > 0){ this.map['removeWidget'](this._lines.shift()); } }; /* マウスダウンイベント処理 */ ZDC.Moyori.prototype.onMouseDown = function() { if (this._opt.disableMove) return; //add 2019/09/12 MLAB.PhongTrinh add option disable move center icon. if(this._isSearching){ return; } this._isSearching = gl._t; this._clearWidgets(); /* マウスダウン位置の緯度経度とマーカの緯度経度の差分を保持 */ var pointedLatLon = this.map['getPointerPosition'](); var diffLat = pointedLatLon['lat'] - this._marker['getLatLon']()['lat']; var diffLon = pointedLatLon['lon'] - this._marker['getLatLon']()['lon']; this._diffLatLon = new ZDC['LatLon'](diffLat, diffLon); this._isDragging = gl._t; }; /* マウスムーブイベント処理 */ ZDC.Moyori.prototype.onMouseMove = function() { if (this._opt.disableMove) return; //add 2019/09/12 MLAB.PhongTrinh add option disable move center icon. if(this._isDragging) { var pointedLatLon = this.map['getPointerPosition'](); /* マーカ表示緯度経度を取得 */ var mkLat = pointedLatLon['lat'] - this._diffLatLon['lat']; var mkLon = pointedLatLon['lon'] - this._diffLatLon['lon']; var mkrll = new ZDC['LatLon'](mkLat, mkLon); this._marker['moveLatLon'](mkrll); if(this._ov) { this._moveOval(pointedLatLon); } } }; /* マウスアップイベント処理 */ ZDC.Moyori.prototype.onMouseUp = function () { if (this._opt.disableMove) return; //add 2019/09/12 MLAB.PhongTrinh add option disable move center icon. if (this._isDragging) { this._isDragging = gl._f; if (this._opt['adjust']) { this.map['moveLatLon'](this._marker['getLatLon']()); } this['moveLatLon'](this._marker['getLatLon']()); //this._callSearchPoi(this._marker['getLatLon']()); } // this._isSearching = gl._f; }; ZDC.Moyori.prototype._callSearchPoi = function (latlon) { this._clearWidgets(); this.routeCounter = this._routeCounter(); for (var key in this.genre) { this._searchPoiByGenre(key, latlon); } if (!this._genreSize) { this._isSearching = gl._f; } }; /* 検索したジャンル数のカウンター 検索結果が0の場合のみカウントする */ var searchGenreCounter = 0; /* 施設検索 */ ZDC.Moyori.prototype._searchPoiByGenre = function (gnrcd, latlon) { var that = this; var ll = latlon || this.map['getPointerPosition'](); ZDC['Search']['getPoiByLatLon']( { 'latlon': ll, 'genrecode': gnrcd, 'limit': this._opt.searchlimit, 'radius': this._opt['radius'] }, function (stt, res) { if (stt.code === '000') { // 検索結果であるpoi情報が存在する場合のみルート検索を行う if (res.item.length > 0) { that._searchRouteByResult(gnrcd, res.item); } else { // poi情報が存在しない場合はカウントアップする searchGenreCounter += 1; } } else { // 検索エラーの場合もカウントアップする searchGenreCounter += 1; } if (_getObjectKeysNumber(that.genre) === searchGenreCounter) { /* 全てのジャンルについて、ルート検索結果が存在しない場合は 検索中フラグをfalseにして終了する */ that._isSearching = gl._f; searchGenreCounter = 0; return; } } ); }; /** * objectのプロパティ数を取得する * * @param obj * @returns {number} * @private */ function _getObjectKeysNumber(obj) { var count = 0; for (var prop in obj) { if (obj.hasOwnProperty(prop)) { count += 1; } } return count; } ZDC.Moyori.prototype._counter = function () { var counter = {}; counter.total = 0; counter.count = 0; return counter; } ZDC.Moyori.prototype._routeCounter = function () { var routeCounter = {}; routeCounter.maxCount = 0; routeCounter.currentCount = 0; routeCounter.data = {}; return routeCounter; } ZDC.Moyori.prototype['searchRouteByUserItem'] = function (items, func) { if (!items || !items.length) { return; } this.routeCounter = this._routeCounter(); var userItemSearch = gl._f; for (var i = 0; i < items.length; i++) { var currentTime = new Date().getTime(); var code = currentTime + '' + i; var genreItem = items[i]; var pois = genreItem.item; var newPois = []; for (var j = 0; j < pois.length; j++) { var ll = pois[j]['poi']['latlon']; var markerll = new ZDC['LatLon'](ll['lat'], ll['lon']); var center = this._marker['getLatLon'](); var dist = this._getLatLonToDistance(center, markerll); if (dist <= this._opt['radius']) { newPois.push(pois[j]); } } if (newPois.length === 0) { //this._isSearching = gl._f; if (!userItemSearch && i >= items.length - 1) { this._isSearching = gl._f; break; } continue; } genreItem.item = newPois; genreItem['code'] = code; this.genre[code] = genreItem; var userCallBack = {}; if (func) { userCallBack['status'] = gl._t; userCallBack['func'] = func; } else { userCallBack['status'] = gl._f; } userItemSearch = gl._t; this._isSearching = gl._t; this._searchRouteByResult(code, genreItem.item, userCallBack); } }; ZDC.Moyori.prototype._getLatLonToDistance = function (p1, p2) { if (p1['lat'] == p2['lat'] && p1['lon'] == p2['lon']) return 0; var pi = Math.PI / 180; var R = 6370000; var a = R * Math.cos(p1['lat'] * pi) * Math.cos(p1['lon'] * pi); var b = R * Math.cos(p1['lat'] * pi) * Math.sin(p1['lon'] * pi); var c = R * Math.sin(p1['lat'] * pi); var d = R * Math.cos(p2['lat'] * pi) * Math.cos(p2['lon'] * pi); var e = R * Math.cos(p2['lat'] * pi) * Math.sin(p2['lon'] * pi); var f = R * Math.sin(p2['lat'] * pi); var g = a * d + b * e + c * f; var h = Math.acos(g / (R * R)); return Math.round(R * h * 100) / 100; }; /* とりあえず全部のPOIのルート検索 */ ZDC.Moyori.prototype._searchRouteByResult = function (gnrcd, item, userCallBack) { this._genreResultList[gnrcd] = item; var counter = this._counter(); counter.total = item.length; if (!this.routeCounter) { this.routeCounter = this._routeCounter(); } /* パラメータのジャンルコード分の回数、呼び出される */ /* POI検索で結果があればルート検索を行う */ if (item.length) { this.routeCounter.maxCount += 1; } for (var i = 0; i < item.length; i++) { this._searchRoute(item[i], gnrcd, counter, item, userCallBack); } }; ZDC.Moyori.prototype._searchRoute = function (item, gnrcd, counter, items, userCallBack) { var that = this; that._isSearching = gl._t; var option = { 'from': this._marker['getLatLon'](), 'to': new ZDC['LatLon'](item['poi']['latlon']['lat'], item['poi']['latlon']['lon']), 'searchtype': 'dist', 'maxdist': 10 }; ZDC['Search']['getRouteByWalk'](option, function (stt, res) { if (stt['code'] === '000') { /* 取得成功 */ item['routedist'] = res['route']['distance']; item['route'] = res['route']; } else { /* 取得失敗 */ if (item['distance'] === 0) { item['routedist'] = 0; } else { // ルート取得成功と失敗が混在するときのソート用 item['routedist'] = 99999 + item['distance']; } item['route'] = {}; } counter.count += 1; if (counter.count === items.length) { var sortedItems = _sortByRoutedist(items, 'routedist'); // マーカー・吹き出し作成 -> ルート描画 の順番で。 var data; if (that.map) { data = that._setWidget(sortedItems, gnrcd); } else { data = that._getReturnItems(sortedItems, gnrcd); } that._genreResultList[gnrcd] = data; that.routeCounter.currentCount += 1; //コールバック関数が設定されている場合の処理 var callback; if (userCallBack) { if (userCallBack['status']) { callback = userCallBack['func']; } } else { callback = that.callback; } if (callback) { if (that.routeCounter.currentCount === that.routeCounter.maxCount) { that._isSearching = gl._f; for (var genre in that._genreResultList) { var oneGenreList = that._genreResultList[genre]; var skip = gl._f; for (var j = 0; j < oneGenreList.length; j++) { if (!oneGenreList[j]['routedist']) { skip = gl._t; break; } } if (!skip) { that.routeCounter.data[genre] = that._genreResultList[genre]; } } callback(that.routeCounter.data); that.routeCounter.currentCount = 0; } } else { if (that.routeCounter.currentCount === that.routeCounter.maxCount) { that._isSearching = gl._f; } } } }); }; ZDC.Moyori.prototype['getCenterIcon'] = function () { return gl._marker; } ZDC.Moyori.prototype['getIconById'] = function (id) { return this._iconContainer[id]; } //add 2019/09/12 MLAB.PhongTrinh return status search route. ZDC.Moyori.prototype['isSearching'] = function () { return this._isSearching; } //add 2019/09/12 MLAB.PhongTrinh return status search route. ZDC.Moyori.prototype._getReturnItems = function (items, gnrcd) { var displayedItems = []; for (var i = 0; i < this._opt.searchlimit; i++) { if (!items[i]) { continue; } items[i]['optgenre'] = this.genre[gnrcd]; if (i < this._opt['maxdisp']) { delete items[i]['route']; displayedItems.push(items[i]); } } return displayedItems; }; /* 検索したPOIのうち近いほうから指定した件数を表示する */ ZDC.Moyori.prototype._setWidget = function (items, gnrcd) { var displayedItems = []; for (var i = 0; i < this._opt.searchlimit; i++) { if (!items[i]) { continue; } items[i]['optgenre'] = this.genre[gnrcd]; if (i < this._opt['maxdisp']) { var ll = new ZDC['LatLon'](items[i]['poi']['latlon']['lat'], items[i]['poi']['latlon']['lon']); var icon = new ZDC['Marker'](ll, (items[i]['icon'] ? items[i]['icon'] : this.genre[gnrcd]['icon'])); var iconId = gnrcd + i; items[i]['iconId'] = iconId; this._iconContainer[iconId] = icon; icon['genre'] = gnrcd; icon['poi'] = items[i]['poi']; icon['sortno'] = i; this.map['addWidget'](icon); this._mrks.push(icon); this._writeRoute(items[i], icon); delete items[i]['route']; delete items[i]['optgenre']; displayedItems.push(items[i]); } } if (this._latlons.length > 0 && this._opt['adjust']) { //var adjust = this.map.getAdjustZoom(this._latlons); var adjust = this.map['getAdjustZoom'](this._latlons, {'fix': gl._t}); this.map['moveLatLon'](adjust['latlon']); this._marker['moveLatLon'](adjust['latlon']); this.map['setZoom'](adjust['zoom']); } return displayedItems; }; ZDC.Moyori.prototype._writeRoute = function (item, icon) { if (!item['route']) { return; } var distance = item['routedist']; var link = item['route']['link']; var opt = item['optgenre']['lineProperty']; icon['line'] = []; if (link) { for (var i = 0, j = link.length; i < j; i++) { var pllatlons = []; for (var k = 0, l = link[i]['line'].length; k < l; k++) { var ll = new ZDC['LatLon'](link[i]['line'][k]['lat'], link[i]['line'][k]['lon']); pllatlons.push(link[i]['line'][k]); this._latlons.push(link[i]['line'][k]); } var pl = new ZDC['Polyline'](pllatlons, opt); this.map['addWidget'](pl); this._lines.push(pl); icon['line'].push(pl); } } else { distance = item['distance']; } icon['msg'] = this._msg; icon['distance'] = distance; }; /* ZDC.Moyori.prototype.moveCenter = function(){ this.moveLatLon(this.map.getLatLon()); }; */ ZDC.Moyori.prototype['moveLatLon'] = function (latlon) { if (this.map) { this._marker['moveLatLon'](latlon); this['refresh'](); } else { this._callSearchPoi(latlon); } }; ZDC.Moyori.prototype['refresh'] = function () { var latlon = this._center; if (this.map) { latlon = this._marker['getLatLon'](); this._checkAndDrawOval(latlon); } this._callSearchPoi(latlon); }; ZDC.Moyori.prototype._checkAndDrawOval = function (latlon) { /* ovaloptionsが存在する場合の処理 */ if (this._opt['ovaloptions']) { for (var p in this._opt['ovaloptions']) { if (this._opt['ovaloptions'].hasOwnProperty(p)) { if (this._ov) { this._moveOval(latlon); } else { this._writeOval(this._opt['radius'], latlon); } break; } } } }; ZDC.Moyori.prototype._writeOval = function (radius, latlon) { this._ov = new ZDC['Oval']( { 'latlon': latlon, 'x': radius, 'y': radius }, this._opt['ovaloptions'] ); /* 円を地図に追加 */ this.map['addWidget'](this._ov); }; ZDC.Moyori.prototype._moveOval = function (latlon) { if (!latlon) { latlon = this.map['getLatLon'](); } this._ov['moveLatLon'](latlon); this._ov['setRadius'](ZDC['Pixel'](this._opt['radius'], this._opt['radius'])); this._ov['redraw'](); }; ZDC.Moyori.prototype['setRadius'] = function (radius) { if (radius) { if (radius > 1000) { radius = 1000; } this._opt['radius'] = radius; } }; ZDC.Moyori.prototype['setMaxdisp'] = function (maxdisp) { if (maxdisp) { if (maxdisp > 10) { maxdisp = 10; } this._opt['maxdisp'] = maxdisp; } }; ZDC.Moyori.prototype['setAdjust'] = function (adjust) { if (adjust === gl._t) { this._opt['adjust'] = gl._t; } else { this._opt['adjust'] = gl._f; } }; function _sortByRoutedist(obj, key) { obj.sort(function (a, b) { return (a[key] > b[key]) ? 1 : -1; }); return obj; }; })(); /**#nocode-*/ eval('/*#output#moyori.js#*/');