Skip to content

Commit

Permalink
Update map
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-bym committed Feb 8, 2024
1 parent 2ec5094 commit 1032e37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
27 changes: 1 addition & 26 deletions src/GenOne.Blazor.Map/src/Component/Map.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

@code {
//todo refactor: notify property change, validate logic, logic to manage multiple markers
[Parameter]
public string? Class { get; set; }

Expand Down Expand Up @@ -56,9 +55,6 @@
[Parameter]
public EventCallback<bool> FollowConsumerLocationChanged { get; set; }

[Parameter]
public GpsLocation? InitMarkerPosition { get; set; }

[Parameter]
public GpsLocation? MarkerPosition

Check warning on line 59 in src/GenOne.Blazor.Map/src/Component/Map.razor

View workflow job for this annotation

GitHub Actions / publish-packages

Component parameter 'GenOne.Blazor.Map.Component.Map.MarkerPosition' should be auto property

Check warning on line 59 in src/GenOne.Blazor.Map/src/Component/Map.razor

View workflow job for this annotation

GitHub Actions / publish-packages

Component parameter 'GenOne.Blazor.Map.Component.Map.MarkerPosition' should be auto property
{
Expand Down Expand Up @@ -92,28 +88,12 @@

private GpsLocation? _markerPosition;

[Parameter]
public GpsLocation? InitViewPosition { get; set; }

[Parameter]
public GpsLocation? ViewPosition
{
get => _viewPosition;
set
{
_viewPosition = value;
_updates.Writer.TryWrite(FieldUpdated.ViewPosition);
}
}

[Parameter]
public IMapIconFactory? OverrideIconFactory { get; set; }

[Parameter]
public EventCallback<Map> OnMapInitialized { get; set; }

private GpsLocation? _viewPosition;

private DPBMap? _map;

private DPBMapOptions? _mapOptions;
Expand Down Expand Up @@ -162,12 +142,7 @@

_ = await Factory.CreateTileLayerAndAddToMap(Options.Value.UrlTileTemplate, _map, tileLayerOptions);

MarkerPosition = InitMarkerPosition ?? MarkerPosition;

var viewPosition = InitViewPosition ?? InitMarkerPosition ?? ViewPosition ?? MarkerPosition ?? ConsumerLocation?.Location;
await UpdateViewLocation(viewPosition, false);

StartReadUpdates();
StartReadUpdates();

await _map.OnClick(OnClickInner);
await _map.MapEvented.OnDragStart(_ => DisableFollowConsumerLocation());
Expand Down
16 changes: 3 additions & 13 deletions src/GenOne.Blazor.Map/src/Component/Map.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ async Task Read()
{
switch (item)
{
case FieldUpdated.ViewPosition:
await UpdateViewLocation();
break;
case FieldUpdated.ConsumerLocation:
_userMarker = await Factory.AddOrUpdateMarker(_userMarker, _map, _consumerLocation?.Location.LatLng(), ResolvedIconFactory.PrepareUserMarkerOptions);
if (FollowConsumerLocation)
Expand Down Expand Up @@ -93,12 +90,6 @@ _marker is not null

Task.Run(Read, CancellationToken.None);
}

public Task UpdateViewLocation(GpsLocation? location, bool flyTo = true, int? zoom = null)
{
_viewPosition = location;
return UpdateViewLocation(flyTo, zoom);
}

public async Task ViewAllMarkers(bool flyTo = true, int? zoom = null)
{
Expand All @@ -110,7 +101,7 @@ public async Task ViewAllMarkers(bool flyTo = true, int? zoom = null)
case (true, true):
var bounds = GeoBounds.FromLocations(MarkerPosition!, ConsumerLocation!.Location).LatLngBounds();
if (flyTo)
{
{
await _map.FlyToBounds(bounds);
}
else
Expand All @@ -129,9 +120,9 @@ public async Task ViewAllMarkers(bool flyTo = true, int? zoom = null)
}
}

private async Task UpdateViewLocation(bool flyTo = true, int? zoom = null)
private async Task UpdateViewLocation(GpsLocation? location, bool flyTo = true, int? zoom = null)
{
var latLng = _viewPosition.LatLng();
var latLng = location.LatLng();

if (latLng is null || _map is null)
return;
Expand All @@ -151,7 +142,6 @@ private enum FieldUpdated
{
ConsumerLocation,
MarkerLocation,
ViewPosition,
MarkerLocationCanBeChanged,
FollowConsumerLocation
}
Expand Down

0 comments on commit 1032e37

Please sign in to comment.