123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- define(function () {
- var status = {
- initialized: false,
- firstAddMeasuring: true
- };
- var modValue = {
- mearsuringGroup: null
- }
- var clickCount = 0;
- /**
- * 初始化并订阅事件
- * @return {[type]} [description]
- */
- function init() {
- if (!status.initialized) {
- subscribe();
- status.initialized = true;
- }
- afac()
- }
- function afac() {
- ONEMAP.C.publisher.publish({
- modName: 'toolMeasuringArea'
- }, 'tools:active');
- $("#measuringText").show().text('左键单击绘制测量点');
- if (map23DData.mouseIn == '3D') {
- $("#measuringText").hide();
- }
- if ($(".tools-area").hasClass("cur")) {
- switchTip();
- document.onclick = function () {
- clickCount++;
- if (clickCount > 1) {
- $("#measuringText").text('左键单击最后测量点结束测量');
- }
- switchTip();
- }
- document.ondblclick = function () {
- clickCount = 0;
- $("#measuringText").text('左键单击绘制测量点');
- switchTip();
- }
- } else {
- $("#measuringText").text('').hide();
- }
- }
- function switchTip() {
- document.onmousemove = function (ev) {
- var oEvent = ev || event;
- var oDiv = document.getElementById('measuringText');
- var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
- oDiv.style.left = oEvent.clientX + scrollLeft + 'px';
- oDiv.style.top = oEvent.clientY + scrollTop + 'px';
- }
- }
- /**
- * 注册订阅
- * @type {Function}
- * 推送:ONEMAP.C.publisher.publish(options,'moduleName::type');
- * 订阅:ONEMAP.C.publisher.subscribe(layoutResize,'sideBarLayoutChange');
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(remove, 'tools:active');
- ONEMAP.C.publisher.subscribe(clearMeasuring, 'cleanMap');
- ONEMAP.C.publisher.subscribe(clearMeasuring, 'controlMearsuring');
- ONEMAP.C.publisher.subscribe(change23DMeasureDistance, 'change23D');
- }
- function change23DMeasureDistance(type) {
- if ($('#toolsBar .tools-area').hasClass('cur')) {
- map2DViewer.setAreaTool({
- action: 'clear'
- })
- map3DViewer.measureArea({
- action: 'remove'
- })
- if (type == '2d') {
- $("#measuringText").show()
- map2DViewer.setAreaTool({
- action: 'add'
- });
- } else if (type == '3d') {
- $("#measuringText").hide()
- map3DViewer.measureArea({
- action: 'add'
- });
- }
- }
- }
- function clearMeasuring(options) {
- if (options) {
- if (options.action == 'clear') {
- map2DViewer.setAreaTool({
- action: 'clear'
- });
- map3DViewer.measureArea({
- action: 'clear'
- });
- status.firstAddMeasuring = true;
- remove({
- modName: 'clear'
- });
- $('#toolsBar .tools-area').removeClass('cur');
- }
- // else if (options.action == 'hide') {
- // map23DControl.group({
- // action: 'hide',
- // guid: modValue.mearsuringGroup
- // })
- // } else if (options.action == 'show') {
- // map23DControl.group({
- // action: 'show',
- // guid: modValue.mearsuringGroup
- // })
- // }
- } else {
- map2DViewer.setAreaTool({
- action: 'clear'
- });
- map3DViewer.measureArea({
- action: 'clear'
- });
- remove({
- modName: 'clear'
- });
- // status.firstAddMeasuring = true;
- // //remove({modName:'clear'});
- // $('#toolsBar .tools-area').removeClass('cur');
- // ONEMAP.M.mapHolder.mouseHand();
- }
- };
- function remove(options) {
- if (options.modName == 'cleanMap') {
- clearMeasuring({
- action: 'clear'
- })
- }
- if (options.modName == 'toolMeasuringArea') {
- if ($('#toolsBar .tools-area').hasClass('cur')) {
- if (map23DData.display.map2D) {
- map2DViewer.setAreaTool({
- action: 'remove',
- offset: [150, 50]
- });
- } else if (map23DData.display.map3D) {
- // var chrome = navigator.userAgent.toLowerCase().match(/chrome/) != null || navigator.userAgent.toLowerCase().match(/firefox/) != null;
- // if (!chrome) {
- // locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
- // locaSpaceMap.Refresh();
- // }
- map3DViewer.measureArea({
- action: 'remove'
- });
- }
- $('#toolsBar .tools-area').removeClass('cur');
- ONEMAP.M.mapHolder.mouseHand();
- } else {
- if (map23DData.display.map2D) {
- ONEMAP.M.mapHolder.removeMouseHand();
- if (status.firstAddMeasuring) {
- map2DViewer.setAreaTool({
- action: 'add',
- offset: [150, 50],
- background: "#fff",
- color: "red",
- font_size: "14px",
- closeButton: true
- });
- status.firstAddMeasuring = false;
- } else {
- map2DViewer.setAreaTool({
- action: 'restart',
- offset: [150, 50]
- });
- }
- } else if (map23DData.display.map3D) {
- // var chrome = navigator.userAgent.toLowerCase().match(/chrome/) != null || navigator.userAgent.toLowerCase().match(/firefox/) != null;
- // if (!chrome) {
- // try {
- // locaSpaceMap.Globe.RulerArea.SpaceMeasure = false; // 量算模式为绘制贴地面方式
- // locaSpaceMap.Globe.RulerArea.ValueMode = 1; // 量算的面上显示的值是地表面积
- // locaSpaceMap.Refresh();
- // locaSpaceMap.Globe.Action = 3;
- // } catch (e) {}
- // }
- map3DViewer.measureArea({
- action: 'add'
- });
- }
- $('#toolsBar .tools-area').addClass('cur');
- // ONEMAP.M.mapHolder.removeMouseHand();
- // ONEMAP.C.publisher.publish('add::area','mearsuring');
- }
- } else {
- if (options.modName != "toolMeasuringArea" && options.modName != "toolMeasuringDistance") {
- ONEMAP.M.mapHolder.mouseHand();
- }
- if ($('#toolsBar .tools-area').hasClass('cur')) {
- if (map23DData.display.map2D) {
- map2DViewer.setAreaTool({
- action: 'remove',
- offset: [150, 50]
- });
- } else if (map23DData.display.map3D) {
- //if (options.modName != 'toolMeasuringDistance') {
- // var chrome = navigator.userAgent.toLowerCase().match(/chrome/) != null || navigator.userAgent.toLowerCase().match(/firefox/) != null;
- // if (!chrome) {
- // try {
- // locaSpaceMap.Globe.Action = 0; //使鼠标动作返回普通浏览状态
- // locaSpaceMap.Refresh();
- // } catch (e) {}
- // }
- map3DViewer.measureArea({
- action: 'remove'
- });
- //}
- }
- $('#toolsBar .tools-area').removeClass('cur');
- //ONEMAP.M.mapHolder.mouseHand();
- }
- }
- }
- return ONEMAP.M.toolMeasuringArea = {
- init: init,
- modValue: modValue
- }
- })
|