Skip to content

Commit b1c6976

Browse files
committed
- try framing the annotationview
1 parent 2df9129 commit b1c6976

File tree

3 files changed

+88
-18
lines changed

3 files changed

+88
-18
lines changed

src/libs/Mapbox.Maui/Platforms/Android/ViewAnnotations/MapboxViewHandler.ViewAnnotations.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ public void AddViewAnnotation(ViewAnnotationOptions options, DataTemplate dataTe
1919
}
2020

2121
var xview = (View)dataTemplate.CreateContent();
22-
xview.BindingContext = VirtualView is View xxview
23-
? xxview.BindingContext
24-
: options;
25-
26-
var platformHandler = TemplateHelpers.GetHandler(xview, VirtualView.Handler.MauiContext);
27-
28-
mapView.ViewAnnotationManager.AddViewAnnotation(platformHandler.PlatformView, options.ToPlatform());
22+
xview.Parent = VirtualView as Element;
23+
xview.BindingContext = options;
24+
xview.HeightRequest = options.Height ?? xview.HeightRequest;
25+
xview.WidthRequest = options.Width ?? xview.WidthRequest;
26+
27+
var platformHandler = TemplateHelpers.GetHandler(
28+
xview,
29+
VirtualView.Handler.MauiContext);
30+
platformHandler.PlatformView.LayoutParameters = new Android.Views.ViewGroup.LayoutParams(
31+
(int) options.Width.Value.PointToPixel(),
32+
(int)options.Height.Value.PointToPixel()
33+
);
34+
35+
mapView.ViewAnnotationManager.AddViewAnnotation(
36+
platformHandler.PlatformView,
37+
options.ToPlatform());
2938
}
3039

3140
public void RemoveAllViewAnnotations()

src/libs/Mapbox.Maui/Platforms/iOS/ViewAnnotations/MapboxViewHandler.ViewAnnotations.cs

+14-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,20 @@ public void AddViewAnnotation(ViewAnnotationOptions options, DataTemplate dataTe
2020
}
2121

2222
var xview = (View)dataTemplate.CreateContent();
23-
xview.BindingContext = VirtualView is View xxview
24-
? xxview.BindingContext
25-
: options;
26-
27-
var platformHandler = TemplateHelpers.GetHandler(xview, VirtualView.Handler.MauiContext);
28-
29-
mapView.ViewAnnotations().AddWithAnnotation(options.ToPlatform(platformHandler.PlatformView));
23+
xview.Parent = VirtualView as Element;
24+
xview.BindingContext = options;
25+
xview.HeightRequest = options.Height ?? xview.HeightRequest;
26+
xview.WidthRequest = options.Width ?? xview.WidthRequest;
27+
28+
var platformHandler = TemplateHelpers.GetHandler(
29+
xview,
30+
VirtualView.Handler.MauiContext);
31+
32+
mapView
33+
.ViewAnnotations()
34+
.AddWithAnnotation(
35+
options.ToPlatform(platformHandler.PlatformView)
36+
);
3037
}
3138

3239
public void RemoveAllViewAnnotations()

src/qs/MapboxMauiQs/Examples/MarkersAndCallouts/ViewAnnotations/64.ViewAnnotationWithPointAnnotation/ViewAnnotationWithPointAnnotationExample.cs

+58-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ private void AddViewAnnotationAt(IPosition value)
8080
var options = new ViewAnnotationOptions
8181
{
8282
Geometry = new GeoJSON.Text.Geometry.Point(value),
83-
Width = 128,
84-
Height = 64,
83+
Width = 144,
84+
Height = 96,
8585
AssociatedFeatureId = Constants.markerId,
8686
AllowOverlap = false,
8787
Anchor = ViewAnnotationAnchor.Bottom,
@@ -105,11 +105,65 @@ private void AddPointAnnotationAt(IPosition value)
105105
pointAnnotationManager.AddAnnotations(pointAnnotation);
106106
}
107107

108-
class SimpleViewAnnodationView : Label
108+
class SimpleViewAnnodationView : Grid
109109
{
110110
public SimpleViewAnnodationView()
111111
{
112-
Text = "Simple";
112+
RowDefinitions.Add(new RowDefinition
113+
{
114+
Height = 16,
115+
});
116+
RowDefinitions.Add(new RowDefinition
117+
{
118+
Height = 48,
119+
});
120+
RowDefinitions.Add(new RowDefinition
121+
{
122+
Height = 32,
123+
});
124+
BackgroundColor = Colors.Purple;
125+
126+
var label = new Label
127+
{
128+
TextColor = Colors.White,
129+
FontSize = 10,
130+
HorizontalOptions = LayoutOptions.Center,
131+
VerticalOptions = LayoutOptions.Center,
132+
Padding = new Thickness(24, 0),
133+
};
134+
135+
label.SetBinding(Label.TextProperty, new Binding(nameof(ViewAnnotationOptions.Title)));
136+
137+
var btnClose = new Label()
138+
{
139+
Text = "X",
140+
TextColor = Colors.Red,
141+
FontSize = 12,
142+
Padding = new Thickness(2),
143+
Margin = 4,
144+
VerticalOptions = LayoutOptions.Start,
145+
HorizontalOptions = LayoutOptions.End,
146+
};
147+
var btnSelect = new Label()
148+
{
149+
Text = "Select",
150+
FontSize = 12,
151+
TextColor = Colors.White,
152+
BackgroundColor = Colors.BlueViolet,
153+
Padding = new Thickness(12, 4),
154+
Margin = 6,
155+
VerticalOptions = LayoutOptions.Center,
156+
HorizontalOptions = LayoutOptions.Center,
157+
};
158+
159+
Add(label);
160+
Add(btnClose);
161+
Add(btnSelect);
162+
163+
Grid.SetRow(btnClose, 0);
164+
Grid.SetRowSpan(btnClose, 2);
165+
Grid.SetRow(label, 1);
166+
Grid.SetRow(btnSelect, 2);
113167
}
114168
}
115169

0 commit comments

Comments
 (0)