Skip to content

Instantly share code, notes, and snippets.

@kaaloo
Last active January 29, 2019 22:05
Show Gist options
  • Save kaaloo/de4fb95f8f2ee71e2c16fe940bd4417c to your computer and use it in GitHub Desktop.
Save kaaloo/de4fb95f8f2ee71e2c16fe940bd4417c to your computer and use it in GitHub Desktop.
module Mdar.Addresses
open Fable.Core.JsInterop
open Fable.Import
open Fable.Import.Fuse
open Node.Exports
open Node.Globals
open Thoth.Json
open Fable.Core
type GeoAddress =
| Address of string
| Coordinates of float []
static member Decoder =
Decode.object (fun get ->
keyValueList CaseRules.LowerFirst [
Address <| get.Required.At ["properties" ; "adresse"] Decode.string
Coordinates <| get.Required.At ["geometry" ; "coordinates"] (Decode.array Decode.float)
]
)
let private streetAddressesFuse =
path.join [| __dirname ; "../../assets/localisateur-adresses.json" |]
|> (fun file -> fs.readFileSync (file, "utf8"))
|> Decode.fromValue "features" (Decode.array GeoAddress.Decoder)
|> (fun result ->
match result with
| Ok addresses ->
Some (Fuse.fuse.Fuse.Create (addresses , jsOptions(fun (o: Fuse.FuseOptions) ->
o.shouldSort <- Some true
o.keys <- Some [| "address" |]
)))
| Error e ->
printfn "Cannot load address geolocation data: %s" e
None
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment