Skip to content

Commit 1900748

Browse files
Draw and edit markers, polylines and polygons on a Leaflet map (#30)
* Added leaflet draw functionality * Added svg-inline-loader * Updated example * Updated package-lock * Added proptypes. Linting * Linting * Remove copied asset files. Remove svg loader. Replaced if else with switch statement * Updated package.lock * Linting * Added polygon edit functionality * Added missing key in map layer item list * linting * Update Dash prop on saved edit of polygon * Added proptype for polygonCoords * Renamed function * Use index instead of item name in React key * Replaced switch with if statement. changed a variable scope from var to let. * Replace switch statement with if statement * Remove debug log message * Remove debug log messages
1 parent a8e7179 commit 1900748

File tree

10 files changed

+3417
-3204
lines changed

10 files changed

+3417
-3204
lines changed

examples/example_layered_map.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
from matplotlib import cm
77

88
import dash
9+
from dash.dependencies import Input, Output
910
import dash_html_components as html
1011
import webviz_subsurface_components
1112

13+
1214
def array_to_png(Z, shift=True, colormap=False):
1315
'''The layered map dash component takes in pictures as base64 data
1416
(or as a link to an existing hosted image). I.e. for containers wanting
@@ -106,23 +108,15 @@ def array_to_png(Z, shift=True, colormap=False):
106108
'data':
107109
[
108110
{
109-
'type': 'image',
110-
'url': map_data,
111-
'colormap': colormap,
112-
'unit': 'm',
113-
'minvalue': min_value,
114-
'maxvalue': max_value,
115-
'bounds': [[432205, 6475078],
116-
[437720, 6481113]]
111+
'type': 'image',
112+
'url': map_data,
113+
'colormap': colormap,
114+
'unit': 'm',
115+
'minvalue': min_value,
116+
'maxvalue': max_value,
117+
'bounds': [[432205, 6475078],
118+
[437720, 6481113]]
117119
},
118-
{
119-
'type': 'polyline',
120-
'positions': [[433204, 6475077],
121-
[436204, 6480077],
122-
[437204, 6475077]],
123-
'color': 'green',
124-
'tooltip': 'This is a green fault line'
125-
}
126120
]
127121
},
128122
{
@@ -132,17 +126,17 @@ def array_to_png(Z, shift=True, colormap=False):
132126
'data':
133127
[
134128
{
135-
'type': 'image',
136-
'url': map_data,
137-
'bounds': [[432205, 6475078],
138-
[437720, 6481113]]
129+
'type': 'image',
130+
'url': map_data,
131+
'bounds': [[432205, 6475078],
132+
[437720, 6481113]]
139133
}
140134
]
141135
},
142136
{
143137
'name': 'Some overlay layer',
144138
'base_layer': False,
145-
'checked': True,
139+
'checked': False,
146140
'data':
147141
[
148142
{
@@ -166,11 +160,10 @@ def array_to_png(Z, shift=True, colormap=False):
166160

167161
with open('../src/demo/example-data/layered-map.json', 'w') as fh:
168162
json.dump({
169-
'map_bounds': map_bounds,
170-
'center': center,
171-
'layers': layers
172-
}, fh)
173-
163+
'map_bounds': map_bounds,
164+
'center': center,
165+
'layers': layers
166+
}, fh)
174167

175168
app = dash.Dash(__name__)
176169

@@ -180,7 +173,25 @@ def array_to_png(Z, shift=True, colormap=False):
180173
map_bounds=map_bounds,
181174
center=center,
182175
layers=layers
183-
)
176+
),
177+
html.Pre(id='polyline'),
178+
html.Pre(id='marker'),
179+
html.Pre(id='polygon'),
184180
])
185181

182+
@app.callback(Output('polyline', 'children'),
183+
[Input('volve-map', 'line_points')])
184+
def get_edited_line(coords):
185+
return f'Edited polyline: {json.dumps(coords)}'
186+
187+
@app.callback(Output('marker', 'children'),
188+
[Input('volve-map', 'marker_point')])
189+
def get_edited_line(coords):
190+
return f'Edited marker: {json.dumps(coords)}'
191+
192+
@app.callback(Output('polygon', 'children'),
193+
[Input('volve-map', 'polygon_points')])
194+
def get_edited_line(coords):
195+
return f'Edited closed polygon: {json.dumps(coords)}'
196+
186197
app.run_server(debug=True)

0 commit comments

Comments
 (0)