/**
* @fileoverview 工具 测量地图面积 模块
* @author Song.Huang
* @version 1.0.0
*/
define(['vendorDir/map23dlib/leaflet.choosebounds'],
function(){
/**
* 状态值
* @type {Boolean}
* @default false
* @private
*/
var status ={
initialized:false//是否初始化
}
/**
* 模块数据 用于数据存储和外部调用
* @type {Object}
* 数据存放
*/
var modValue ={
loopAjaxTimeOut:{},
time_stamp:'',
postData:null,
mapChoose:null
}
var status = {
countingLock:false
}
/**
* 初始化
* 监听事件
* @type {Function}
*/
function init(){
if(!status.initialized){
status.initialized = true;
setLayout();
bindEvent();
subscribe();
modValue.mapChoose = L.control.mapChoose().addTo(map2DViewer.map);
//map2DViewer.map.on('mapShot:postData',modValue.mapShotPostData,this);
}
ONEMAP.C.publisher.publish({
modName:'toolMapChoose'
},'tools:active');
};
function setLayout(){
$('body').append($('
'));
$(window).resize(function() {
layoutResize();
});
};
function bindEvent(){
};
function layoutResize(){
var curWindowHeigth = $(window).height();
if(map23DData.display.map2D){
if(curWindowHeigth < 955){
$("#mapHolder .leaflet-mapshot-info").css({
"left":-130
})
}else{
$("#mapHolder .leaflet-mapshot-info").css({
"left":-179
})
}
}else{
$("#mapHolder .leaflet-mapshot-info").css({
"left":-179
})
}
};
function mapShotPostData(postData){
modValue.postData = postData;
var LTpx = map2DViewer.map.project(
new L.LatLng(JSON.parse(postData.bbox)[1],JSON.parse(postData.bbox)[0]),
postData.zoom
);
var RBpx = map2DViewer.map.project(
new L.LatLng(JSON.parse(postData.bbox)[3],JSON.parse(postData.bbox)[2]),
postData.zoom
);
var countDownTF = parseInt(((RBpx.x-LTpx.x)*(RBpx.y-LTpx.y))/(5120*5120));
if(countDownTF > onemapUrlConfig.mapShotMaxPicCount){
$('#mapShotDownload p').html('当前范围产生'+countDownTF+'个图幅数,'+
'
已经超过单次下载'+onemapUrlConfig.mapShotMaxPicCount+'个最大图幅数(5120×5120像素/图幅),请分开截图!
'+
'修改区域')
$('#mapShotDownload').show();
return false;
}
$('#mapShotDownload').show();
var nDate = new Date();
modValue.time_stamp = nDate.getTime();
var url = onemapUrlConfig.mapShotDownServerUrl+'/puzzles/?bbox='+postData.bbox+'&zoom='+postData.zoom+'&type='+postData.guid+'&ext='+postData.ext+'&time_stamp='+modValue.time_stamp+'&name='+encodeURI(postData.name);
$.ajax({
type:"get",
url:url,
dataType:'jsonp',
jsonp:'callback',
success:function(data){
//modValue._loopGetResult({ajaxKey:'1'});
}
});
setTimeout(function(){
loopGetResult({ajaxKey:modValue.time_stamp});
}, 1000);
};
function againMapShotPostData(){
mapShotPostData(modValue.postData);
}
function loopGetResult(options){
};
function continueMapShot(){
if(modValue.loopAjaxTimeOut.hasOwnProperty(modValue.time_stamp)){
clearTimeout(modValue.loopAjaxTimeOut[modValue.time_stamp]);
}
$('#mapShotDownload').hide().html('正在提交截图数据到服务器
');
}
function exitMapShot(){
$('#mapshotScreen').click();
modValue.mapChoose.remove();
$('#mapShotDownload').hide()
}
/**
* 注册监听
*/
function subscribe(){
ONEMAP.C.publisher.subscribe(remove, 'tools:active');
ONEMAP.C.publisher.subscribe(mapShotPostData,'mapShot:postData');
};
/**
* 功能移除
*/
function remove(options){
// console.log(options.modName);
// 防止与截图功能发生混乱
if(options.modName == 'toolMapShot'){
return false;
} else{
modValue.mapChoose.init();
}
};
return ONEMAP.M.toolMapChoose = {
init:init
}
});