use leaflet lib

This commit is contained in:
Swrup 2022-04-08 10:39:20 +02:00
parent ce7bb9d386
commit ccba00b2e7
5 changed files with 78 additions and 117 deletions

View file

@ -32,7 +32,7 @@ module Visibility = struct
set_visible return_button;
set_invisible thread_preview_div;
Option.iter set_invisible new_thread_button;
ignore @@ Jv.call Leaflet.map "closePopup" [||]
Leaflet.Map.close_popup ~popup:None map
let to_babillard_mode _event =
log "change_page_mode@\n";
@ -41,7 +41,7 @@ module Visibility = struct
set_invisible return_button;
set_visible thread_preview_div;
Option.iter set_visible new_thread_button;
ignore @@ Jv.call Leaflet.map "closePopup" [||]
Leaflet.Map.close_popup ~popup:None map
let () =
log "add events on return/new thread button@\n";
@ -71,15 +71,14 @@ module Marker = struct
log "on_each_feature@\n";
let feature_properties = Jv.get feature "properties" in
let thread_preview = Jv.get feature_properties "content" in
ignore
@@ Jv.call layer "on"
[| Jv.of_string "click"; Jv.repr (marker_on_click thread_preview) |]
Leaflet.Layer.on Leaflet.Event.Click (marker_on_click thread_preview) layer
let handle_geojson geojson =
log "handle_geojson@\n";
let dict = Jv.obj [| ("onEachFeature", Jv.repr on_each_feature) |] in
let layer = Jv.call Leaflet.leaflet "geoJSON" [| geojson; dict |] in
let _marker_layer = Jv.call layer "addTo" [| Leaflet.map |] in
let layer =
Leaflet.Layer.create_geojson geojson [ On_each_feature on_each_feature ]
in
let _marker_layer = Leaflet.Layer.add_to map layer in
()
let markers_handle_response response =
@ -104,22 +103,19 @@ let button = Jv.get Jv.global "submit-new-thread-button"
let on_click_set_latlng e =
log "on_click_set_latlng@\n";
if !Visibility.is_in_new_thread_mode then (
let lat_lng = Jv.get e "latlng" in
ignore @@ Jv.call Leaflet.popup "setLatLng" [| lat_lng |];
ignore
@@ Jv.call Leaflet.popup "setContent"
[| Jv.of_string "create thread here" |];
ignore @@ Jv.call Leaflet.popup "openOn" [| Leaflet.map |];
let latlng = Leaflet.Event.latlng e in
let popup =
Leaflet.Popup.create ~content:(Some "create thread here")
~latlng:(Some latlng) []
in
Leaflet.Map.open_popup popup map;
let lat = Jv.get lat_lng "lat" in
let lng = Jv.get lat_lng "lng" in
let lat = Leaflet.Latlng.lat latlng |> Jv.of_float in
let lng = Leaflet.Latlng.lng latlng |> Jv.of_float in
ignore @@ Jv.call lat_input "setAttribute" [| Jv.of_string "value"; lat |];
ignore @@ Jv.call lng_input "setAttribute" [| Jv.of_string "value"; lng |];
ignore @@ Jv.call button "removeAttribute" [| Jv.of_string "disabled" |] )
(*add on_click callback to map*)
let () =
ignore
@@ Jv.call Leaflet.map "on"
[| Jv.of_string "click"; Jv.repr on_click_set_latlng |]
let () = Leaflet.Map.on Leaflet.Event.Click on_click_set_latlng map