123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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: 'toolMeasuringDistance'
- }, 'tools:active');
- $("#measuringText").show().text('左键单击绘制测量点');
- if(map23DData.mouseIn == '3D'){
- $("#measuringText").hide();
- }
- if ($(".tools-distance").hasClass("cur")) {
- switchTip();
- document.onclick = function () {
- clickCount++;
- if (clickCount > 0) {
- $("#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-distance').hasClass('cur')) {
- map2DViewer.setDistanceTool({
- action: 'clear'
- })
- map3DViewer.measureDistance({
- action: 'remove'
- })
- if (type == '2d') {
- $("#measuringText").show()
- map2DViewer.setDistanceTool({
- action: 'add'
- });
- } else if (type == '3d') {
- $("#measuringText").hide()
- map3DViewer.measureDistance({
- action: 'add'
- });
- }
- }
- }
- function clearMeasuring(options) {
- if (options) {
- if (options.action == 'clear') {
- map2DViewer.setDistanceTool({
- action: 'clear'
- });
- map3DViewer.measureDistance({
- action: 'clear'
- });
- status.firstAddMeasuring = true;
- remove({
- modName: 'clear'
- });
- }
- } else {
- map2DViewer.setDistanceTool({
- action: 'clear'
- });
- map3DViewer.measureDistance({
- action: 'clear'
- });
- status.firstAddMeasuring = true;
- remove({
- modName: 'clear'
- });
- }
- };
- function remove(options) {
- if (options.modName == 'cleanMap') {
- clearMeasuring({
- action: 'clear'
- })
- }
- if (options.modName == 'toolMeasuringDistance') {
- if ($('#toolsBar .tools-distance').hasClass('cur')) {
- if (map23DData.display.map2D) {
- map2DViewer.setDistanceTool({
- action: 'remove',
- offset: [150, 50]
- });
- } else if (map23DData.display.map3D) {
- map3DViewer.measureDistance({
- action: 'remove'
- });
- }
- ONEMAP.M.mapHolder.mouseHand();
- $('#toolsBar .tools-distance').removeClass('cur');
- } else {
- if (map23DData.display.map2D) {
- ONEMAP.M.mapHolder.removeMouseHand();
- if (status.firstAddMeasuring) {
- map2DViewer.setDistanceTool({
- action: 'add',
- offset: [150, 50],
- background: "#fff",
- color: "red",
- font_size: "14px",
- closeButton: true
- });
- status.firstAddMeasuring = false;
- } else {
- map2DViewer.setDistanceTool({
- action: 'restart',
- offset: [150, 50],
- background: "#fff",
- color: "red",
- font_size: "14px",
- closeButton: true
- });
- }
- } else if (map23DData.display.map3D) {
- map3DViewer.measureDistance({
- action: 'add'
- });
- }
- $('#toolsBar .tools-distance').addClass('cur');
- // ONEMAP.C.publisher.publish('add::diatance','mearsuring');
- }
- } else {
- if (options.modName != "toolMeasuringArea" && options.modName != "toolMeasuringDistance") {
- ONEMAP.M.mapHolder.mouseHand();
- }
- if ($('#toolsBar .tools-distance').hasClass('cur')) {
- if (map23DData.display.map2D) {
- map2DViewer.setDistanceTool({
- action: 'remove',
- offset: [150, 50]
- });
- } else if (map23DData.display.map3D) {
- //if (options.modName != 'toolMeasuringArea') {
- map3DViewer.measureDistance({
- action: 'remove'
- });
- //}
- }
- $('#toolsBar .tools-distance').removeClass('cur');
- //ONEMAP.M.mapHolder.mouseHand();
- }
- }
- }
- return ONEMAP.M.toolMeasuringDistance = {
- init: init,
- modValue: modValue
- }
- })
|