@@ -15,10 +15,58 @@ define([
15
15
'backbone' ,
16
16
'wellknown' ,
17
17
'usngs' ,
18
- 'js/store'
19
- ] , function ( _ , Backbone , wellknown , usngs , store ) {
18
+ 'js/store' ,
19
+ 'js/Common'
20
+ ] , function ( _ , Backbone , wellknown , usngs , store , Common ) {
20
21
21
22
var converter = new usngs . Converter ( ) ;
23
+ var minimumDifference = 0.0001 ;
24
+ var minimumBuffer = 0.000001 ;
25
+
26
+ function convertToValid ( key , model ) {
27
+ if ( key . mapSouth !== undefined && ( key . mapSouth >= key . mapNorth || key . mapSouth >= model . get ( 'mapNorth' ) ) ) {
28
+ key . mapSouth = parseFloat ( ( key . mapNorth || model . get ( 'mapNorth' ) ) ) - minimumDifference ;
29
+ }
30
+ if ( key . mapEast !== undefined && ( key . mapEast <= key . mapWest || key . mapEast <= model . get ( 'mapWest' ) ) ) {
31
+ key . mapEast = parseFloat ( ( key . mapWest || model . get ( 'mapWest' ) ) ) + minimumDifference ;
32
+ }
33
+ if ( key . mapWest !== undefined && ( key . mapWest >= key . mapEast || key . mapWest >= model . get ( 'mapEast' ) ) ) {
34
+ key . mapWest = parseFloat ( ( key . mapEast || model . get ( 'mapEast' ) ) ) - minimumDifference ;
35
+ }
36
+ if ( key . mapNorth !== undefined && ( key . mapNorth <= key . mapSouth || key . mapNorth <= model . get ( 'mapSouth' ) ) ) {
37
+ key . mapNorth = parseFloat ( ( key . mapSouth || model . get ( 'mapSouth' ) ) ) + minimumDifference ;
38
+ }
39
+ if ( key . mapNorth !== undefined ) {
40
+ key . mapNorth = Math . max ( - 90 + minimumDifference , key . mapNorth ) ;
41
+ key . mapNorth = Math . min ( 90 , key . mapNorth ) ;
42
+ }
43
+ if ( key . mapSouth !== undefined ) {
44
+ key . mapSouth = Math . max ( - 90 , key . mapSouth ) ;
45
+ key . mapSouth = Math . min ( 90 - minimumDifference , key . mapSouth ) ;
46
+ }
47
+ if ( key . mapWest !== undefined ) {
48
+ key . mapWest = Math . max ( - 180 , key . mapWest ) ;
49
+ key . mapWest = Math . min ( 180 - minimumDifference , key . mapWest ) ;
50
+ }
51
+ if ( key . mapEast !== undefined ) {
52
+ key . mapEast = Math . max ( - 180 + minimumDifference , key . mapEast ) ;
53
+ key . mapEast = Math . min ( 180 , key . mapEast ) ;
54
+ }
55
+ if ( key . lat !== undefined ) {
56
+ key . lat = Math . max ( - 90 , key . lat ) ;
57
+ key . lat = Math . min ( 90 , key . lat ) ;
58
+ }
59
+ if ( key . lon !== undefined ) {
60
+ key . lon = Math . max ( - 180 , key . lon ) ;
61
+ key . lon = Math . min ( 180 , key . lon ) ;
62
+ }
63
+ if ( key . radius !== undefined ) {
64
+ key . radius = Math . max ( minimumBuffer , key . radius ) ;
65
+ }
66
+ if ( key . lineWidth !== undefined ) {
67
+ key . lineWidth = Math . max ( minimumBuffer , key . lineWidth ) ;
68
+ }
69
+ }
22
70
23
71
return Backbone . AssociatedModel . extend ( {
24
72
defaults : {
@@ -32,7 +80,7 @@ define([
32
80
mapWest : undefined ,
33
81
mapSouth : undefined ,
34
82
radiusUnits : 'meters' ,
35
- radius : 0 ,
83
+ radius : 1 ,
36
84
locationType : 'latlon' ,
37
85
lat : undefined ,
38
86
lon : undefined ,
@@ -44,6 +92,19 @@ define([
44
92
lineWidth : 1 ,
45
93
lineUnits : 'meters'
46
94
} ,
95
+ set : function ( key , value , options ) {
96
+ if ( ! _ . isObject ( key ) ) {
97
+ var keyObject = { } ;
98
+ keyObject [ key ] = value ;
99
+ key = keyObject ;
100
+ value = options ;
101
+ }
102
+ convertToValid ( key , this ) ;
103
+ Backbone . AssociatedModel . prototype . set . call ( this , key , value , options ) ;
104
+ Common . queueExecution ( function ( ) {
105
+ this . trigger ( 'change' , Object . keys ( key ) ) ;
106
+ } . bind ( this ) ) ;
107
+ } ,
47
108
initialize : function ( ) {
48
109
this . listenTo ( this , 'change:north change:south change:east change:west' , this . setBBox ) ;
49
110
this . listenTo ( this , 'change:locationType' , this . handleLocationType ) ;
@@ -110,11 +171,15 @@ define([
110
171
west = this . get ( 'west' ) ,
111
172
east = this . get ( 'east' ) ;
112
173
if ( north && south && east && west ) {
113
- var usngsStr = converter . LLBboxtoUSNG ( north , south , east , west ) ;
174
+ try {
175
+ var usngsStr = converter . LLBboxtoUSNG ( north , south , east , west ) ;
176
+
177
+ this . set ( 'usngbb' , usngsStr , { silent : this . get ( 'locationType' ) !== 'usng' } ) ;
178
+ if ( this . get ( 'locationType' ) === 'usng' && this . drawing ) {
179
+ this . repositionLatLon ( ) ;
180
+ }
181
+ } catch ( err ) {
114
182
115
- this . set ( 'usngbb' , usngsStr , { silent : this . get ( 'locationType' ) !== 'usng' } ) ;
116
- if ( this . get ( 'locationType' ) === 'usng' && this . drawing ) {
117
- this . repositionLatLon ( ) ;
118
183
}
119
184
}
120
185
} ,
@@ -123,8 +188,12 @@ define([
123
188
var lat = this . get ( 'lat' ) ,
124
189
lon = this . get ( 'lon' ) ;
125
190
if ( lat && lon ) {
126
- var usngsStr = converter . LLtoUSNG ( lat , lon , 5 ) ;
127
- this . set ( 'usng' , usngsStr , { silent : true } ) ;
191
+ try {
192
+ var usngsStr = converter . LLtoUSNG ( lat , lon , 5 ) ;
193
+ this . set ( 'usng' , usngsStr , { silent : true } ) ;
194
+ } catch ( err ) {
195
+
196
+ }
128
197
}
129
198
} ,
130
199
0 commit comments