Last active
January 29, 2019 22:05
-
-
Save kaaloo/de4fb95f8f2ee71e2c16fe940bd4417c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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