$(document).ready(function(){ myprj.models.onload(); myprj.events(); }); myprj = { _map : {}, _mouse : {}, models : { _layer : {}, _layer_surround : {}, _markers : [], _marker_center : {}, _minLat : null, _maxLat : null, _minLon : null, _maxLon : null, onload : function () { myprj._map = new ZdcMap($('#Emap')[0]); myprj._map.setWheelOff(); this._layer = new ZdcUserLayer(); myprj._map.addUserLayer(this._layer); this.setController(); var poi = {}; $($('#PoiDataForm').serializeArray()).each(function (_key, _val) { poi[_val.name] = _val.value; }); /** * 主マーカーを追加 */ poi.point = new ZdcPoint(parseFloat(poi.lon), parseFloat(poi.lat)); poi.icon = this.mkIcon(poi.imgIcon, poi.specialFlg); var marker = this.mkMarker(poi); this._layer.addMarker(marker); /** * マップ移動 */ this._marker_center = marker; myprj._map.saveMapLocation(marker.Point); myprj._map.scrollToCenter(marker.Point); /** * 周辺スポット表示 */ this.getSurroundPoints(poi); }, setController : function () { myprj._map.addMapControl(new ZdcControl(3,'large')); myprj._map.addMapScaleBar(new ZdcScaleBar()); }, mkIcon : function (imgUrl, specialFlg) { var icon = new ZdcIcon(); icon.printimage = icon.image = imgUrl; icon.size = new ZdcSize(30, 30); icon.printsize = new ZdcSize(30, 30); icon.offset = new ZdcPixel(-15,-15); icon.msgoffset = new ZdcPixel(0,-15); icon.shdoffset = new ZdcPixel(-3,-3); if(specialFlg) icon.shadowimage = '/images/map/marker/shadow_special.png'; else icon.shadowimage = '/images/map/marker/shadow_normal.png'; icon.shadowsize = new ZdcSize(40,40); return icon; }, mkMarker : function (poi) { if (typeof(poi.icon) != 'object') { alert('マーカー作成時にアイコンオブジェクトが指定されていません。'); return; } var marker = new ZdcMarker(poi.point, poi.icon); marker.type = 'hands'; marker.poiType = poi.poiType; marker.poiName = poi.poiName; marker.poiCode = poi.poiCode; marker.todCode = poi.todCode; marker.todName = poi.todName; marker.specialFlg = poi.specialFlg; marker.imgIcon = poi.imgIcon; marker.imgThumb = poi.imgThumb; marker.imgOriginal = poi.imgOriginal; marker.point = poi.point; marker.insDate = poi.insDate; ZdcEvent.addListener(marker, 'mouseovermarker', function(){ myprj.models.Tooltip.set(this) }); ZdcEvent.addListener(marker, 'mouseoutmarker', function(){ myprj.models.Tooltip.remove(); }); myprj.models._markers.push(marker); return marker; }, setMarkerClickEvent : function (marker) { ZdcEvent.addListener(marker, 'mouseclickmarker', function(){ window.location.href = '/poi/poi-detail.php?pid=' + marker.poiCode; }); }, getSurroundPoints : function (poi) { $.ajax({ type : "post", url : "/ajax/Poi/GetSurroundPoints.php", data : {json:JSON.stringify(poi)}, dataType : 'jsonp', jsonp : 'jsoncallback', success : function(result){ if (result == undefined) return; var markers = Array(); $(result).each(function (_key, _val) { _val.poiType = 'ClSurroundPoi'; _val.point = new ZdcPoint(parseFloat(_val.lon), parseFloat(_val.lat)); _val.icon = myprj.models.mkIcon(_val.imgIcon, _val.specialFlg); var marker = myprj.models.mkMarker(_val); myprj.models._layer.addMarker(marker); myprj.models.setMarkerClickEvent(marker); markers.push(marker); }); myprj.models.setSurroundPoints(markers); } }); }, setSurroundPoints : function (markers) { var cnt = 0; var tbody = $(''); var row = $(''); $(markers).each(function (_key, _val) { myprj.models.setMinMaxPoint(_val.Point); if (cnt == 3) { tbody.append(row); row = $(''); } row.append( $('').addClass('item').attr('width', '33%').attr('pid', _val.poiCode).append( $('').text(_val.insDate) ).append( $('
') ).append( $('').attr('src', _val.imgThumb).attr('alt', _val.poiName).attr('title', _val.poiName) ).append( $('
') ).append( $('').text(_val.poiName) ).append( $('
') ).append( $('').text(_val.todName) ).bind('click', function () { window.location.href = '/poi/poi-detail.php?pid=' + _val.poiCode; }) ); cnt++; }); tbody.append(row); $('#SurroundSpotList').append(tbody); $('#SurroundSpotList .item').bind('mouseover', function () { myprj.models.setActiveMarker($(this).attr('pid')); }); $('#SurroundSpotList .item').bind('mouseout', function () { myprj.models.delActiveMarker($(this).attr('pid')); }); scale = myprj._map.getMapBoxScale( new ZdcBox( new ZdcPoint(this._minLon, this._minLat), new ZdcPoint(this._maxLon, this._maxLat) ), this._marker_center.Point ); myprj._map.setMapScale(parseInt(scale)); }, setMinMaxPoint : function (point) { // Latitude if (point.lat < myprj.models._minLat || myprj.models._minLat == null) myprj.models._minLat = point.lat; if (point.lat > myprj.models._maxLat || myprj.models._maxLat == null) myprj.models._maxLat = point.lat; // Longitude if (point.lon < myprj.models._minLon || myprj.models._minLon == null) myprj.models._minLon = point.lon; if (point.lon > myprj.models._maxLon || myprj.models._maxLon == null) myprj.models._maxLon = point.lon; }, setActiveMarker : function (id) { $(this._markers).each(function (_key, _val) { if (_val.poiCode == id) { var icon = myprj.models.mkIcon(_val.imgIcon, _val.specialFlg); icon.shadowimage = '/images/map/marker/shadow_select.png'; this.setIcon(icon); } }); }, delActiveMarker : function (id) { $(this._markers).each(function (_key, _val) { if (_val.poiCode == id) { var icon = myprj.models.mkIcon(_val.imgIcon, _val.specialFlg); this.setIcon(icon); } }); }, Favorite : { insertPoi : function () { poi = { poiId : $('#poi_id').val() }; $.ajax({ type : "post", url : "/ajax/Poi/FavoriteIns.php", data : poi, success : function(result){ var AjaxResult = undefined; eval(result); if (AjaxResult) { alert('追加しました'); window.location.reload(); } } }); }, deletePoi : function () { if (confirm('削除してよろしいですか?')) { poi = { poiId : $('#poi_id').val() }; $.ajax({ type : "post", url : "/ajax/Poi/FavoriteDel.php", data : poi, success : function(result){ var AjaxResult = undefined; eval(result); if (AjaxResult) { window.location.reload(); } } }); } } }, Export : { insert : function () { poi = { poiId : $('#poiCode').val(), lat : $('#lat').val(), lon : $('#lon').val(), title : $('#poiName').val(), tel : $('#telNo').val() }; $.ajax({ type : "post", url : "/ajax/ExportIns.php", data : poi, success : function(result){ var AjaxResult = undefined; eval(result); if (AjaxResult) { alert('保存箱に移動しました。保存箱からカードに保存してください'); } } }); } }, setErrorMessage : function (messages) { $('#CommentError ul').remove(); errorList = ''; $(messages).each(function (_key, _val) { errorList += '
  • ' + _val + '
  • '; }); $('#CommentError').append($('
      ').html(errorList)); }, setToken : function (key) { $('#CommentToken').val(key); }, Tooltip : { set : function (marker) { $('#Tooltip').html(marker.poiName); $('#Tooltip').show(); }, remove : function () { $('#Tooltip').hide(); } }, chgDispRssItem : function (target) { $('#RssEntryList .detail').hide(); $(target).parent().children('.detail').show(); }, editPoi : function () { $('#EditForm').submit(); } }, // Model End events : function () { $(window.document).bind('mousemove', function( e ){ e = e || window.event; if(document.body != null){ $('#Tooltip')[0].style.left = (e.clientX + $(window).scrollLeft() + 15) + 'px'; $('#Tooltip')[0].style.top = (e.clientY + $(window).scrollTop() + 10) + 'px'; } }); $('#RssEntryList .head').bind('click', function () { myprj.models.chgDispRssItem(this); }); $('#BtnAddExport').bind('click', function () { myprj.models.Export.insert(); }); $('#BtnAddFavorite').bind('click', function () { myprj.models.Favorite.insertPoi(); }); $('#BtnDelFavorite').bind('click', function () { myprj.models.Favorite.deletePoi(); }); $('#BtnEditPoi').bind('click', function () { myprj.models.editPoi(); }); } // Event End } // All End