Карта не была показана, Fabulous для Xamarin.Forms (с использованием карт, полный Elmish) - PullRequest
1 голос
/ 31 октября 2019

Я изменяю пример Fabulous для Xamarin.Forms (используя Карты, полный Elmish): "https://fsprojects.github.io/Fabulous/Fabulous.XamarinForms/views-maps.html". Однако результат не такой, как я ожидал. Карта не была показана, пожалуйста, посоветуйте, какустранить проблему. Спасибо.

// Copyright 2018-2019 Fabulous contributors. See LICENSE.md for license.
namespace SqueakyApp

open System.Diagnostics
open Fabulous
open Fabulous.XamarinForms
open Fabulous.XamarinForms.LiveUpdate
open Fabulous.XamarinForms.MapsExtension
open Xamarin.Forms
open Xamarin.Forms.Maps

module App =
    // Declaration
    type Model =
        { Count : int
          Step : int
          Pressed : bool }

    type Msg =
        | Increment
        | Decrement
        | UserLocation

    // Functions

    // Lifecycle
    let initModel =
        { Count = 0
          Step = 0
          Pressed = false }

    let init() = initModel, Cmd.none

    let update msg model =
        match msg with
        | Increment -> { model with Count = model.Count + model.Step }, Cmd.none
        | Decrement -> { model with Count = model.Count - model.Step }, Cmd.none
        | Reset -> init()

    let view (model : Model) dispatch =

        let paris = Position(48.8566, 2.3522)
        let london = Position(51.5074, -0.1278)
        let calais = Position(50.9513, 1.8587)
        let timbuktu = Position(16.7666, -3.0026)

        let map =
            View.Map
                (hasZoomEnabled = true, hasScrollEnabled = true,
                 pins = [ View.Pin(paris, label = "Paris", pinType = PinType.Place)
                          View.Pin(london, label = "London", pinType = PinType.Place) ],
                 requestedRegion = MapSpan.FromCenterAndRadius(calais, Distance.FromKilometers(300.0)))
        // View
        View.ContentPage(content = map)

    // Note, this declaration is needed if you enable LiveUpdate
    let program = Program.mkProgram init update view

type App() as app =
    inherit Application()

    let runner =
        App.program
        |> Program.withConsoleTrace
        |> XamarinFormsProgram.run app

Снимок экрана

enter image description here

1 Ответ

1 голос
/ 04 ноября 2019

Изучение примера от Timothé Larivière (https://github.com/TimLariviere/FabulousContacts).

) Необходимо инициализировать FormsMaps в файле "AppDelegate.fs" в подкаталоге .iOS. Для справки есть исходный файл.

// Copyright 2018 Fabulous contributors. See LICENSE.md for license.
namespace SqueakyApp.iOS

open System
open UIKit
open Foundation
open Xamarin
open Xamarin.Forms
open Xamarin.Forms.Platform.iOS

[<Register ("AppDelegate")>]
type AppDelegate () =
    inherit FormsApplicationDelegate ()

    override this.FinishedLaunching (app, options) =
        Forms.Init()
        FormsMaps.Init() //*** initialization the FormsMaps is required 
        let appcore = new SqueakyApp.App()
        this.LoadApplication (appcore)
        base.FinishedLaunching(app, options)

module Main =
    [<EntryPoint>]
    let main args =
        UIApplication.Main(args, null, "AppDelegate")
        0

enter image description here

...