// JavaScript Document (function($){ var dataList = new Array(); var allData = new Array(); var mapSetJobj = null; var mapSetObj = null; //var map = null; var loadURL = 'http://fudosan.cbiz.ne.jp/get_csv_data.cgi'; var loadDefParam = 'need_pos=off&js=on&desc=on'; var opt = null; var zoomChangeFlg = 0; var autoPosi = new Array(); var mapSize = new Array(); var error_cnt = 0; var defaultFlg = true; $.fn.setgmap = function( config ) { /* 引数の初期値を設定(カンマ区切り) */ var defaults = { center_lat : 41.837992, // 中心位置緯度 center_lng : 140.733154, // 中心位置経度 zoom : 16, // 拡大率 mapTypeId: google.maps.MapTypeId.ROADMAP, // MAPタイプ scrollWheel : false, // マウスホイールで拡大 navConOpt : null, // ナビコントロールOption(ナビゲーションの位置を変更など) infoOnly : true, // 情報ウィンドウを常に1個だけ表示する dataload : false, // 物件読み込みフラグ mode : null, // 物件読み込み種別 rent or sale param : null, // 物件読み込みパラメータ markerSetTime : 0, // マーカーをセットしていく時間 icon_src : null, // アイコン画像パス icon_size : null, // アイコン画像サイズ icon_position : null, // アイコン画像位置 icon_aposition : null, // アイコン画像アンカー位置 iconAnimation : true, // アイコン画像マウスオーバーアニメーション shadow_src : null, // 影画像パス shadow_size : null, // 影画像サイズ shadow_position : null, // 影画像位置 shadow_aposition : null, // 影画像アンカー位置 animation : null, // アニメーション group : false, // グループ化 infoTurn : 'pic-g,name,price,area_2,area_3,area_4,madori', // 表示順 imgSize : 100, // 画像サイズ nopic : 'http://www.rals.co.jp/fudosan/img/detailPage/default/icons/no_picture.gif', // 写真準備中画像 loadFormChange : null, // ロード時抽出条件変更(フォームのIDをセット) paramTxtSelector : null, // 抽出条件セットセレクタ paramTxtForm : null, // 抽出条件取得フォーム hideParamTxt : '', // 抽出条件非表示項目 detaCountSelect : null, // データ件数セットセレクタ customIcon : null, // カスタムアイコン画像 loaderImage : null, set_comment : null, // セットするコメント getIdData : '' } var options = $.extend( defaults, config ); /* 一致した要素上で繰り返す */ return this.each(function(i){ opt = options; mapSetJobj = $( this ); mapSetObj = $( this ).get( 0 ); mapSize.width = $( this ).width(); mapSize.height = $( this ).height(); // 物件を読み込むか if( options.dataload && options.param && options.param != '' && options.mode && ( options.mode == 'rent' || options.mode == 'sale' ) ) { // 抽出条件変更の場合 if( options.loadFormChange ) { $.loadParamChange( options.loadFormChange ); } // 変更なし else { $.loadData(); } } else { // 地図表示 map = $.mapView( mapSetObj, options.center_lat, options.center_lng, options.zoom, options.mapTypeId, options.navConOpt, options.scrollWheel ); // データをパース dataList = $.parseData( [{ lat : options.center_lat, lng : options.center_lng }] ); // マーカーセット $.setMarker(function() { $.setClickFunc(); $.mouseOverAnimation(); }); $.clickFunc( 0 ); } $.moreView(); }); }; // 物件情報読み込み $.loadData = function() { $.ajaxSetup({ scriptCharset: 'shift-jis', type: 'POST', cache: false }); var param = loadDefParam + '&mode=' + opt.mode + '&' + opt.param; $.ajax({ url : loadURL, dataType : 'jsonp', charset : 'shift-jis', success : $.loadDataCallback, data : param, error : function( a, b, c ) { if( error_cnt < 5 ) { error_cnt++; $.loadData(); } else { error_cnt = 0; } }, timeout : 5000 }); } // 物件情報読み込み完了 $.loadDataCallback = function( result ) { if( typeof( map ) == 'undefined' || !map ) { setTimeout(function() { $.loadDataCallback( result ); }, 100); return false; } error_cnt = 0; $.loaderClose(); $.paramTxtSet(); if( !result || result.length == 0 ) { $.loadDataClear(); allData = new Array(); return false; } // 全データ格納 allData = result; $.dataCountTxtSet(); var idNum = ''; for(var dt in allData){ if(allData[ dt ].f_data_id == opt.getIdData){ idNum = dt; } } if(idNum != ''){ allData.splice(idNum, 1); idNum = ''; } // 位置・サイズ自動調整用の値格納 var getId = ''; var posiFlg = false; for( var key in allData ) { if( !allData[ key ].lat || !allData[ key ].lng || allData[ key ].lat == '' || allData[ key ].lng == '' ) { continue; } //alert(allData[ key ].lat); //alert(allData[ key ].lng); autoPosi = { minlat : allData[ key ].lat, maxlat : allData[ key ].lat, minlng : allData[ key ].lng, maxlng : allData[ key ].lng }; posiFlg = true; break; } if( !posiFlg ) { return false; } for( var key in allData ) { if( !allData[ key ].lat || !allData[ key ].lng || allData[ key ].lat == '' || allData[ key ].lng == '' ) { continue; } if( allData[ key ].lat < autoPosi.minlat ) { autoPosi.minlat = allData[ key ].lat } if( allData[ key ].lat > autoPosi.maxlat ) { autoPosi.maxlat = allData[ key ].lat } if( allData[ key ].lng < autoPosi.minlng ) { autoPosi.minlng = allData[ key ].lng } if( allData[ key ].lng > autoPosi.maxlng ) { autoPosi.maxlng = allData[ key ].lng } } // 地図セット if( defaultFlg ) { loadResizeFlg = true; // map = $.mapView( mapSetObj, opt.center_lat, opt.center_lng, opt.zoom, opt.mapTypeId, opt.navConOpt, opt.scrollWheel ); google.maps.event.addListener ( map, 'bounds_changed', function() { $.bounds_changed(); }); google.maps.event.addListener ( map, 'zoom_changed', function() { $.zoom_changed(); }); } $.autoPositionAdjustment( autoPosi.minlat, autoPosi.maxlat, autoPosi.minlng, autoPosi.maxlng, true ); } // BOUNDSイベント $.bounds_changed = function() { if( zoomChangeFlg != 1 || allData.length == 0 ) { return false; } $.clearMarkerAll(); // データをパース dataList = $.parseData( allData ); // マーカーセット $.setMarker(function() { $.setClickFunc(); $.mouseOverAnimation(); }); zoomChangeFlg = 2; } // ズームLEVEL変更 $.zoom_changed = function() { if( zoomChangeFlg != 0 ) { opt.animation = null; opt.markerSetTime = 0; } zoomChangeFlg = 1; } // 物件数テキストセット $.dataCountTxtSet = function() { if( !opt.detaCountSelect ) { return false; } $( opt.detaCountSelect ).each(function() { $( this ).text( allData.length ); }); } // 抽出条件テキストセット $.paramTxtSet = function() { if( !opt.paramTxtForm ) { return false; } var setTxt = ''; var hideListAll = opt.hideParamTxt.split( '&' ); var hideList = new Array(); for( var key in hideListAll ) { if( hideListAll[ key ].match( /(.+?)=(.*)/ ) ) { hideList[ RegExp.$1 ] = RegExp.$2; } } $( opt.paramTxtForm ).find( 'input, select, textarea' ).each(function() { if( $( this ).attr( 'name' ) in hideList && hideList[ $( this ).attr( 'name' ) ] == $( this ).val() ) { return; } // input if( $( this ).get( 0 ).tagName.match( /^input$/i ) ) { if( $( this ).attr( 'type' ) != 'checkbox' && $( this ).attr( 'type' ) != 'radio' ) { return; } if( !$( this ).is( ':checked' ) ) { return; } if( setTxt != '' ) { setTxt += ' > '; } setTxt += $( 'label[for=' + $( this ).attr( 'id' ) + ']' ).text(); } // select else if( $( this ).get( 0 ).tagName.match( /^select$/i ) ) { $( 'option', this ).each(function() { if( !$( this ).is( ':selected' ) ) { return; } if( setTxt != '' ) { setTxt += ' > '; } setTxt += $( this ).text().replace( /(├ |└ )/, '' ); }); } // textarea else { // setTxt += $( this ).val(); } }); if( opt.paramTxtSelector && $( opt.paramTxtSelector ).size() > 0 ) { $( opt.paramTxtSelector ).each(function() { $( this ).text( setTxt ); }); } } // 物件情報リスト変換 $.parseData = function( all_data_list ) { var resList = new Array(); for( var key in all_data_list ) { var setKey = null; if( opt.group ) { setKey = $.markerGroupCheck( resList, all_data_list[ key ].lat, all_data_list[ key ].lng ); } // グループ化 if( setKey ) { resList[ setKey ].cnt++; // カスタムアイコン画像 if( opt.customIcon ) { for( var ckey in opt.customIcon ) { if( all_data_list[ key ][ opt.customIcon[ ckey ].skey ] == opt.customIcon[ ckey ].sval ) { continue; } // アイコン画像 resList[ setKey ].icon = $.getMarkerImage( icons.src, ( icons.size && icons.size[0] ) ? icons.size[0] : null, ( icons.size && icons.size[1] ) ? icons.size[1] : null, ( icons.position && icons.position[0] ) ? icons.position[0] : null, ( icons.position && icons.position[1] ) ? icons.position[1] : null, ( icons.aposition && icons.aposition[0] ) ? icons.aposition[0] : null, ( icons.aposition && icons.aposition[1] ) ? icons.aposition[1] : null ); resList[ setKey ].shadow = $.getMarkerImage( shadow.src, ( shadow.size && shadow.size[0] ) ? shadow.size[0] : null, ( shadow.size && shadow.size[1] ) ? shadow.size[1] : null, ( shadow.position && shadow.position[0] ) ? shadow.position[0] : null, ( shadow.position && shadow.position[1] ) ? shadow.position[1] : null, ( shadow.aposition && shadow.aposition[0] ) ? shadow.aposition[0] : null, ( shadow.aposition && shadow.aposition[1] ) ? shadow.aposition[1] : null ); break; } } resList[ setKey ].comment += $.getComment( all_data_list[ key ], resList[ setKey ].cnt ); } // 単体 else { icons = { src : opt.icon_src, size : opt.icon_size, position : opt.icon_position, aposition : opt.icon_aposition }; shadow = { src : opt.shadow_src, size : opt.shadow_size, position : opt.shadow_position, aposition : opt.shadow_aposition }; // カスタムアイコン画像 if( opt.customIcon ) { for( var ckey in opt.customIcon ) { if( all_data_list[ key ][ opt.customIcon[ ckey ].skey ] != opt.customIcon[ ckey ].sval ) { continue; } // アイコン画像 icons.src = opt.customIcon[ ckey ].icon_src; icons.size = ( ( opt.customIcon[ ckey ].icon_size ) ? opt.customIcon[ ckey ].icon_size : null ); icons.position = ( ( opt.customIcon[ ckey ].icon_position ) ? opt.customIcon[ ckey ].icon_position : null ); icons.aposition = ( ( opt.customIcon[ ckey ].icon_aposition ) ? opt.customIcon[ ckey ].icon_aposition : null ); // 影画像 shadow.src = opt.customIcon[ ckey ].shadow_src; shadow.size = ( ( opt.customIcon[ ckey ].shadow_size ) ? opt.customIcon[ ckey ].shadow_size : null ); shadow.position = ( ( opt.customIcon[ ckey ].shadow_position ) ? opt.customIcon[ ckey ].shadow_position : null ); shadow.aposition = ( ( opt.customIcon[ ckey ].shadow_aposition ) ? opt.customIcon[ ckey ].shadow_aposition : null ); break; } } resList.push({ lat : all_data_list[ key ].lat, lng : all_data_list[ key ].lng, icon : $.getMarkerImage( icons.src, ( icons.size && icons.size[0] ) ? icons.size[0] : null, ( icons.size && icons.size[1] ) ? icons.size[1] : null, ( icons.position && icons.position[0] ) ? icons.position[0] : null, ( icons.position && icons.position[1] ) ? icons.position[1] : null, ( icons.aposition && icons.aposition[0] ) ? icons.aposition[0] : null, ( icons.aposition && icons.aposition[1] ) ? icons.aposition[1] : null ), shadow : $.getMarkerImage( shadow.src, ( shadow.size && shadow.size[0] ) ? shadow.size[0] : null, ( shadow.size && shadow.size[1] ) ? shadow.size[1] : null, ( shadow.position && shadow.position[0] ) ? shadow.position[0] : null, ( shadow.position && shadow.position[1] ) ? shadow.position[1] : null, ( shadow.aposition && shadow.aposition[0] ) ? shadow.aposition[0] : null, ( shadow.aposition && shadow.aposition[1] ) ? shadow.aposition[1] : null ), comment : $.getComment( all_data_list[ key ] ), animation : opt.animation, cnt : 1 }); } } for( var key in resList ) { resList[ key ].comment = '