Skip to content

Commit 753e8f3

Browse files
committed
explicit to_json calls for map rendering, add popup option for overlays
1 parent 2ae72ed commit 753e8f3

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

app/helpers/gtt_map_helper.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@ def map_form_field(form, map, field: :geojson, edit_mode:)
1111

1212
def map_tag(map: nil, layers: map&.layers,
1313
geom: map.json, bounds: map.bounds,
14-
edit: nil)
14+
edit: nil, popup: nil)
1515

1616
data = {
17-
geom: geom,
18-
layers: layers
17+
geom: geom.is_a?(String) ? geom : geom.to_json
1918
}
20-
data[:bounds] = bounds if bounds
19+
20+
if layers
21+
data[:layers] = layers.is_a?(String) ? layers : layers.to_json
22+
end
23+
24+
if bounds
25+
data[:bounds] = bounds.is_a?(String) ? bounds : bounds.to_json
26+
end
27+
2128
data[:edit] = edit if edit
29+
data[:popup] = popup if popup
2230

23-
map_id = rand(36**8).to_s(36)
24-
content_tag(:div, "", data: data, id: "ol-#{map_id}", class: 'ol-map')
31+
content_tag(:div, "", data: data, id: "ol-#{rand(36**8).to_s(36)}", class: 'ol-map')
2532
end
2633

2734
end

0 commit comments

Comments
 (0)