123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900 |
- /**
- * @fileoverview 工具 测量地图面积 模块
- * @author Song.Huang
- * @version 1.0.0
- */
- define(['vendorDir/map23dlib/leaflet.mapshot',
- 'css!vendorDir/map23dlib/leaflet.mapshot'
- ],
- function() {
- /**
- * 状态值
- * @type {Boolean}
- * @default false
- * @private
- */
- var status = {
- initialized: false //是否初始化
- }
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- loopAjaxTimeOut: {},
- time_stamp: '',
- postData: null,
- mapShotControl: null,
- offsetX :[0,0,108000,72000,54000,27000,13500,10800,5400,2700,1350,675,450,225,135,90,45,30,20,10],
- offsetY :[0,0,72000,54000,36000,18000,9000,7200,3600,1800,900,450,300,150,90,60,30,20,10,5],
- BLC: [200000000, 100000000, 50000000, 25000000, 12000000, 6000000, 1600000, 1550000, 800000, 400000, 200000, 100000, 50000, 25000, 12000, 2300, 3000, 1500, 800],
- scaleMap:[591657527.6,295828763.8,147914381.9,73957190.95,36978595.47,18489297.74,9244648.868,4622324.434,2311162.217,1155581.109,577790.5543,288895.2771,144447.6386,72223.81928,36111.90964,18055.95482,9027.97741,4513.988705,2256.994353,1128.497176]
- }
- var status = {
- countingLock: false
- }
- /**
- * 初始化
- * 监听事件
- * @type {Function}
- */
- function init(type) {
- if (!status.initialized) {
- status.initialized = true;
- setLayout();
- bindEvent();
- subscribe();
- modValue.mapShotControl = L.control.mapShot().addTo(map2DViewer.map);
- }
- if (type == 2) {
- ONEMAP.C.publisher.publish({
- modName: 'msAll'
- }, 'tools:active');
- } else {
- ONEMAP.C.publisher.publish({
- modName: 'toolMapShot'
- }, 'tools:active');
- }
- }
- function setLayout() {
- $('body').append($('<div id="mapShotDownload"><p></p></div>'));
- $('body').append($('#toolsBar .zhengshiDl'));
- $(window).resize(function() {
- layoutResize();
- });
- };
- function bindEvent() {
- };
- function layoutResize() {
- };
- function mapfishPostData(postData) {
- var newPostData = encodeURIComponent(changeMapShotData(postData));
- // console.log(modValue.mapShotDrawData)
- //var appId = 'print_osm_new_york_EPSG_900913';
- var appId = "print_osm_EPSG3857";
- if($("#paperSize").val() == 4){
- appId = 'print_osm_EPSG3857';
- }else if($("#paperSize").val() == 3){
- appId = 'print_osm_EPSG3857_a3';
- }
-
- var format = postData.ext;
- //console.log(changeMapShotData(postData));
- var startTime = new Date().getTime();
- ONEMAP.C.publisher.publish({ type: 'success', message: '开始下载' }, 'noteBar::add');
- //return false;
- $.ajax({
- type: 'POST',
- url: onemapUrlConfig.mapFishServerUrl + '/print/' + appId + '/report.' + format,
- data: newPostData,
- success: function(data) {
- downloadWhenReady(startTime, data);
- },
- error: function(data) {
- ONEMAP.C.publisher.publish({ type: 'error', message: '下载出错' }, 'noteBar::add');
- },
- dataType: 'json'
- });
- };
- function downloadWhenReady(startTime, data) {
- if ((new Date().getTime() - startTime) > 30000) {
- ONEMAP.C.publisher.publish({ type: 'success', message: '准备下载' }, 'noteBar::add');
- } else {
- updateWaitingMsg(startTime, data);
- setTimeout(function() {
- $.getJSON(onemapUrlConfig.mapFishServerUrl + data.statusURL, function(statusData) {
- if (!statusData.done) {
- downloadWhenReady(startTime, data);
- } else {
- window.location = onemapUrlConfig.mapFishServerUrl + statusData.downloadURL;
- //ONEMAP.C.publisher.publish({ type: 'success', message: 'Downloading: ' + data.ref }, 'noteBar::add');
- }
- }, function error(data) { ONEMAP.C.publisher.publish({ type: 'error', message: '下载出错' }, 'noteBar::add') });
- }, 1000);
- }
- }
- function changeMapShotData(postData) {
- var scale = modValue.BLC[postData.zoom - 1];
- var mapcenter = lonlatToMercator(postData.center);
- var geojsonFeatures = [];
- var geojsonStyles = {};
- if ($(".zhengshiDl .stw").is(':checked')) {
- //计算截图中心点
- var ST = getPaperBounds(
- {
- lat:postData.center[1],
- lng:postData.center[0]
- },
- 297,
- 210,
- postData.zoom
- )
-
- //获取截图元素数据
- $.each(ST.polylineArry,function(i,t){
- var guid = map23DControl.buildGuid('mapfish_style');
- var polylinescoor = [];
- for (var i = 0; i < t.length; i++) {
- curpolylinescoor = stringToParse([t[i][1], t[i][0]]);
- curpolylinescoor = lonlatToMercator(curpolylinescoor);
- polylinescoor.push(curpolylinescoor);
- }
- var guid = guid;
- var fItem = {
- "geometry": {
- "coordinates": polylinescoor,
- "type": "LineString"
- },
- "properties": {
- "_gx_style": guid
- },
- "type": "Feature"
- };
- geojsonStyles[guid] = {
- "strokeColor": "#04cfed",
- "strokeDashstyle": "solid",
- "strokeLinecap": "round",
- "strokeOpacity": 1,
- "strokeWidth": 2
- };
- geojsonFeatures.push(fItem);
- })
- $.each(ST.markerArry,function(i,t){
- var guid = map23DControl.buildGuid('mapfish_style');
- var curmarkerCoor = stringToParse([t.latlng[1], t.latlng[0]]);
- curmarkerCoor = lonlatToMercator(curmarkerCoor)
- var fItem = {
- "geometry": {
- "coordinates": curmarkerCoor,
- "type": "Point"
- },
- "properties": {
- "_gx_style": guid
- },
- "type": "Feature"
- };
- geojsonStyles[guid] = {
- "fontColor": "#ff6600",
- "fontSize": "40px",
- "fontStyle": "normal",
- "fontWeight": "normal",
- "label": t.title,
- "labelAlign": "cm",
- "labelXOffset": t.offset[0],
- "labelYOffset": t.offset[1],
- };
- geojsonFeatures.push(fItem);
- })
- }
-
- $.each(map2DViewer.map._layers, function(i, t) {
- var guid = map23DControl.buildGuid('mapfish_style');
- if (t.shape == 'Marker') {
- var curmarkerCoor = stringToParse([t._latlng.lng, t._latlng.lat]);
- curmarkerCoor = lonlatToMercator(curmarkerCoor)
- var fItem = {
- "geometry": {
- "coordinates": curmarkerCoor,
- "type": "Point"
- },
- "properties": {
- "_gx_style": guid
- },
- "type": "Feature"
- };
- var iconUrl = onemapUrlConfig.siteUrl + '/scripts/vendor/leaflet/draw_new/images/marker-icon.png';
- if (t.options.icon) {
- iconUrl = t.options.icon.options.iconUrl;
- if (iconUrl.length < 18) {
- iconUrl = onemapUrlConfig.siteUrl + '/scripts/vendor/leaflet/draw_new/images/marker-icon.png';
- }
- geojsonStyles[guid] = {
- "fillColor": "#ff0000",
- "fillOpacity": 1,
- "pointRadius": 25,
- "externalGraphic": iconUrl,
- "graphicOpacity": 1,
- "graphicFormat": "image/png"
- };
- geojsonFeatures.push(fItem);
- }
- if (t.zhuji) {
- var zguid = map23DControl.buildGuid('mapfish_style');
- var zfItem = {
- "geometry": {
- "coordinates": curmarkerCoor,
- "type": "Point"
- },
- "properties": {
- "_gx_style": zguid
- },
- "type": "Feature"
- };
- geojsonStyles[zguid] = {
- "fontColor": "#f00",
- "fontFamily": "黑体",
- "fontSize": "20px",
- "fontStyle": "normal",
- "fontWeight": "normal",
- "label": t.zhuji,
- "labelAlign": "cm",
- "labelXOffset": "60.0",
- "labelYOffset": "65.0",
- };
- geojsonFeatures.push(zfItem);
- }
- } else if (t.shape == 'Line') {
- var polylinescoor = [];
- for (var i = 0; i < t._latlngs.length; i++) {
- curpolylinescoor = stringToParse([t._latlngs[i].lng, t._latlngs[i].lat]);
- curpolylinescoor = lonlatToMercator(curpolylinescoor);
- polylinescoor.push(curpolylinescoor);
- }
- var guid = guid;
- var fItem = {
- "geometry": {
- "coordinates": polylinescoor,
- "type": "LineString"
- },
- "properties": {
- "_gx_style": guid
- },
- "type": "Feature"
- };
- geojsonStyles[guid] = {
- "strokeColor": t.options.color,
- "strokeDashstyle": "solid",
- "strokeLinecap": "round",
- "strokeOpacity": 1,
- "strokeWidth": 2
- };
- geojsonFeatures.push(fItem);
- } else if (t.shape == 'Poly' || t.shape == 'Rectangle') {
- var polygonscoor = [];
- polygonscoor[0] = [];
- for (var i = 0; i <= t._latlngs[0].length; i++) {
- if (i < t._latlngs[0].length) {
- var curpolygonscoor = stringToParse([t._latlngs[0][i].lng, t._latlngs[0][i].lat]);
- curpolygonscoor = lonlatToMercator(curpolygonscoor);
- polygonscoor[0].push(curpolygonscoor);
- } else {
- var curpolygonscoor = stringToParse([t._latlngs[0][0].lng, t._latlngs[0][0].lat]);
- curpolygonscoor = lonlatToMercator(curpolygonscoor);
- polygonscoor[0].push(curpolygonscoor);
- }
- }
- var fItem = {
- "geometry": {
- "coordinates": polygonscoor,
- "type": "Polygon"
- },
- "properties": {
- "_gx_style": guid
- },
- "type": "Feature"
- };
- geojsonStyles[guid] = {
- "fillColor": t.options.color,
- "fillOpacity": 0.5,
- "strokeColor": t.options.color,
- "strokeDashstyle": "solid",
- "strokeLinecap": "round",
- "strokeOpacity": 1,
- "strokeWidth": 2
- };
- geojsonFeatures.push(fItem);
- } else if (t.shape == 'Circle') {
- //圆心
- var allCirclePoint = [];
- var center_lat = t._latlng.lat;
- var center_lon = t._latlng.lng;
- //半径
- var radius = t.options.radius; //米
- //转换定义 核心
- var epsg_4326 = "+proj=longlat +datum=WGS84 +no_defs "
- var esri_102016 = "+proj=aeqd +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs"
- var self_defined = "+proj=aeqd +lat_0=" + center_lat + "+lon_0=" + center_lon + "+x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs"
- //生成圆平面点;
- var pointArr = L.Util.getCirclePoint(0, 0, radius);
- //圆的轮廓点转换为经纬度,当做GeoJSON来使用。
- var circlePoints = [];
- for (var k = 0; k < pointArr.length; k++) {
- var item = pointArr[k];
- //核心 将平面坐标转经纬度坐标
- var xy = proj4(self_defined, epsg_4326, [item.x, item.y]);
- circlePoints.push([
- xy[0],
- xy[1]
- ])
- }
- var polygonscoor = [];
- polygonscoor[0] = [];
- for (var i = 0; i < circlePoints.length + 1; i++) {
- if (i < circlePoints.length) {
- var curpolygonscoor = stringToParse([circlePoints[i][0], circlePoints[i][1]]);
- curpolygonscoor = lonlatToMercator(curpolygonscoor);
- polygonscoor[0].push(curpolygonscoor);
- } else {
- var curpolygonscoor = stringToParse([circlePoints[0][0], circlePoints[0][1]]);
- curpolygonscoor = lonlatToMercator(curpolygonscoor);
- polygonscoor[0].push(curpolygonscoor);
- }
- }
- var fItem = {
- "geometry": {
- "coordinates": polygonscoor,
- "type": "Polygon"
- },
- "properties": {
- "_gx_style": guid
- },
- "type": "Feature"
- };
- geojsonStyles[guid] = {
- "fillColor": t.options.color,
- "fillOpacity": 0.5,
- "strokeColor": t.options.color,
- "strokeDashstyle": "solid",
- "strokeLinecap": "round",
- "strokeOpacity": 1,
- "strokeWidth": 2
- };
- geojsonFeatures.push(fItem);
- } else if (t.shape == 'Label') {
- var curmarkerCoor = stringToParse([t._latlng.lng, t._latlng.lat]);
- curmarkerCoor = lonlatToMercator(curmarkerCoor)
- var fItem = {
- "geometry": {
- "coordinates": curmarkerCoor,
- "type": "Point"
- },
- "properties": {
- "_gx_style": guid
- },
- "type": "Feature"
- };
- if (t.options.icon) {
- var cl = t.options.icon.options.className;
- var scolor = $(".leaflet-marker-icon." + cl).css("color");
- var slb = $(".leaflet-marker-icon." + cl).text();
- var sfont = $(".leaflet-marker-icon." + cl).css("font-family");
- if (scolor != undefined) {
- geojsonStyles[guid] = {
- "fontColor": scolor,
- "fontFamily": sfont || 'microsoft yahei',
- "fontSize": t.options.icon.options.iconSize + "px",
- "fontStyle": "normal",
- "fontWeight": "normal",
- "label": t.zhuji || slb,
- "labelAlign": "cm",
- "labelXOffset": "-25.0",
- "labelYOffset": "-35.0",
- };
- console.log(guid)
- console.log(geojsonStyles[guid])
- geojsonFeatures.push(fItem);
- }
- } else {
- geojsonStyles[guid] = {
- "fontColor": t.options.Oc,
- "fontFamily": t.options.Off,
- "fontSize": t.options.Ofz + "px",
- "fontStyle": "normal",
- "fontWeight": "normal",
- "label": t.options.txt,
- "labelAlign": "cm",
- "labelXOffset": "-25.0",
- "labelYOffset": "-35.0",
- };
- geojsonFeatures.push(fItem);
- }
- }
- })
- geojsonStyles.styleProperty = "_gx_style";
- geojsonStyles.version = 1;
-
- var curpostData = {
- "outputFormat": "png",
- "attributes": {
- "description": postData.mapshotcopyright,
- //"northArrowDef": nad,
- "map": {
- "center": mapcenter,
- "dpi": 72,
- "layers": [{
- "geoJson": {
- "features": geojsonFeatures,
- "type": "FeatureCollection"
- },
- "style": geojsonStyles,
- "type": "geojson"
- }, {
- // "baseURL": map23DConfig.tileServerUrl + "/" + postData.guid + "?l={z}&x={x}&y={y}",
- "baseURL": map23DConfig.tileServerFo3DUrl + "/" + postData.guid + "?l={z}&x={x}&y={y}",
- "imageExtension": "png",
- "type": "OSM"
- }],
- "projection": "EPSG:3857",
- "rotation": 0,
- "scale": scale,
- "useAdjustBounds": true
- // "height":20
- },
- "title": postData.mapshotName,
- //"scalebar": scb
- },
- "layout": "A4 landscape"
- }
- if (!$(".zhengshiDl .blc").is(':checked')) {
- curpostData.attributes.scalebar = {
- "barSize": 0,
- "padding": 0,
- "backgroundColor": "rgba(255,255,255,0.001)",
- "barBgColor": "rgba(255,255,255,0.001)",
- "color": "rgba(255,255,255,0.001)",
- "fontColor": "rgba(255,255,255,0.001)"
- }
- }
- if (!$(".zhengshiDl .zbz").is(':checked')) {
- curpostData.attributes.northArrowDef = {
- "backgroundColor": "rgba(255,255,255,0.001)",
- "graphic": onemapUrlConfig.siteUrl + "/images/layout/0.png"
- }
- }
- return postData = JSON.stringify(curpostData);
- };
- function updateWaitingMsg(startTime, data) {
- var elapsed = Math.floor((new Date().getTime() - startTime) / 100);
- var time = '';
- if (elapsed > 5) {
- time = (elapsed / 10) + " sec";
- }
- ONEMAP.C.publisher.publish({ type: 'success', message: '等候时间' + time }, 'noteBar::add');
- }
- //经纬度转魔卡托
- function lonlatToMercator(lonlat) {
- var mercator = [];
- var x = lonlat[0] * 20037508.34 / 180;
- var y = Math.log(Math.tan((90 + lonlat[1]) * Math.PI / 360)) / (Math.PI / 180);
- y = y * 20037508.34 / 180;
- mercator.push(x);
- mercator.push(y);
- return mercator;
- }
- function stringToParse(lnglat) {
- var x = JSON.parse(lnglat[0]);
- var y = JSON.parse(lnglat[1]);
- var parsecoor = [x, y];
- return parsecoor;
- }
- 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) {
- var xiangsu = parseInt(5120 * Math.sqrt(onemapUrlConfig.mapShotMaxPicCount));
- $('#mapShotDownload p').html('地图拼接下载像素超过了' + xiangsu + '×' + xiangsu + '像素,请缩小截图下载区域<br/>' +
- '<span id="continueMapShot" onclick="ONEMAP.M.toolMapShot.continueMapShot()">修改区域</span>')
- $('#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) {
- $.ajax({
- url: onemapUrlConfig.mapShotDownServerUrl + '/processing/' + modValue.time_stamp,
- type: "get",
- dataType: 'jsonp',
- jsonp: 'callback',
- success: function(data) {
- if (data.processing == '') {
- $('#mapShotDownload p').html('服务器处理失败,请重试! <br/><span id="continueMapShot" onclick="ONEMAP.M.toolMapShot.againMapShot()">再次提交</span>');
- }
- if (data.processing.length < 3) {
- if (modValue.loopAjaxTimeOut.hasOwnProperty(options.ajaxKey)) {
- clearTimeout(modValue.loopAjaxTimeOut[options.ajaxKey]);
- }
- $('#mapShotDownload p').html('服务器正在截图,截图进度 ' + data.processing + ' %. <br/><span id="continueMapShot" onclick="ONEMAP.M.toolMapShot.continueMapShot()">取消截图</span>');
- modValue.loopAjaxTimeOut[options.ajaxKey] = setTimeout(function() {
- loopGetResult(options);
- }, 1000);
- } else if (data.processing == '100') {
- if (modValue.loopAjaxTimeOut.hasOwnProperty(options.ajaxKey)) {
- clearTimeout(modValue.loopAjaxTimeOut[options.ajaxKey]);
- }
- $('#mapShotDownload p').html('服务器已完成截图,正在进行打包. <br/><span id="continueMapShot" onclick="ONEMAP.M.toolMapShot.continueMapShot()">取消截图</span>');
- modValue.loopAjaxTimeOut[options.ajaxKey] = setTimeout(function() {
- loopGetResult(options);
- }, 1000);
- } else {
- delete modValue.loopAjaxTimeOut[options.ajaxKey];
- //获取最终结果
- $('#mapShotDownload p').html('服务器截图完成,<a target="_blank" href="' + onemapUrlConfig.mapShotDownServerUrl + '/image_zip/' + data.processing + '">点击下载!</a><br/><span id="continueMapShot" onclick="ONEMAP.M.toolMapShot.continueMapShot()">继续截图</span><span style="cursor:pointer" onclick="ONEMAP.M.toolMapShot.exitMapShot();">退出截图</span>')
- //alert(data);
- }
- }
- });
- };
- function continueMapShot() {
- if (modValue.loopAjaxTimeOut.hasOwnProperty(modValue.time_stamp)) {
- clearTimeout(modValue.loopAjaxTimeOut[modValue.time_stamp]);
- }
- $('#mapShotDownload').hide().html('<p>正在提交截图数据到服务器</p>');
- }
- function exitMapShot() {
- $('#mapshotScreen').click();
- modValue.mapShotControl.remove();
- $('#mapShotDownload').hide()
- }
- function mapChange() {
- var centerlng = (map2DViewer.map.getCenter().lng).toFixed(5);
- var centerlat = (map2DViewer.map.getCenter().lat).toFixed(5);
- $(".zhengshiDl #mapfishCenter").html("纬度:" + centerlat + ",经度:" + centerlng);
- }
- /**
- * [getPaperBounds description]
- * 根据中心点经纬度和纸张大小获取纸张经纬度范围
- * @return {[type]} [description]
- */
- function getPaperBounds(center, width, height,zoom) {
- //中心点经纬度转墨卡托
- var centerMercator = L.Util.transformMercator({
- x: center.lng,
- y: center.lat
- })
- //根据纸张大小和所选比例尺等级确定墨卡托范围
- var scale = modValue.scaleMap[zoom-1];
- var scaleWidth = scale * width /1000 / 2;
- var scaleHeight = scale * height /1000 / 2;
- var NElatlng = {
- X: centerMercator.x + scaleWidth,
- Y: centerMercator.y + scaleHeight
- }
- var SWlatlng = {
- X: centerMercator.x - scaleWidth,
- Y: centerMercator.y - scaleHeight
- }
- NElatlng = L.Util.formMercatorToLatlng(NElatlng);
- SWlatlng = L.Util.formMercatorToLatlng(SWlatlng);
- return showSTLayer({
- zoom:zoom,
- bounds:{
- _northEast:{
- lat:NElatlng.Y,
- lng:NElatlng.X
- },
- _southWest:{
- lat:SWlatlng.Y,
- lng:SWlatlng.X
- }
- }
- })
- }
- function showSTLayer(options) {
- var offsetX = modValue.offsetX[options.zoom];
- var offsetY = modValue.offsetY[options.zoom];
- var startSW = {
- lat: (parseInt(options.bounds._southWest.lat * 3600 / offsetY) - 1) * offsetY,
- lng: (parseInt(options.bounds._southWest.lng * 3600 / offsetX) - 1) * offsetX
- };
- var startNE = {
- lat: (parseInt(options.bounds._northEast.lat * 3600 / offsetY) + 1) * offsetY,
- lng: (parseInt(options.bounds._northEast.lng * 3600 / offsetX) + 1) * offsetX
- };
- var polylineArry = [];
- var markerArry = [];
- //todo 这里需要做下优化 优化内容: 经纬度坐标文字更新和画线更新分离开来,让地图移动的时候让文字始终靠在界面边上
- for (var i = startSW.lat; i < startNE.lat; i += offsetY) {
- polylineArry.push([
- [i / 3600, startSW.lng / 3600],
- [i / 3600, startNE.lng / 3600]
- ])
- //左
- if (L.Util.verifyLatLng(i / 3600, options.bounds._southWest.lng)) {
- markerArry.push({
- latlng:[i / 3600, options.bounds._southWest.lng],
- title:formatHMS([i, options.bounds._southWest.lng*3600]).lat,
- offset:[60,0]
- })
- }
- //右
- if (L.Util.verifyLatLng(i / 3600, options.bounds._northEast.lng)) {
- markerArry.push({
- latlng:[i / 3600, options.bounds._northEast.lng],
- title:formatHMS([i, options.bounds._northEast.lng*3600]).lat,
- offset:[-10,0]
- })
- }
- }
- for (var ii = startSW.lng; ii < startNE.lng; ii += offsetX) {
- polylineArry.push([
- [startSW.lat / 3600, ii / 3600],
- [startNE.lat / 3600, ii / 3600]
- ])
- if (L.Util.verifyLatLng(options.bounds._southWest.lat, ii / 3600)) {
- markerArry.push({
- latlng:[options.bounds._southWest.lat, ii / 3600],
- title:formatHMS([options.bounds._southWest.lng*3600, ii]).lng,
- offset:[0,-60]
- })
- }
- if (L.Util.verifyLatLng(options.bounds._northEast.lat, ii / 3600)) {
- markerArry.push({
- latlng:[options.bounds._northEast.lat, ii / 3600],
- title:formatHMS([options.bounds._northEast.lng*3600, ii]).lng,
- offset:[0,90]
- })
- }
- }
- return {
- polylineArry:polylineArry,
- markerArry:markerArry
- }
- }
- /**
- * 分格式化
- * @param {[type]} latlng [分]
- * @return {[type]} [description]
- */
- function formatHMS(latlng){
- var lat = latlng.hasOwnProperty('lat')?latlng.lat:latlng[0];
- var lng = latlng.hasOwnProperty('lng')?latlng.lng:latlng[1];
- function setHMS(f){
- var h = parseInt(f/3600);
- var m = parseInt((f-h*3600)/60);
- var s = parseInt((f-h*3600-m*60));
-
- if(m.toString().length == 1){
- m = '0' + m.toString();
- }
- if(s.toString().length == 1){
- s = '0' + s.toString();
- }
- return h + '\u00b0' + m + '\u2032' + s + '\u2033';
- }
- var nLat = '';
- var nLng = '';
- if (lat < 0) {
- nLat = setHMS(lat * -1)+'S';
- } else {
- nLat = setHMS(lat)+'N';
- }
- if (lng < 0) {
- nLng = setHMS(lng * -1)+'W';
- } else {
- nLng = setHMS(lng)+'E';
- }
- return {lat:nLat,lng:nLng};
- };
- /**
- * 注册监听
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(remove, 'tools:active');
- ONEMAP.C.publisher.subscribe(mapShotPostData, 'mapShot:postData');
- ONEMAP.C.publisher.subscribe(mapfishPostData, 'mapFish:postData');
- ONEMAP.C.publisher.subscribe(mapChange, 'mapChange');
- };
- function mapfishInit() {
- var baseMapObj = {
- translate: null,
- guid: null
- }
- baseMapObj.guid = ONEMAP.M.mapHolder.modValue.mainLayers;
- if (baseMapObj.guid === 'gm') {
- baseMapObj.translate = '交通图';
- baseMapObj.guid = 'gm';
- }
- if (baseMapObj.guid === 'gr') {
- baseMapObj.translate = '影像图';
- baseMapObj.guid = 'gr';
- }
- if (baseMapObj.guid === 'gr') {
- baseMapObj.translate = '影像叠加地名图';
- baseMapObj.guid = 'gr';
- }
- if (baseMapObj.guid === 'gt') {
- baseMapObj.translate = '地势图';
- baseMapObj.guid = 'gt';
- }
- $(".zhengshiDl").addClass('active');
- $(".zhengshiDl .name").attr("placeholder", baseMapObj.translate)
- $(".zhengshiDl .bili").val(map2DViewer.map.getZoom());
- var centerlng = (map2DViewer.map.getCenter().lng).toFixed(5);
- var centerlat = (map2DViewer.map.getCenter().lat).toFixed(5);
- $(".zhengshiDl #mapfishCenter").html("纬度:" + centerlat + ",经度:" + centerlng);
- $(".zhengshiDl .subdiv button").off("click").on("click", function() {
- postScreenMapFishInfo(baseMapObj);
- })
- }
- function postScreenMapFishInfo(curLayerObj) {
- var centerlng = (map2DViewer.map.getCenter().lng).toFixed(5) / 1;
- var centerlat = (map2DViewer.map.getCenter().lat).toFixed(5) / 1;
- newdata = new Date();
- year = newdata.getFullYear();
- month = newdata.getMonth() + 1;
- day = newdata.getDate().toString();
- var hour = newdata.getHours().toString();
- var mintes = newdata.getMinutes().toString();
- var second = newdata.getSeconds().toString();
- if (month < 10) {
- // month = "0" + month;
- }
- if (day < 10) {
- day = "0" + day;
- }
- if (hour < 10) {
- hour = "0" + hour;
- }
- if (mintes < 10) {
- mintes = "0" + mintes;
- }
- if (second < 10) {
- second = "0" + second;
- }
- var time = year + "年" + month + "月" + day + "日 " + hour + ":" + mintes + ":" + second;
- if (curLayerObj.guid == "gr") {
- curLayerObj.guid = 'gh';
- }
- var svname = $(".zhengshiDl .name").val();
- if (svname == "") {
- svname = curLayerObj.translate;
- }
- var svzoom = $('.zhengshiDl .bili option:selected').val();
- var svimgtype = $(".zhengshiDl .geshi option:selected").val();
- // $(_this.selectZoom).val()
- var postDataMapfish = {
- center: [centerlng, centerlat],
- name: svname,
- zoom: svzoom, //_this.selectZoom.value
- guid: curLayerObj.guid,
- ext: svimgtype, //'png'
- mapshotName: svname, //_this.curLayerObj.translate
- mapshotcopyright: time
- }
- ONEMAP.C.publisher.publish(postDataMapfish, 'mapFish:postData');
- }
- /**
- * 功能移除
- */
- function remove(options) {
- if (options.modName == 'toolMapShot') {
- if ($('.tools-mapshot').hasClass('cur')) {
- $('.tools-mapshot').removeClass('cur');
- modValue.mapShotControl.remove();
- } else {
- $('.tools-mapshot').addClass('cur');
- $('.tools-msAll').removeClass('cur');
- $(".zhengshiDl").removeClass('active')
- modValue.mapShotControl.init();
- }
- } else if (options.modName == 'msAll') {
- if ($('.tools-msAll').hasClass('cur')) {
- $('.tools-msAll').removeClass('cur');
- $(".zhengshiDl").removeClass('active');
- modValue.mapShotControl.remove();
- } else {
- $('.tools-msAll').addClass('cur');
- $('.tools-mapshot').removeClass('cur');
- $('#mapHolder .leaflet-mapshot-info').hide()
- modValue.mapShotControl.remove();
- mapfishInit();
- }
- } else {
- $('.tools-mapshot').removeClass('cur')
- $('.tools-msAll').removeClass('cur');
- $(".zhengshiDl").removeClass('active')
- modValue.mapShotControl.remove();
- }
- };
- return ONEMAP.M.toolMapShot = {
- init: init,
- continueMapShot: continueMapShot,
- exitMapShot: exitMapShot
- }
- });
|