/** * 路線APIを利用して、FS路線を表示する */ var RosenMap = (function(){ return { d: null, // documentオブジェクト MAP_ROSEN: null, // 全域の路線 MAP_SUBURB: null, // 近郊の路線 MAP_SUBWAY: null, // 地下鉄の路線 map_child_id: "mmap", map_id: ["map1","map2","map3","map4"], tab_id: ["tab1","tab2","tab3","tab4"], reset_btn_id: ["reset_btn_map1","reset_btn_map2","reset_btn_map3"], img_path: "/f/mapion/img/station/", type: null, // 路線の表示タイプ [rosen/suburb/subway] map_width: 633, map_height: 400, layer_name: "", // 表示している路線のレイヤ名 pref_code: null, // 都道府県コード default_stcode: null, // デフォルト表示する駅コード rosen_code: null, // 路線コード rosen_subway_flg: false, // 路線の地下鉄フラグ [true:地下鉄/false:地下鉄でない] rosen_station_list: null, // 路線の駅の駅コードリスト has_layer_rosen: false, // 全域レイヤがあるか has_layer_suburb: false, // 近郊レイヤがあるか has_layer_subway: false, // 地下鉄レイヤがあるか rosen_div: null, // 全域の路線 表示用 suburb_div: null, // 近郊の路線 表示用 subway_div: null, // 地下鉄の路線 表示用 map_div: null, // 地図表示用 rosen_tab: null, // 全域タブ表示用 suburb_tab: null, // 近郊タブ表示用 subway_tab: null, // 地下鉄タブ表示用 map_tab: null, // 地図タブ表示用 /** * 初期表示 * * @param pref_code 都道府県コード * @param stcode 駅コード * @param rosen_code 路線コード * @param rosen_subway_flag 路線の地下鉄フラグ * @param rosen_stcode_arr 路線上の駅の駅コードの配列 */ init: function(pref_code, stcode, rosen_code, rosen_subway_flag, rosen_stcode_arr) { // 路線図廃止のため地図のみを表示する this.d = document; //路線表示用div // this.rosen_div = this.d.getElementById(this.map_id[0]); // this.suburb_div = this.d.getElementById(this.map_id[1]); // this.subway_div = this.d.getElementById(this.map_id[2]); this.map_div = this.d.getElementById(this.map_id[3]); //タブ表示用div // this.rosen_tab = this.d.getElementById(this.tab_id[0]); // this.suburb_tab = this.d.getElementById(this.tab_id[1]); // this.subway_tab = this.d.getElementById(this.tab_id[2]); this.map_tab = this.d.getElementById(this.tab_id[3]); // 都道府県コードを設定 this.pref_code = pref_code; // 路線コードを設定 this.rosen_code = rosen_code; // 路線が地下鉄なのかのフラグを設定 this.rosen_subway_flg = (rosen_subway_flag=="1") ? true : false; // 路線上の駅の駅コードの配列を設定 this.rosen_station_list = rosen_stcode_arr; // 駅コードがSTxxxxxなら駅コードの駅をデフォルトで表示する駅に設定 if ( stcode && stcode.match("ST[0-9]{5}") ) { this.default_stcode = stcode.replace("ST",""); // ポートライナー(ROP082001)の場合、初期表示時に中心とする駅を三宮駅(ST80091)から貿易センター駅(ST26546)に置き換える // 三宮駅がVAL側に存在せず、初期表示の中心に設定すると地図が表示できないため if ( this.rosen_code == "ROP082001" && this.default_stcode == "80091" ) { this.default_stcode = "26546"; } } else { // それ以外は都道府県コードごとに指定された駅コードをデフォルトで表示する駅に設定 this.default_stcode = this.pref_info[pref_code].default_stcode; } RosenMap.show("map"); /* // 路線APIが認証されていて対象ブラウザの場合 if ( isAuthenticated() && isSupportedBrowser() ) { this.d = document; //路線表示用div this.rosen_div = this.d.getElementById(this.map_id[0]); this.suburb_div = this.d.getElementById(this.map_id[1]); this.subway_div = this.d.getElementById(this.map_id[2]); this.map_div = this.d.getElementById(this.map_id[3]); //タブ表示用div this.rosen_tab = this.d.getElementById(this.tab_id[0]); this.suburb_tab = this.d.getElementById(this.tab_id[1]); this.subway_tab = this.d.getElementById(this.tab_id[2]); this.map_tab = this.d.getElementById(this.tab_id[3]); // 都道府県コードを設定 this.pref_code = pref_code; // 路線コードを設定 this.rosen_code = rosen_code; // 路線が地下鉄なのかのフラグを設定 this.rosen_subway_flg = (rosen_subway_flag=="1") ? true : false; // 路線上の駅の駅コードの配列を設定 this.rosen_station_list = rosen_stcode_arr; // 駅コードがSTxxxxxなら駅コードの駅をデフォルトで表示する駅に設定 if ( stcode && stcode.match("ST[0-9]{5}") ) { this.default_stcode = stcode.replace("ST",""); // ポートライナー(ROP082001)の場合、初期表示時に中心とする駅を三宮駅(ST80091)から貿易センター駅(ST26546)に置き換える // 三宮駅がVAL側に存在せず、初期表示の中心に設定すると地図が表示できないため if ( this.rosen_code == "ROP082001" && this.default_stcode == "80091" ) { this.default_stcode = "26546"; } } else { // それ以外は都道府県コードごとに指定された駅コードをデフォルトで表示する駅に設定 this.default_stcode = this.pref_info[pref_code].default_stcode; } // 非同期処理オブジェクト var counter = { up: function(){this.waits++}, down: function(){ this.waits--; if (!this.waits) { this.doComplete() }; }, waits: 0 }; // 広域400%(jpnx4)の地図上に、指定した駅コードの駅があるかどうかを取得 var exp_app = new CExpApp(); counter.up(); exp_app.getStationFromCode(this.default_stcode, function(station, errorCode) { if(errorCode == CExpApp.SUCCESS) { RosenMap.has_layer_rosen = true; } counter.down(); }, RosenMap.getMapLayerName("rosen")); // 近郊の地図上に、指定した駅コードの駅があるかどうかを取得 var suburb_layer = this.getMapLayerName("suburb"); if ( suburb_layer != null ) { var exp_app2 = new CExpApp(); counter.up(); exp_app2.getStationFromCode(this.default_stcode, function(station, errorCode) { if(errorCode == CExpApp.SUCCESS) { RosenMap.has_layer_suburb = true; } counter.down(); }, suburb_layer); } // 地下鉄の地図上に、指定した駅コードの駅があるかどうかを取得 var subway_layer = this.getMapLayerName("subway"); if ( subway_layer != null ) { var exp_app3 = new CExpApp(); counter.up(); exp_app3.getStationFromCode(this.default_stcode, function(station, errorCode) { if(errorCode == CExpApp.SUCCESS) { RosenMap.has_layer_subway = true; } counter.down(); }, subway_layer); } // それぞれのレイヤの有無を取得したら、路線やタブの表示処理を行う counter.doComplete = function() { // 近郊レイヤがあれば近郊タブを表示 if ( RosenMap.has_layer_suburb ) { RosenMap.showTab(RosenMap.suburb_tab); } else { RosenMap.hideTab(RosenMap.suburb_tab); } // 地下鉄レイヤがあれば地下鉄タブを表示 if ( RosenMap.has_layer_subway ) { RosenMap.showTab(RosenMap.subway_tab); } else { RosenMap.hideTab(RosenMap.subway_tab); } // 地図タブを表示 RosenMap.showTab(RosenMap.map_tab); // 全域レイヤにも、近郊レイヤにも、地下鉄レイヤにも駅がない場合は地図を表示 if ( !RosenMap.has_layer_rosen && !RosenMap.has_layer_suburb && !RosenMap.has_layer_subway ) { RosenMap.show("map"); } else if ( RosenMap.rosen_subway_flg && RosenMap.has_layer_subway ) { // 地下鉄路線フラグがtrueで、地下鉄レイヤに駅がある場合は地下鉄を初期表示 RosenMap.show("subway"); } else if ( RosenMap.rosen_subway_flg && RosenMap.has_layer_suburb ) { // 地下鉄路線フラグがtrueで、地下鉄レイヤに駅がある場合は地下鉄を初期表示 RosenMap.show("suburb"); } else if ( !RosenMap.has_layer_rosen && RosenMap.has_layer_suburb ) { // 全域レイヤに駅がなく、近郊レイヤに駅がある場合は近郊を初期表示 RosenMap.show("suburb"); } else if ( !RosenMap.has_layer_rosen && RosenMap.has_layer_subway ) { // 全域レイヤに駅がなく、地下鉄レイヤに駅がある場合は地下鉄を初期表示 RosenMap.show("subway"); } else { // それ以外は全域を表示 RosenMap.show("rosen"); } }; } else { // 認証エラーまたは対象外のブラウザで路線が表示できないとき var div = document.getElementById(this.map_id[0]); div.className = "map_disable"; div.innerHTML = "大変申し訳ございませんが、現在、路線を表示できません。
大変お手数ですが、しばらく経ってから再度お試しください。" } */ }, /** * 路線/地図を表示 * * @param 路線の表示タイプ [rosen:広域, suburb:近郊, subway:地下鉄] */ show: function(type) { if ( this.type == type ) return; this.type = type; var d = this.d; var layer_name = this.getMapLayerName(this.type); this.hideErrorMessage(); if ( this.type == "rosen" ) { // 全域の路線を表示 this.showRosenMap(true, false, false, false); // 初期位置に戻るボタン this.createResetButton(this.type); // タブの選択状態を設定 this.selectedTab(this.tab_id[0]+"_link", true); this.selectedTab(this.tab_id[1]+"_link", false); this.selectedTab(this.tab_id[2]+"_link", false); this.selectedTab(this.tab_id[3]+"_link", false); // 全域レイヤの初期位置を設定。初期表示でなければ前回の表示位置を保つため何もしない。 if ( this.MAP_ROSEN == null ) { this.MAP_ROSEN = new CMapApp(this.rosen_div); this.setMapSize(this.MAP_ROSEN); var stcode = this.default_stcode; // 全域レイヤに駅がない場合は、都道府県ごとに設定されたデフォルトの駅コードを設定(地下鉄の駅など) if ( !this.has_layer_rosen ) { stcode = this.pref_info[this.pref_code].default_stcode; } this.MAP_ROSEN.dispMapStation(stcode, layer_name, RosenMap.markStation, RosenMap.jumpToStation); this.createResetButton(type); this.createZoomControl(this.type, stcode); } } else if ( this.type == "suburb" ) { // 近郊の路線を表示 this.showRosenMap(false, true, false, false); this.createResetButton(this.type); this.selectedTab(this.tab_id[0]+"_link", false); this.selectedTab(this.tab_id[1]+"_link", true); this.selectedTab(this.tab_id[2]+"_link", false); this.selectedTab(this.tab_id[3]+"_link", false); // 近郊レイヤの初期位置を設定。初期表示でなければ前回の表示位置を保つため何もしない。 if ( this.MAP_SUBURB == null ) { this.MAP_SUBURB = new CMapApp(this.suburb_div); this.setMapSize(this.MAP_SUBURB); this.MAP_SUBURB.dispMapStation(this.default_stcode, layer_name, RosenMap.markStation, RosenMap.jumpToStation); this.createResetButton(type); this.createZoomControl(this.type, this.default_stcode); } } else if ( this.type == "subway" ) { // 地下鉄の路線を表示 this.showRosenMap(false, false, true, false); this.createResetButton(this.type); this.selectedTab(this.tab_id[0]+"_link", false); this.selectedTab(this.tab_id[1]+"_link", false); this.selectedTab(this.tab_id[2]+"_link", true); this.selectedTab(this.tab_id[3]+"_link", false); // 地下鉄レイヤの初期位置を設定。初期表示でなければ前回の表示位置を保つため何もしない。 if ( this.MAP_SUBWAY == null ) { this.MAP_SUBWAY = new CMapApp(this.subway_div); this.setMapSize(this.MAP_SUBWAY); this.createResetButton(type); this.MAP_SUBWAY.dispMapStation(this.default_stcode, layer_name, RosenMap.markStation, RosenMap.jumpToStation); } } else { // 地図を表示 this.showRosenMap(false, false, false, true); this.selectedTab(this.tab_id[0]+"_link", false); this.selectedTab(this.tab_id[1]+"_link", false); this.selectedTab(this.tab_id[2]+"_link", false); this.selectedTab(this.tab_id[3]+"_link", true); } }, /** * 路線を表示 * * @param is_rosen 全域か * @param is_suburb 近郊か * @param is_subway 地下鉄か * @param is_map 地図か */ showRosenMap: function(is_rosen, is_suburb, is_subway, is_map) { var d = this.d; // 全域 if( is_rosen ){ this.showMap(this.rosen_div); //全域を表示 } else { this.hideMap(this.rosen_div); //全域を非表示 } // 近郊 if( is_suburb ){ this.showMap(this.suburb_div); //近郊を表示 } else { this.hideMap(this.suburb_div); //近郊を非表示 } // 地下鉄 if( is_subway ){ this.showMap(this.subway_div); //地下鉄を表示 } else { this.hideMap(this.subway_div); //地下鉄を非表示 } var map_child_div = d.getElementById(this.map_child_id); // 地図 if( is_map ){ //地図を表示 this.showMap(this.map_div); if ( this.map_div != null ) { this.map_div.style.visibility = "visible"; } if ( map_child_div != null ) { map_child_div.style.visibility = "visible"; } } else { //地図を非表示 this.hideMap(this.map_div); if ( this.map_div != null ) { this.map_div.style.visibility = "hidden"; } if ( map_child_div != null ) { map_child_div.style.visibility = "hidden"; } } }, /** * 駅をマークする * CMapApp.dispMapStation()のコールバック関数 * * @isSuccess true:成功 false:失敗 * @stcode 駅コード */ markStation: function(isSuccess, stcode) { if ( isSuccess ) { if ( RosenMap.rosen_station_list != "" ) { for ( var i = 0; i < RosenMap.rosen_station_list.length; i++ ) { var rosen_stcode = RosenMap.rosen_station_list[i].replace("ST",""); RosenMap.mark(rosen_stcode); } } else { RosenMap.mark(stcode); } } else { // エラー発生時の処理 // エラーは、地下鉄の駅や全域200%レイヤや全域100%レイヤに存在しないなど、指定したレイヤに指定した駅コードがない場合に発生する。 // その場合は、都道府県ごとに設定されたデフォルトの駅コードを設定して路線を表示する。 var stcode = RosenMap.pref_info[RosenMap.pref_code].default_stcode; if ( RosenMap.type == "rosen" ) { RosenMap.MAP_ROSEN.dispMapStation(stcode, RosenMap.layer_name, function(isSuccess, stcode){ RosenMap.createZoomControl(RosenMap.type, stcode); RosenMap.createResetButton(RosenMap.type); }, RosenMap.jumpToStation); } else if ( RosenMap.type == "suburb" ) { RosenMap.MAP_SUBURB.dispMapStation(stcode, RosenMap.layer_name, function(isSuccess, stcode){ RosenMap.createZoomControl(RosenMap.type, stcode); RosenMap.createResetButton(RosenMap.type); }, RosenMap.jumpToStation); } else { RosenMap.MAP_SUBWAY.dispMapStation(stcode, RosenMap.layer_name, function(isSuccess, stcode){ RosenMap.createZoomControl(RosenMap.type, stcode); RosenMap.createResetButton(RosenMap.type); }, RosenMap.jumpToStation); } } }, /** * 駅をマークする * * @stcode 駅コード */ mark: function(stcode) { var mark = null; if ( RosenMap.type == "rosen" ) { if( !RosenMap.has_layer_rosen ) return; mark = RosenMap.MAP_ROSEN.createMark(); } else if ( RosenMap.type == "suburb" ) { if( !RosenMap.has_layer_suburb ) return; mark = RosenMap.MAP_SUBURB.createMark(); } else { if( !RosenMap.has_layer_subway ) return; mark = RosenMap.MAP_SUBWAY.createMark(); } if(mark == null) return; mark._color = CMark.COLOR_GREEN; //mark._isBlink = false; mark.showOnStation(stcode, CMark.STYLE_STATION_POINT); }, /** * 駅ページへ遷移 * CMapApp.dispMapStation()の引数にて指定。路線上の駅で発生するイベントを処理する。 * * @param name 駅名 * @param stcode 駅コード * @param lat 緯度 * @param lon 経度 * @param kencode 都道府県コード * @param eventType イベントタイプ */ jumpToStation: function(name, stcode, lat, lon, kencode, eventType) { // クリック時の処理 if ( eventType == CMapApp.EVENT_CLICK ) { this.service = new MAPION.net.HTTPService() .setURL("/search/station2/select/?q=poi_code:{poi_code}&start=0&rows=1&key=mapion&wt=json&json.wrf=?") .setContext({ poi_code: "ST"+stcode }) .setParameterForInvoker("charset","utf-8") .setParameterForInvoker("timeOutMS",5000) .filter(function(data){ // 駅の検索結果がなければ文言表示 if ( data.response.docs.length == 0 ) { RosenMap.showErrorMessage("大変申し訳ございません。
この地点は詳細情報ページが存在しないため、表示できません。"); } else { // 検索結果があれば駅ページへ遷移 location.href = "/station/ST" + stcode + "/"; } }) .fire(); } }, /** * 路線上にエラーメッセージを表示 */ showErrorMessage: function(msg) { var d = RosenMap.d; var elem_id = RosenMap.getMapElemId(); var err_msg_div = d.getElementById("err_msg_"+elem_id); var err_msg_bg_div = d.getElementById("err_msg_bg_"+elem_id); if ( err_msg_div && err_msg_div.style.display == "none" ) { err_msg_div.style.display = "block"; err_msg_bg_div.style.display = "block"; } else { // エラーメッセージ閉じるボタン var close_btn = d.createElement("img"); close_btn.id = "err_msg_close_"+elem_id; close_btn.src = RosenMap.img_path+"x.png"; close_btn.onclick = function(){ RosenMap.hideErrorMessage(); }; // エラーメッセージ表示div var err_msg = d.createElement("div"); err_msg.innerHTML = "

"+msg+"

"; err_msg.id = "err_msg_"+elem_id; err_msg.style.display = "block"; err_msg.appendChild(close_btn); // エラーメッセージ背景div var err_msg_bg = d.createElement("div"); err_msg_bg.id = "err_msg_bg_"+elem_id; err_msg_bg.style.display = "block"; // 路線上にエラーメッセージ表示 if ( RosenMap.type == "rosen" ) { RosenMap.rosen_div.appendChild(err_msg_bg); RosenMap.rosen_div.appendChild(err_msg); } else if ( RosenMap.type == "suburb" ) { RosenMap.suburb_div.appendChild(err_msg_bg); RosenMap.suburb_div.appendChild(err_msg); } else if ( RosenMap.type == "subway" ) { RosenMap.subway_div.appendChild(err_msg_bg); RosenMap.subway_div.appendChild(err_msg); } else { RosenMap.rosen_div.appendChild(err_msg_bg); RosenMap.rosen_div.appendChild(err_msg); } } }, /** * 路線上のエラーメッセージを非表示 */ hideErrorMessage: function() { var d = RosenMap.d; for(var i=0; i