bind popup with plant content
This commit is contained in:
parent
3defcfde96
commit
dfb193476f
1 changed files with 29 additions and 32 deletions
41
src/map.ml
41
src/map.ml
|
|
@ -1,4 +1,5 @@
|
||||||
(* TODO only run this on /add_plant and /map *)
|
(* TODO only run this on /add_plant and /map *)
|
||||||
|
(*TODO use Jv.find everywhere (do we care?)*)
|
||||||
let log = Format.printf
|
let log = Format.printf
|
||||||
|
|
||||||
(* get the leaflet object *)
|
(* get the leaflet object *)
|
||||||
|
|
@ -50,7 +51,6 @@ let () =
|
||||||
let on_click e =
|
let on_click e =
|
||||||
log "on_click@.";
|
log "on_click@.";
|
||||||
|
|
||||||
(*TODO use Jv.find *)
|
|
||||||
let lat_lng = Jv.get e "latlng" in
|
let lat_lng = Jv.get e "latlng" in
|
||||||
ignore @@ Jv.call popup "setLatLng" [| lat_lng |];
|
ignore @@ Jv.call popup "setLatLng" [| lat_lng |];
|
||||||
ignore @@ Jv.call popup "setContent" [| Jv.of_string "euujjj" |];
|
ignore @@ Jv.call popup "setContent" [| Jv.of_string "euujjj" |];
|
||||||
|
|
@ -64,40 +64,37 @@ let on_click e =
|
||||||
ignore @@ Jv.call lat_input "setAttribute" [| Jv.of_string "value"; lat |];
|
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 lng_input "setAttribute" [| Jv.of_string "value"; lng |]
|
||||||
|
|
||||||
(* let add_marker lat lng content =
|
module Marker = struct
|
||||||
log "add_marker@.";
|
let on_each_feature feature layer =
|
||||||
|
log "on_each_feature@.";
|
||||||
let marker =
|
let feature_properties = Jv.get feature "properties" in
|
||||||
Jv.call leaflet "marker" [| Jv.of_array Jv.of_float [| lat; lng |] |]
|
let feature_properties_content = Jv.get feature_properties "content" in
|
||||||
in
|
ignore @@ Jv.call layer "bindPopup" [| feature_properties_content |];
|
||||||
ignore @@ Jv.call marker "bindPopup" [| Jv.of_string content |];
|
|
||||||
ignore @@ Jv.call marker "addTo" [| map |]
|
|
||||||
*)
|
|
||||||
|
|
||||||
let handle_geojson geojson =
|
|
||||||
log "handle_geojson@.";
|
|
||||||
log "feed geojson to leaflet@.";
|
|
||||||
let layer = Jv.call leaflet "geoJSON" [| geojson |] in
|
|
||||||
ignore @@ Jv.call layer "addTo" [| map |];
|
|
||||||
(* TODO this doesnt work :^) *)
|
|
||||||
()
|
()
|
||||||
|
|
||||||
let handle_response response =
|
let handle_geojson geojson =
|
||||||
|
log "handle_geojson@.";
|
||||||
|
log "feed geojson to leaflet@.";
|
||||||
|
(* TODO add onEachFeature *)
|
||||||
|
let dict = Jv.obj [| ("onEachFeature", Jv.repr on_each_feature) |] in
|
||||||
|
let layer = Jv.call leaflet "geoJSON" [| geojson; dict |] in
|
||||||
|
ignore @@ Jv.call layer "addTo" [| map |];
|
||||||
|
()
|
||||||
|
|
||||||
|
let handle_response response =
|
||||||
log "handle_response@.";
|
log "handle_response@.";
|
||||||
let geo_json_list_futur = Jv.call response "json" [||] in
|
let geo_json_list_futur = Jv.call response "json" [||] in
|
||||||
ignore @@ Jv.call geo_json_list_futur "then" [| Jv.repr handle_geojson |];
|
ignore @@ Jv.call geo_json_list_futur "then" [| Jv.repr handle_geojson |];
|
||||||
()
|
()
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
(* TODO only on /map *)
|
(* TODO only on /map *)
|
||||||
(* TODO add marker for plants on the map *)
|
|
||||||
(* TODO GET /markers -> geojson *)
|
|
||||||
(* TODO make popup *)
|
|
||||||
log "fetch geojson@.";
|
log "fetch geojson@.";
|
||||||
let window = Jv.get Jv.global "window" in
|
let window = Jv.get Jv.global "window" in
|
||||||
let fetchfutur = Jv.call window "fetch" [| Jv.of_string "/markers" |] in
|
let fetchfutur = Jv.call window "fetch" [| Jv.of_string "/markers" |] in
|
||||||
ignore @@ Jv.call fetchfutur "then" [| Jv.repr handle_response |];
|
ignore @@ Jv.call fetchfutur "then" [| Jv.repr handle_response |];
|
||||||
()
|
()
|
||||||
|
end
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
(*add on_click callback to map*)
|
(*add on_click callback to map*)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue