Skip to content

Commit

Permalink
Map support
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Oct 17, 2022
1 parent eb6fc4f commit c6ef22f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Fabulous.XamarinForms.Maps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Global
{77D266C1-CEB9-4342-BCCF-C767B4D9C3B6}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{1C73C577-0B28-46E8-90F6-60868E259B01}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator
{1C73C577-0B28-46E8-90F6-60868E259B01}.Release|Any CPU.Build.0 = Release|iPhoneSimulator
{1C73C577-0B28-46E8-90F6-60868E259B01}.Debug|Any CPU.ActiveCfg = Debug|iPhone
{1C73C577-0B28-46E8-90F6-60868E259B01}.Debug|Any CPU.Build.0 = Debug|iPhone
{1C73C577-0B28-46E8-90F6-60868E259B01}.Debug|Any CPU.Deploy.0 = Debug|iPhone
{1C73C577-0B28-46E8-90F6-60868E259B01}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
{1C73C577-0B28-46E8-90F6-60868E259B01}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
{1C73C577-0B28-46E8-90F6-60868E259B01}.Debug|Any CPU.Deploy.0 = Debug|iPhoneSimulator
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{42433804-9F8B-4F47-9A69-8073E0E7259C} = {C85DF18C-B918-40DA-907C-29F57C72A6D9}
Expand Down
1 change: 1 addition & 0 deletions src/Fabulous.XamarinForms.Maps.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<None Include="PackageREADME.md" Pack="true" PackagePath="\" />
<None Include="../logo/nuget-icon.png" Pack="true" PackagePath="\" />
<Compile Include="Pin.fs" />
<Compile Include="Map.fs" />
</ItemGroup>

Expand Down
32 changes: 32 additions & 0 deletions src/Map.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@ type IMap =

module Map =
let WidgetKey = Widgets.register<Map> ()

let HasScrollEnabled = Attributes.defineBindableBool Map.HasScrollEnabledProperty
let HasZoomEnabled = Attributes.defineBindableBool Map.HasZoomEnabledProperty
let IsShowingUse = Attributes.defineBindableBool Map.IsShowingUserProperty

let TrafficEnabledProperty = Attributes.defineBindableBool Map.TrafficEnabledProperty

let MoveToLastRegionOnLayoutChange = Attributes.defineBindableBool Map.MoveToLastRegionOnLayoutChangeProperty

let MapType =
Attributes.defineEnum<MapType>
"Map_MapType"
(fun _ newValueOpt node ->
let map = node.Target :?> Map

let value =
match newValueOpt with
| ValueNone -> MapType.Street
| ValueSome v -> v

map.MapType <- value)

let ItemsSource<'T> =
Attributes.defineBindable<WidgetItems<'T>, System.Collections.Generic.IEnumerable<Widget>>
Map.ItemsSourceProperty
(fun modelValue ->
seq {
for x in modelValue.OriginalItems do
modelValue.Template x
})
(fun a b -> ScalarAttributeComparers.equalityCompare a.OriginalItems b.OriginalItems)


[<AutoOpen>]
module MapBuilders =
Expand Down
28 changes: 28 additions & 0 deletions src/Pin.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Fabulous.XamarinForms.Maps

open System.Runtime.CompilerServices
open Fabulous
open Fabulous.StackAllocatedCollections.StackList
open Fabulous.XamarinForms
open Xamarin.Forms.Maps

type IPin =
inherit Fabulous.XamarinForms.IElement

module Pin =
let WidgetKey = Widgets.register<Pin> ()

[<AutoOpen>]
module PinBuilders =
type Fabulous.XamarinForms.View with

/// Defines a Pin widget
static member inline Pin<'msg>() =
WidgetBuilder<'msg, IPin>(Pin.WidgetKey, AttributesBundle(StackList.empty (), ValueNone, ValueNone))

[<Extension>]
type PinModifiers =
/// <summary>Link a ViewRef to access the direct Pin control instance</summary>
[<Extension>]
static member inline reference(this: WidgetBuilder<'msg, IPin>, value: ViewRef<Pin>) =
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))

0 comments on commit c6ef22f

Please sign in to comment.