MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
MWF.xDesktop.requireApp("Template", "Explorer", null, false);
o2.require("MWF.widget.UUID", null, false);
MWF.xApplication.Attendance.AddressExplorer = new Class({
Extends: MWF.xApplication.Attendance.Explorer,
Implements: [Options, Events],
initialize: function(node, app, actions, options){
this.setOptions(options);
this.app = app;
this.path = "../x_component_Attendance/$AddressExplorer/";
this.cssPath = "../x_component_Attendance/$AddressExplorer/"+this.options.style+"/css.wcss";
this._loadCss();
this.actions = actions;
this.node = $(node);
this.initData();
},
reload: function(){
this.node.empty();
this.load();
},
load: function(){
this.loadToolbar();
this.loadContentNode();
this.loadContent();
this.setNodeScroll();
},
destroy: function(){
if( this.baiduMap ){
this.baiduMap.map.clearOverlays();
this.elementContentNode.destroy();
}
this.node.empty();
delete this;
},
loadContent : function( filterData ){
this.elementContentNode.empty();
//this.view = new MWF.xApplication.Attendance.AddressExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
//this.view.filterData = filterData;
//this.view.load();
this.actions.listWorkplace( function(json){
json.data = json.data || [];
this.wpContent = this.toolbarNode.getElements("[name=wpContent]")[0];
this.createList( json.data );
this.baiduMap = new MWF.xApplication.Attendance.AddressExplorer.BaiduMap( this.elementContentNode, this.app, this, {} );
this.baiduMap.load( json.data );
this.setContentSize();
}.bind(this));
},
setBiduAccount: function(){
var baiduAccountForm = new MWF.xApplication.Attendance.AddressExplorer.BaiduAccountForm( this );
baiduAccountForm.edit();
},
reloadList: function(){
this.actions.listWorkplace( function(json){
this.wpContent.empty();
this.createList( json.data || [] );
}.bind(this))
},
createList: function( data ){
var _self = this;
this.wdList = new Element("div", {
styles : this.css.wdList
}).inject( this.wpContent );
this.wdList.setStyle( "width" , this.toolbarNode.getSize().x - 470 + "px" );
data.each( function( d ){
var placeItem = new Element( "div", {
styles : this.app.css.toolbarContentItem,
text : d.placeName
}).inject( this.wdList );
placeItem.addEvents( {
"mouseover": function () {
this.setStyles( _self.app.css.toolbarItemNode_over );
this.addClass("mainColor_bg");
},
"mouseout": function () {
this.setStyles( _self.app.css.toolbarItemNode_normal );
this.removeClass("mainColor_bg");
},
"click": function(e){
this.obj.baiduMap.gotoMarker( this.data );
e.stopPropagation();
}.bind({ obj : this, data : d })
})
}.bind(this) );
// this.arrow = "up";
// if( this.wdList.getScrollSize().y > this.wpContent.getSize().y + 10){
//
// this.wdList.addEvent("click",function(e){
// if( this.arrow != "down" ){
// this.openList( e );
// }else{
// this.closeList( e )
// }
// }.bind(this));
//
// this.arrowNode = new Element("div.arrowNode",{
// "styles" : this.css.arrowNode
// }).inject( this.wpContent, "top" );
// this.arrowNode.addEvents({
// "mouseover" : function(){
// this.arrowNode.setStyles( this.categoryArrow != "down" ? this.css.arrowNode_over : this.css.arrowNode_down_over);
// }.bind(this),
// "mouseout" : function(){
// this.arrowNode.setStyles( this.categoryArrow != "down" ? this.css.arrowNode : this.css.arrowNode_down);
// }.bind(this),
// "click" : function( e ){
// if( this.arrow != "down" ){
// this.openList( e );
// }else{
// this.closeList( e )
// }
// }.bind(this)
// });
// }
},
_setContentSize: function(){
this.wdList.setStyle( "width" , this.toolbarNode.getSize().x - 370 + "px" );
},
openList : function( e ){
this.arrow = "down";
//this.arrowNode.setStyles(this.css.arrowNode_down_over );
this.arrowNode.setStyle("display","none");
this.wdList.setStyles(this.css.wdList_all);
window.closeList = this.closeList.bind(this);
this.app.content.addEvent("click", window.closeList );
e.stopPropagation();
},
closeList : function( e ){
this.arrow = "up";
//this.arrowNode.setStyles(this.css.arrowNode );
this.arrowNode.setStyle("display","");
this.wdList.setStyles(this.css.wdList);
this.app.content.removeEvent("click" , window.closeList );
e.stopPropagation();
},
createDocument: function(){
this.baiduMap.createMarker();
}
});
MWF.xApplication.Attendance.AddressExplorer.BaiduMap = new Class({
Implements: [Options, Events],
options: {
"style": "default"
},
initialize: function (container, app, explorer, options) {
this.container = container;
this.explorer = explorer;
this.app = app;
this.actions = explorer.actions;
this.setOptions(options);
this.markers = {};
this.markerInfoWindows = {};
},
load : function( markerData ){
this.markerData = markerData;
this.mapNode = new Element("div", {styles : {
width : "100%",
height : "99%"
}}).inject(this.container);
setTimeout( function(){
MWF.UD.getPublicData("baiduAccountKey", function (json) {
this.loadResource(null, json );
}.bind(this))
}.bind(this) , 200 )
},
loadResource: function (callback, ak) {
window.BMap_loadScriptTime = (new Date).getTime();
//var apiPath = "http://api.map.baidu.com/api?v=2.0&ak=Qac4WmBvHXiC87z3HjtRrbotCE3sC9Zg";
var apiPath;
var accountkey = ak || "Qac4WmBvHXiC87z3HjtRrbotCE3sC9Zg";
if( window.location.protocol.toLowerCase() === "https:" ){
window.HOST_TYPE = '2';
apiPath = "//api.map.baidu.com/getscript?v=2.0&ak="+accountkey+"&s=1&services=&t=20161219171637";
// apiPath = "https://api.map.baidu.com/api?v=1.0&type=webgl&ak="+accountkey+"&s=1&services=&t=20161219171637";
}else{
apiPath = "http://api.map.baidu.com/getscript?v=2.0&ak="+accountkey+"&services=&t=20161219171637";
}
if( !window.BDMapApiLoaded ){
COMMON.AjaxModule.loadDom(apiPath, function () {
window.BDMapApiLoaded = true;
if( !window.BDMarkerToolLoaded ){
COMMON.AjaxModule.load( "../x_component_Attendance/BDMarkerTool.js", function(){
window.BDMarkerToolLoaded = true;
this._loadMap();
if (callback)callback();
}.bind(this) );
}else{
this._loadMap();
if (callback)callback();
}
}.bind(this));
}else{
this._loadMap();
if (callback)callback();
}
},
_loadMap: function(){
if (navigator.geolocation){
try{
navigator.geolocation.getCurrentPosition(this.loadMap.bind(this), this.loadMap.bind(this));
}catch( e ){
this.loadMap();
}
}else{
this.loadMap();
}
},
loadMap: function(position){
this.createMap( position );
this.addMapControl();
if( this.markerData ){
this.addMarkerArray( this.markerData );
}
},
createMap: function( position ){
var point = null;
if (position && position.coords){
point = new BMap.Point(position.coords.longitude, position.coords.latitude);
}
if( !point ){
if( this.markerData && this.markerData.length > 0){
var json = this.markerData[0];
point = new BMap.Point(json.longitude, json.latitude);
}else{
point = new BMap.Point(116.404, 39.915);
}
}
var map = this.map = new BMap.Map(this.mapNode); // 创建Map实例
map.centerAndZoom(point, 12); // 初始化地图,设置中心点坐标和地图级别
// map.centerAndZoom(new BMap.Point(116.404, 39.915), 11); // 初始化地图,设置中心点坐标和地图级别
// map.setCurrentCity("北京"); // 设置地图显示的城市 此项是必须设置的
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
},
addMapControl: function(){
//向地图中添加缩放控件
var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_RIGHT,type:BMAP_NAVIGATION_CONTROL_LARGE});
this.map.addControl(ctrl_nav);
//向地图中添加缩略图控件
var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
this.map.addControl(ctrl_ove);
//向地图中添加比例尺控件
var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
this.map.addControl(ctrl_sca);
//map.addControl(new this.mapWindow.BMap.MapTypeControl()); //添加地图类型控件
this.addCityListControl();
},
addCityListControl : function(){
this.map.addControl(new BMap.CityListControl({
anchor: BMAP_ANCHOR_TOP_LEFT,
offset: new BMap.Size(10, 20),
// 切换城市之间事件
onChangeBefore: function( ){
},
// 切换城市之后事件
onChangeAfter:function( ){
}
}));
},
getInfoWindowHtml: function( json ){
json = json || {};
//拼接infowindow内容字串
var html = [];
html.push('
');
html.push('
'+ this.app.lp.name1 +': | '); html.push(''); html.push(' | * | '); html.push('
'+this.app.lp.alias+': | '); html.push(''); html.push(' | '); html.push(' |
'+this.app.lp.range+': | '); html.push(''); html.push(' | '+this.app.lp.meter+' | '); html.push('
'+this.app.lp.description+': | '); html.push(''); html.push(' | '); html.push(' |
'); html.push(' '); if( json.id ){ html.push(' '); } html.push(' '); html.push(' | '); html.push('