You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							170 lines
						
					
					
						
							5.8 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							170 lines
						
					
					
						
							5.8 KiB
						
					
					
				| var LatLngSwitch = function (parent) { | |
|     this.Parent = parent; | |
| 
 | |
|     this.Startup = function () { | |
|         $('#first-copy-btn').on('click', this.OnFirstCopyClick.bind(this)); | |
|         $('#second-copy-btn').on('click', this.OnSecondCopyClick.bind(this)); | |
|         $('#first-switch-btn').on('click', this.onFirstSwitchClick.bind(this)); | |
|         $('#second-switch-btn').on('click', this.onSecondSwitchClick.bind(this)); | |
|         $('#close-lat-lng-switch-dialog').on('click', this.HideDialog.bind(this)); | |
|         $('#dialog-lat-lng-switch-cancel').on('click', this.HideDialog.bind(this)); | |
| 
 | |
|         $('#first-degree').on('change', this.onFirstDegreeChange.bind(this)); | |
|         $('#first-minute').on('change', this.onFirstMinuteChange.bind(this)); | |
|         $('#first-second').on('change', this.onFirstSecondChange.bind(this)); | |
|         $('#second-decimal').on('change', this.onSencondDecimalChange.bind(this)); | |
|     }; | |
| 
 | |
|     this.onFirstDegreeChange = function (event) { | |
|         this.checkInput($(event.target), 180); | |
|     }; | |
| 
 | |
|     this.onFirstMinuteChange = function (event) { | |
|         this.checkInput($(event.target), 60); | |
|     }; | |
| 
 | |
|     this.onFirstSecondChange = function (event) { | |
|         this.checkInput($(event.target), 60); | |
|     }; | |
| 
 | |
|     this.onSencondDecimalChange = function (event) { | |
|         this.checkInput($(event.target), 180); | |
|     } | |
| 
 | |
|     this.checkInput = function (element, max) { | |
|         if (element.val().trim() === '') { | |
|             id.addClass('error'); | |
|             element.next().show(); | |
|             return; | |
|         } else if (Number(element.val()) > max || Number(element.val()) < 0) { | |
|             console.log(Number(element.val())) | |
|             $(element).addClass('error'); | |
|             element.next().show(); | |
|             return; | |
|         } else { | |
|             $(element).removeClass('error'); | |
|             element.next().hide(); | |
|         } | |
|     }; | |
| 
 | |
|     this.ShowDialog = function () { | |
|         $('#dialog-lat-lng-switch').show(); | |
|         $('#first-degree').val(''); | |
|         $('#first-minute').val(''); | |
|         $('#first-second').val(''); | |
|         $('#first-decimal').val(''); | |
|         $('#second-degree').val(''); | |
|         $('#second-minute').val(''); | |
|         $('#second-second').val(''); | |
|         $('#second-decimal').val(''); | |
|         $('#hide-text').text(''); | |
|     }; | |
|      | |
|     this.getLatLng = function (value) { | |
|         value = value.toString() | |
|         let index = value.indexOf('.') | |
|         if (index !== -1) { | |
|             value = value.substring(0, 6 + index + 1) | |
|         } else { | |
|             value = value.substring(0) | |
|         } | |
|         return parseFloat(value).toFixed(6) | |
|     } | |
| 
 | |
|     this.onFirstSwitchClick = function (event) { | |
|         var degree = $('#first-degree').val(); | |
|         var minute = $('#first-minute').val(); | |
|         var second = $('#first-second').val(); | |
|         $('#first-degree').removeClass('error'); | |
|         $('#first-minute').removeClass('error'); | |
|         $('#first-second').removeClass('error'); | |
| 
 | |
|         if (degree.trim() === '' || Number(degree) > 180 || Number(degree) < 0) { | |
|             this.showError($('#first-degree')); | |
|         } else if (minute.trim() === '' || Number(minute) > 60 || Number(minute) < 0) { | |
|             this.showError($('#first-minute')); | |
|         } else if (second.trim() === '' || Number(second) > 60 || Number(second) < 0) { | |
|             this.showError($('#first-second')); | |
|         }  else { | |
|             this.hideError($('#first-degree')); | |
|             this.hideError($('#first-minute')); | |
|             this.hideError($('#first-second')); | |
|             var value = this.changeToDegree(degree, minute, second); | |
|             $('#first-decimal').val(value); | |
|         } | |
|     }; | |
| 
 | |
|     this.onSecondSwitchClick = function () { | |
|         var decimal = $('#second-decimal').val(); | |
|         $('#second-decimal').removeClass('error'); | |
| 
 | |
|         if (decimal.trim() === '' || Number(decimal) > 180 || Number(decimal) < 0) { | |
|             this.showError($('#second-decimal')); | |
|         } else if (decimal.indexOf(".") < 0 || decimal.length < 5) { | |
|             this.showError($('#second-decimal')); | |
|         } else { | |
|             this.hideError($('#second-decimal')); | |
|             var value = this.changeToDecimal(decimal); | |
|             var degree = $('#second-degree').val(value.degree); | |
|             var minute = $('#second-minute').val(value.minute); | |
|             var second = $('#second-second').val(value.second); | |
|             $('#hide-text').val(degree.val() + "°" + minute.val() + "'" + second.val() + "\""); | |
|         } | |
|     }; | |
| 
 | |
|     this.showError = function (id) { | |
|         id.next().show(); | |
|         id.addClass('error'); | |
|         alert('请输入正确的值。'); | |
|         return | |
|     }; | |
| 
 | |
|     this.hideError = function (id) { | |
|         id.next().hide(); | |
|         id.removeClass('error'); | |
|     }; | |
| 
 | |
|     this.changeToDecimal = function (value) { | |
|         var text = value.split("."); | |
|         var degree = text[0]; | |
| 
 | |
|         var temp = "0." + text[1]; | |
|         var temp = String(temp * 60); | |
|         var str = temp.split("."); | |
|         var minute = str[0]; | |
| 
 | |
|         temp = "0." + str[1]; | |
|         temp = temp * 60; | |
|         var second = temp; | |
|         return { | |
|             degree: degree, | |
|             minute: minute, | |
|             second: second | |
|         } | |
|     } | |
| 
 | |
|     this.changeToDegree = function (degree, minute, second) { | |
|         var str = parseFloat(minute) + parseFloat(second / 60); | |
|         var value = parseFloat(str / 60) + parseFloat(degree); | |
|         return value; | |
|     } | |
| 
 | |
|     this.HideDialog = function () { | |
|         $('#dialog-lat-lng-switch').hide(); | |
|         $('#map').css('cursor', '-webkit-grab'); | |
| 
 | |
|         this.Parent.isSwitch = false; | |
|     }; | |
| 
 | |
|     this.OnFirstCopyClick = function () { | |
|         var selected = document.querySelector('#first-decimal'); | |
|         selected.select(); | |
|         document.execCommand('Copy'); | |
|     }; | |
| 
 | |
|     this.OnSecondCopyClick = function () { | |
|         var selected = document.querySelector('#hide-text'); | |
|         selected.select(); | |
|         document.execCommand('Copy'); | |
|     }; | |
| } |