27
27
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28
28
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
30
+ import os
30
31
import copy
31
32
import datetime
32
33
import ipywidgets
@@ -223,10 +224,13 @@ def __init__(self):
223
224
self .savebutton .on_click (self .saveas_file )
224
225
self .savelabel .observe (self .set_savefile )
225
226
# create hbox of file selection
226
- self .filesaver = ipywidgets .HBox ([
227
- self .savebutton ,
228
- self .savelabel
229
- ])
227
+ if os .environ .get ("DISPLAY" ):
228
+ self .filesaver = ipywidgets .HBox ([
229
+ self .savebutton ,
230
+ self .savelabel
231
+ ])
232
+ else :
233
+ self .filesaver = copy .copy (self .savelabel )
230
234
231
235
# button and label for input file selection
232
236
self .loadbutton = ipywidgets .Button (
@@ -240,10 +244,13 @@ def __init__(self):
240
244
self .loadbutton .on_click (self .select_file )
241
245
self .loadlabel .observe (self .set_loadfile )
242
246
# create hbox of file selection
243
- self .fileloader = ipywidgets .HBox ([
244
- self .loadbutton ,
245
- self .loadlabel
246
- ])
247
+ if os .environ .get ("DISPLAY" ):
248
+ self .fileloader = ipywidgets .HBox ([
249
+ self .loadbutton ,
250
+ self .loadlabel
251
+ ])
252
+ else :
253
+ self .fileloader = copy .copy (self .loadlabel )
247
254
248
255
def saveas_file (self , b ):
249
256
"""function for file save
@@ -457,10 +464,13 @@ def __init__(self, projection, **kwargs):
457
464
# keep track of cursor position
458
465
self .map .on_interaction (self .handle_interaction )
459
466
# add control for drawing polygons or bounding boxes
460
- draw_control = ipyleaflet .DrawControl (polyline = {},circlemarker = {})
467
+ draw_control = ipyleaflet .DrawControl (polyline = {},circlemarker = {},
468
+ edit = False )
461
469
shapeOptions = {'color' :kwargs ['color' ],'fill_color' :kwargs ['color' ]}
462
- draw_control .rectangle = dict (shapeOptions = shapeOptions )
463
- draw_control .polygon = dict (shapeOptions = shapeOptions )
470
+ draw_control .rectangle = dict (shapeOptions = shapeOptions ,
471
+ metric = ['km' ,'m' ])
472
+ draw_control .polygon = dict (shapeOptions = shapeOptions ,
473
+ allowIntersection = False ,showArea = True ,metric = ['km' ,'m' ])
464
474
# create regions
465
475
self .regions = []
466
476
draw_control .on_draw (self .handle_draw )
@@ -469,12 +479,15 @@ def __init__(self, projection, **kwargs):
469
479
# handle cursor movements for label
470
480
def handle_interaction (self , ** kwargs ):
471
481
if (kwargs .get ('type' ) == 'mousemove' ):
482
+ lat ,lon = kwargs .get ('coordinates' )
483
+ lon = sliderule .io .wrap_longitudes (lon )
472
484
self .cursor .value = u"""Latitude: {d[0]:8.4f}\u00B0 ,
473
- Longitude: {d[1]:8.4f}\u00B0 """ .format (d = kwargs . get ( 'coordinates' ) )
485
+ Longitude: {d[1]:8.4f}\u00B0 """ .format (d = [ lat , lon ] )
474
486
475
487
# keep track of rectangles and polygons drawn on map
476
488
def handle_draw (self , obj , action , geo_json ):
477
489
lon ,lat = np .transpose (geo_json ['geometry' ]['coordinates' ])
490
+ lon = sliderule .io .wrap_longitudes (lon )
478
491
cx ,cy = sliderule .io .centroid (lon ,lat )
479
492
wind = sliderule .io .winding (lon ,lat )
480
493
# set winding to counter-clockwise
@@ -489,3 +502,4 @@ def handle_draw(self, obj, action, geo_json):
489
502
elif (action == 'deleted' ):
490
503
self .regions .remove (region )
491
504
return self
505
+
0 commit comments