diff --git a/GoogleMapsComponents/Maps/AdvancedMarkerView.cs b/GoogleMapsComponents/Maps/AdvancedMarkerView.cs index 0a3a4ab9..29cdc8fa 100644 --- a/GoogleMapsComponents/Maps/AdvancedMarkerView.cs +++ b/GoogleMapsComponents/Maps/AdvancedMarkerView.cs @@ -1,5 +1,5 @@ using Microsoft.JSInterop; - +using System; using System.Threading.Tasks; namespace GoogleMapsComponents.Maps; @@ -8,6 +8,30 @@ namespace GoogleMapsComponents.Maps; /// 2023-09 /// Notice: Available only in the v=beta channel. /// +public class AdvancedMarkerElement : ListableEntityBase +{ + // https://developers.google.com/maps/documentation/javascript/reference/3.55/advanced-markers + public const string GoogleMapAdvancedMarkerName = "google.maps.marker.AdvancedMarkerElement"; + + public static async Task CreateAsync(IJSRuntime jsRuntime, AdvancedMarkerElementOptions? opts = null) + { + var jsObjectRef = await JsObjectRef.CreateAsync(jsRuntime, GoogleMapAdvancedMarkerName, opts); + var obj = new Marker(jsObjectRef); + return obj; + } + + internal AdvancedMarkerElement(JsObjectRef jsObjectRef) + : base(jsObjectRef) + { + } + + public Task GetZIndex() + { + return _jsObjectRef.InvokeAsync("getZIndex"); + } +} + +[Obsolete("Use AdvancedMarkerElement")] public class AdvancedMarkerView : ListableEntityBase { // https://developers.google.com/maps/documentation/javascript/reference/3.55/advanced-markers diff --git a/GoogleMapsComponents/Maps/AdvancedMarkerViewOptions.cs b/GoogleMapsComponents/Maps/AdvancedMarkerViewOptions.cs index 0cc1e015..9a824055 100644 --- a/GoogleMapsComponents/Maps/AdvancedMarkerViewOptions.cs +++ b/GoogleMapsComponents/Maps/AdvancedMarkerViewOptions.cs @@ -1,38 +1,73 @@ -using System.Text.Json.Serialization; +using System; +using System.Text.Json.Serialization; -namespace GoogleMapsComponents.Maps +namespace GoogleMapsComponents.Maps; + +public class AdvancedMarkerElementOptions : ListableEntityOptionsBase { - public class AdvancedMarkerViewOptions : ListableEntityOptionsBase - { - /// - /// Sets the AdvancedMarkerElement's position. An AdvancedMarkerElement may be constructed without a position, but will not be displayed until its position is provided - for example, by a user's actions or choices. An AdvancedMarkerElement's position can be provided by setting AdvancedMarkerElement.position if not provided at the construction. - /// Note: AdvancedMarkerElement with altitude is only supported on vector maps. - /// - public LatLngLiteral? Position { get; set; } - - /// - /// An enumeration specifying how an AdvancedMarkerElement should behave when it collides with another AdvancedMarkerElement or with the basemap labels on a vector map. - /// Note: AdvancedMarkerElement to AdvancedMarkerElement collision works on both raster and vector maps, however, AdvancedMarkerElement to base map's label collision only works on vector maps. - /// - - [JsonConverter(typeof(GoogleMapsComponents.Serialization.JsonStringEnumConverterEx))] - public CollisionBehavior? CollisionBehavior { get; set; } - - /// - /// 2023-10-29 Currently only html content is supported - /// Svg, images url could not work - /// - public string? Content { get; set; } - - /// - /// If true, the AdvancedMarkerElement can be dragged. - /// Note: AdvancedMarkerElement with altitude is not draggable. - /// - public bool GmpDraggable { get; set; } - - /// - /// Rollover text. If provided, an accessibility text (e.g. for use with screen readers) will be added to the - /// - public string? Title { get; set; } - } + /// + /// Sets the AdvancedMarkerElement's position. An AdvancedMarkerElement may be constructed without a position, but will not be displayed until its position is provided - for example, by a user's actions or choices. An AdvancedMarkerElement's position can be provided by setting AdvancedMarkerElement.position if not provided at the construction. + /// Note: AdvancedMarkerElement with altitude is only supported on vector maps. + /// + public LatLngLiteral? Position { get; set; } + + /// + /// An enumeration specifying how an AdvancedMarkerElement should behave when it collides with another AdvancedMarkerElement or with the basemap labels on a vector map. + /// Note: AdvancedMarkerElement to AdvancedMarkerElement collision works on both raster and vector maps, however, AdvancedMarkerElement to base map's label collision only works on vector maps. + /// + + [JsonConverter(typeof(Serialization.JsonStringEnumConverterEx))] + public CollisionBehavior? CollisionBehavior { get; set; } + + /// + /// 2023-10-29 Currently only html content is supported + /// Svg, images url could not work + /// + public string? Content { get; set; } + + /// + /// If true, the AdvancedMarkerElement can be dragged. + /// Note: AdvancedMarkerElement with altitude is not draggable. + /// + public bool GmpDraggable { get; set; } + + /// + /// Rollover text. If provided, an accessibility text (e.g. for use with screen readers) will be added to the + /// + public string? Title { get; set; } } + +[Obsolete("Use AdvancedMarkerElementOptions")] +public class AdvancedMarkerViewOptions : ListableEntityOptionsBase +{ + /// + /// Sets the AdvancedMarkerElement's position. An AdvancedMarkerElement may be constructed without a position, but will not be displayed until its position is provided - for example, by a user's actions or choices. An AdvancedMarkerElement's position can be provided by setting AdvancedMarkerElement.position if not provided at the construction. + /// Note: AdvancedMarkerElement with altitude is only supported on vector maps. + /// + public LatLngLiteral? Position { get; set; } + + /// + /// An enumeration specifying how an AdvancedMarkerElement should behave when it collides with another AdvancedMarkerElement or with the basemap labels on a vector map. + /// Note: AdvancedMarkerElement to AdvancedMarkerElement collision works on both raster and vector maps, however, AdvancedMarkerElement to base map's label collision only works on vector maps. + /// + + [JsonConverter(typeof(Serialization.JsonStringEnumConverterEx))] + public CollisionBehavior? CollisionBehavior { get; set; } + + /// + /// 2023-10-29 Currently only html content is supported + /// Svg, images url could not work + /// + public string? Content { get; set; } + + /// + /// If true, the AdvancedMarkerElement can be dragged. + /// Note: AdvancedMarkerElement with altitude is not draggable. + /// + public bool GmpDraggable { get; set; } + + /// + /// Rollover text. If provided, an accessibility text (e.g. for use with screen readers) will be added to the + /// + public string? Title { get; set; } +} \ No newline at end of file diff --git a/GoogleMapsComponents/Maps/Extension/AdvancedMarkerList.cs b/GoogleMapsComponents/Maps/Extension/AdvancedMarkerElementList.cs similarity index 83% rename from GoogleMapsComponents/Maps/Extension/AdvancedMarkerList.cs rename to GoogleMapsComponents/Maps/Extension/AdvancedMarkerElementList.cs index 3764091c..469ebb2a 100644 --- a/GoogleMapsComponents/Maps/Extension/AdvancedMarkerList.cs +++ b/GoogleMapsComponents/Maps/Extension/AdvancedMarkerElementList.cs @@ -11,28 +11,28 @@ namespace GoogleMapsComponents.Maps.Extension; /// /// -/// A class able to manage a lot of AdvancedMarkerView objects and get / set their properties at the same time, eventually with different values +/// A class able to manage a lot of AdvancedMarkerElement objects and get / set their properties at the same time, eventually with different values /// /// -/// Main concept is that for each AdvancedMarkerView to be distinguished from other ones, it needs +/// Main concept is that for each AdvancedMarkerElement to be distinguished from other ones, it needs /// to have a "unique key" with an "external world meaning", so not necessarily a GUID. /// /// -/// In real cases Markers are likely to be linked to places, activities, transit stops and so on -> So, what better way to choose as AdvancedMarkerView "unique key" the "id" of the object each marker is related to? +/// In real cases Markers are likely to be linked to places, activities, transit stops and so on -> So, what better way to choose as AdvancedMarkerElement "unique key" the "id" of the object each marker is related to? /// A string key has been selected as type due to its implicit versatility. /// /// -/// To create Markers, simply call AdvancedMarkerList.CreateAsync with a Dictionary of desired AdvancedMarkerView keys and AdvancedMarkerViewOptions values. +/// To create Markers, simply call AdvancedMarkerList.CreateAsync with a Dictionary of desired AdvancedMarkerElement keys and AdvancedMarkerElementOptions values. /// After that, a new instance of AdvancedMarkerList class will be returned with its Markers dictionary member populated with the corresponding results /// /// /// At run-time is possible to:
/// -/// add AdvancedMarkerView to the same AdvancedMarkerList class using AddMultipleAsync method (only keys not matching with existent AdvancedMarkerView keys will be created)
-/// Markers dictionary will contain "union distinct" of existent AdvancedMarkerView's keys and new keys
+/// add AdvancedMarkerElement to the same AdvancedMarkerList class using AddMultipleAsync method (only keys not matching with existent AdvancedMarkerElement keys will be created)
+/// Markers dictionary will contain "union distinct" of existent AdvancedMarkerElement's keys and new keys
///
-/// remove AdvancedMarkerView from the AdvancedMarkerList class (only AdvancedMarkerView having keys matching with existent keys will be removed)
-/// Markers dictionary will contain "original - required and found" AdvancedMarkerView's keys (eventually any is all AdvancedMarkerView are removed)
+/// remove AdvancedMarkerElement from the AdvancedMarkerList class (only AdvancedMarkerElement having keys matching with existent keys will be removed)
+/// Markers dictionary will contain "original - required and found" AdvancedMarkerElement's keys (eventually any is all AdvancedMarkerElement are removed)
///
///
///
@@ -43,30 +43,30 @@ namespace GoogleMapsComponents.Maps.Extension; /// /// /// Each setter properties can be used as follows:
-/// With a Dictionary<string, {property type}> indicating for each AdvancedMarkerView (related to that key) the corresponding related property value. +/// With a Dictionary<string, {property type}> indicating for each AdvancedMarkerElement (related to that key) the corresponding related property value. ///
///
-public class AdvancedMarkerList : ListableEntityListBase +public class AdvancedMarkerElementList : ListableEntityListBase { - public Dictionary Markers => BaseListableEntities; + public Dictionary Markers => BaseListableEntities; /// /// Create markers list /// /// - /// Dictionary of desired AdvancedMarkerView keys and AdvancedMarkerViewOptions values. Key as any type unique key. Not necessarily Guid + /// Dictionary of desired AdvancedMarkerElement keys and AdvancedMarkerElementOptions values. Key as any type unique key. Not necessarily Guid /// New instance of AdvancedMarkerList class will be returned with its Markers dictionary member populated with the corresponding results - public static async Task CreateAsync(IJSRuntime jsRuntime, Dictionary opts) + public static async Task CreateAsync(IJSRuntime jsRuntime, Dictionary opts) { var jsObjectRef = new JsObjectRef(jsRuntime, Guid.NewGuid()); Dictionary jsObjectRefs = await JsObjectRef.CreateMultipleAsync( jsRuntime, - AdvancedMarkerView.GoogleMapAdvancedMarkerName, + AdvancedMarkerElement.GoogleMapAdvancedMarkerName, opts.ToDictionary(e => e.Key, e => (object)e.Value)); - Dictionary objs = jsObjectRefs.ToDictionary(e => e.Key, e => new AdvancedMarkerView(e.Value)); - var obj = new AdvancedMarkerList(jsObjectRef, objs); + Dictionary objs = jsObjectRefs.ToDictionary(e => e.Key, e => new AdvancedMarkerElement(e.Value)); + var obj = new AdvancedMarkerElementList(jsObjectRef, objs); return obj; } @@ -84,10 +84,10 @@ public static async Task CreateAsync(IJSRuntime jsRuntime, D /// /// The managed list. Assign to the variable you used as parameter. /// - public static async Task SyncAsync(AdvancedMarkerList? list, + public static async Task SyncAsync(AdvancedMarkerElementList? list, IJSRuntime jsRuntime, - Dictionary opts, - Action? clickCallback = null) + Dictionary opts, + Action? clickCallback = null) { if (opts.Count == 0) { @@ -101,7 +101,7 @@ public static async Task SyncAsync(AdvancedMarkerList? list, { if (list == null) { - list = await AdvancedMarkerList.CreateAsync(jsRuntime, new Dictionary()); + list = await AdvancedMarkerElementList.CreateAsync(jsRuntime, new Dictionary()); if (clickCallback != null) { list.EntityClicked += (_, e) => @@ -115,7 +115,7 @@ public static async Task SyncAsync(AdvancedMarkerList? list, return list; } - private AdvancedMarkerList(JsObjectRef jsObjectRef, Dictionary markers) + private AdvancedMarkerElementList(JsObjectRef jsObjectRef, Dictionary markers) : base(jsObjectRef, markers) { } @@ -125,18 +125,18 @@ private AdvancedMarkerList(JsObjectRef jsObjectRef, Dictionary /// /// - public async Task SetMultipleAsync(Dictionary opts) + public async Task SetMultipleAsync(Dictionary opts) { - await base.SetMultipleAsync(opts, AdvancedMarkerView.GoogleMapAdvancedMarkerName); + await base.SetMultipleAsync(opts, AdvancedMarkerElement.GoogleMapAdvancedMarkerName); } /// - /// Only keys not matching with existent AdvancedMarkerView keys will be created + /// Only keys not matching with existent AdvancedMarkerElement keys will be created /// /// - public async Task AddMultipleAsync(Dictionary opts) + public async Task AddMultipleAsync(Dictionary opts) { - await base.AddMultipleAsync(opts, AdvancedMarkerView.GoogleMapAdvancedMarkerName); + await base.AddMultipleAsync(opts, AdvancedMarkerElement.GoogleMapAdvancedMarkerName); } public Task> GetAnimations(List? filterKeys = null) @@ -352,7 +352,7 @@ public Task SetCursors(Dictionary cursors) } /// - /// Set Icon on each AdvancedMarkerView matching a param dictionary key to the param value with single JSInterop call. + /// Set Icon on each AdvancedMarkerElement matching a param dictionary key to the param value with single JSInterop call. /// /// /// @@ -379,7 +379,7 @@ public Task SetIcons(Dictionary icons) } /// - /// Set Label on each AdvancedMarkerView matching a param dictionary key to the param value with single JSInterop call. + /// Set Label on each AdvancedMarkerElement matching a param dictionary key to the param value with single JSInterop call. /// /// /// diff --git a/ServerSideDemo/Pages/AdvancedMarkerViewPage.razor b/ServerSideDemo/Pages/AdvancedMarkerViewPage.razor index 4ced6cd8..0f7b5bbc 100644 --- a/ServerSideDemo/Pages/AdvancedMarkerViewPage.razor +++ b/ServerSideDemo/Pages/AdvancedMarkerViewPage.razor @@ -10,14 +10,11 @@ @code { private GoogleMap _map1; private MapOptions _mapOptions; - - private readonly List _events = new List(); - private ElementReference memberRef; private LatLngBounds _bounds; [Inject] - public IJSRuntime JsObjectRef { get; set; } + public IJSRuntime JsObjectRef { get; set; } = null!; protected override void OnInitialized() { @@ -43,7 +40,7 @@ { var mapCenter = await _map1.InteropObject.GetCenter(); - var marker = await AdvancedMarkerView.CreateAsync(_map1.JsRuntime, new AdvancedMarkerViewOptions() + var marker = await AdvancedMarkerElement.CreateAsync(_map1.JsRuntime, new AdvancedMarkerElementOptions() { Position = mapCenter, Map = _map1.InteropObject, diff --git a/ServerSideDemo/Pages/MapAdvancedMarkerListPage.razor b/ServerSideDemo/Pages/MapAdvancedMarkerElementListPage.razor similarity index 58% rename from ServerSideDemo/Pages/MapAdvancedMarkerListPage.razor rename to ServerSideDemo/Pages/MapAdvancedMarkerElementListPage.razor index 487bb26d..a35cbeb5 100644 --- a/ServerSideDemo/Pages/MapAdvancedMarkerListPage.razor +++ b/ServerSideDemo/Pages/MapAdvancedMarkerElementListPage.razor @@ -3,13 +3,10 @@

Google Advanced Map Markers List

- + - + - - - - \ No newline at end of file + \ No newline at end of file diff --git a/ServerSideDemo/Pages/MapAdvancedMarkerElementListPage.razor.cs b/ServerSideDemo/Pages/MapAdvancedMarkerElementListPage.razor.cs new file mode 100644 index 00000000..49cce133 --- /dev/null +++ b/ServerSideDemo/Pages/MapAdvancedMarkerElementListPage.razor.cs @@ -0,0 +1,186 @@ +using GoogleMapsComponents; +using GoogleMapsComponents.Maps; +using GoogleMapsComponents.Maps.Coordinates; +using GoogleMapsComponents.Maps.Extension; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace ServerSideDemo.Pages; + +public partial class MapAdvancedMarkerElementListPage +{ + private GoogleMap _map1; + + private MapOptions _mapOptions; + + private Stack _markers = new Stack(); + + private LatLngBounds _bounds; + + private AdvancedMarkerElementList? _markerElementList; + + [Inject] + public IJSRuntime JsObjectRef { get; set; } = default!; + + protected override void OnInitialized() + { + _mapOptions = new MapOptions() + { + Zoom = 13, + Center = new LatLngLiteral() + { + Lat = 13.505892, + Lng = 100.8162 + }, + MapTypeId = MapTypeId.Roadmap + }; + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + _bounds = await LatLngBounds.CreateAsync(_map1.JsRuntime); + } + } + + private async Task AddMarker2() + { + var coordinates = new List() + { + new LatLngLiteral(){ Lng = 145.128708, Lat = -37.759859 }, + new LatLngLiteral(){ Lng = 145.133858, Lat = -37.765015 }, + new LatLngLiteral(){ Lng = 145.143299, Lat = -37.770104 }, + new LatLngLiteral(){ Lng = 145.145187, Lat = -37.7737 }, + new LatLngLiteral(){ Lng = 145.137978, Lat = -37.774785 }, + new LatLngLiteral(){ Lng = 144.968119, Lat = -37.819616 }, + new LatLngLiteral(){ Lng = 144.695692, Lat = -38.330766 }, + new LatLngLiteral(){ Lng = 175.053218, Lat = -39.927193 }, + new LatLngLiteral(){ Lng = 174.865694, Lat = -41.330162 }, + new LatLngLiteral(){ Lng = 147.439506, Lat = -42.734358 }, + new LatLngLiteral(){ Lng = 147.501315, Lat = -42.734358 }, + new LatLngLiteral(){ Lng = 147.438, Lat = -42.735258 }, + new LatLngLiteral(){ Lng = 170.463352, Lat = -43.999792 }, + }; + await AddMarkersGroup(coordinates); + } + + private async Task AddMarker1() + { + var coordinates = new List() + { + new LatLngLiteral(){ Lng = 147.154312, Lat = -31.56391 }, + new LatLngLiteral(){ Lng = 150.363181, Lat = -33.718234 }, + new LatLngLiteral(){ Lng = 150.371124, Lat = -33.727111 }, + new LatLngLiteral(){ Lng = 151.209834, Lat = -33.848588 }, + new LatLngLiteral(){ Lng = 151.216968, Lat = -33.851702 }, + new LatLngLiteral(){ Lng = 150.863657, Lat = -34.671264 }, + new LatLngLiteral(){ Lng = 148.662905, Lat = -35.304724 }, + new LatLngLiteral(){ Lng = 175.699196, Lat = -36.817685 }, + new LatLngLiteral(){ Lng = 175.790222, Lat = -36.828611 }, + new LatLngLiteral(){ Lng = 145.116667, Lat = -37.75 }, + }; + + + for (int index = 0; index < 200; index++) + { + var dif = (index * 0.001); + coordinates.Add(new LatLngLiteral() { Lng = 145.116667 + dif, Lat = -37.75 + dif }); + } + + await AddMarkersGroup(coordinates); + } + + private async Task AddMarkersGroup(ICollection coordinates) + { + if (_markerElementList == null) + { + _markerElementList = await AdvancedMarkerElementList.CreateAsync( + _map1.JsRuntime, + coordinates.ToDictionary(_ => Guid.NewGuid().ToString(), y => new AdvancedMarkerElementOptions() + { + Position = new LatLngLiteral() { Lng = y.Lng, Lat = y.Lat }, + Map = _map1.InteropObject, + //Icon = new Icon() { Url = s.MarkerIconPath, ScaledSize = iconSize, Anchor = iconAnchor }, + Clickable = true, + Title = Guid.NewGuid().ToString(), + Visible = true + }) + ); + } + else + { + var cordDic = coordinates.ToDictionary(_ => Guid.NewGuid().ToString(), y => new AdvancedMarkerElementOptions() + { + Position = new LatLngLiteral() { Lng = y.Lng, Lat = y.Lat }, + Map = _map1.InteropObject, + //Icon = new Icon() { Url = s.MarkerIconPath, ScaledSize = iconSize, Anchor = iconAnchor }, + Clickable = true, + Title = Guid.NewGuid().ToString(), + Visible = true + }); + + await _markerElementList.AddMultipleAsync(cordDic); + } + + foreach (var latLngLiteral in coordinates) + { + await _bounds.Extend(latLngLiteral); + } + + await FitBounds(); + } + + private async Task RemoveMarkers() + { + if (_markerElementList == null) + { + return; + } + + foreach (var markerListMarker in _markerElementList.Markers) + { + await markerListMarker.Value.SetMap(null); + } + + await _markerElementList.RemoveAllAsync(); + } + + private async Task RemoveMarker() + { + if (!_markers.Any()) + { + return; + } + + var lastMarker = _markers.Pop(); + await lastMarker.SetMap(null); + } + + private async Task Recenter() + { + if (!_markers.Any()) + { + return; + } + + var lastMarker = _markers.Peek(); + var center = await _map1.InteropObject.GetCenter(); + await lastMarker.SetPosition(center); + } + + private async Task FitBounds() + { + if (await this._bounds.IsEmpty()) + { + return; + } + + var boundsLiteral = await _bounds.ToJson(); + await _map1.InteropObject.FitBounds(boundsLiteral, OneOf.OneOf.FromT0(5)); + } +} \ No newline at end of file diff --git a/ServerSideDemo/Pages/MapAdvancedMarkerListPage.razor.cs b/ServerSideDemo/Pages/MapAdvancedMarkerListPage.razor.cs deleted file mode 100644 index 3bafa763..00000000 --- a/ServerSideDemo/Pages/MapAdvancedMarkerListPage.razor.cs +++ /dev/null @@ -1,249 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -using GoogleMapsComponents; -using GoogleMapsComponents.Maps; -using GoogleMapsComponents.Maps.Coordinates; -using GoogleMapsComponents.Maps.Extension; - -using Microsoft.AspNetCore.Components; -using Microsoft.JSInterop; - -using ServerSideDemo.Shared; - -namespace ServerSideDemo.Pages; - -public partial class MapAdvancedMarkerListPage -{ - private GoogleMap map1; - - private MapOptions mapOptions; - - private Stack markers = new Stack(); - - private List _events = new List(); - - private MapEventList eventList; - - private LatLngBounds bounds; - private AdvancedMarkerList _markerList; - - [Inject] - public IJSRuntime JsObjectRef { get; set; } - - protected override void OnInitialized() - { - mapOptions = new MapOptions() - { - Zoom = 13, - Center = new LatLngLiteral() - { - Lat = 13.505892, - Lng = 100.8162 - }, - MapTypeId = MapTypeId.Roadmap - }; - } - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - bounds = await LatLngBounds.CreateAsync(map1.JsRuntime); - } - } - - private async Task InvokeClustering() - { - var coordinates = new List() - { - new LatLngLiteral(){ Lng = 147.154312, Lat = -31.56391 }, - new LatLngLiteral(){ Lng = 150.363181, Lat = -33.718234 }, - new LatLngLiteral(){ Lng = 150.371124, Lat = -33.727111 }, - new LatLngLiteral(){ Lng = 151.209834, Lat = -33.848588 }, - new LatLngLiteral(){ Lng = 151.216968, Lat = -33.851702 }, - new LatLngLiteral(){ Lng = 150.863657, Lat = -34.671264 }, - new LatLngLiteral(){ Lng = 148.662905, Lat = -35.304724 }, - new LatLngLiteral(){ Lng = 175.699196, Lat = -36.817685 }, - new LatLngLiteral(){ Lng = 175.790222, Lat = -36.828611 }, - new LatLngLiteral(){ Lng = 145.116667, Lat = -37.75 }, - new LatLngLiteral(){ Lng = 145.128708, Lat = -37.759859 }, - new LatLngLiteral(){ Lng = 145.133858, Lat = -37.765015 }, - new LatLngLiteral(){ Lng = 145.143299, Lat = -37.770104 }, - new LatLngLiteral(){ Lng = 145.145187, Lat = -37.7737 }, - new LatLngLiteral(){ Lng = 145.137978, Lat = -37.774785 }, - new LatLngLiteral(){ Lng = 144.968119, Lat = -37.819616 }, - new LatLngLiteral(){ Lng = 144.695692, Lat = -38.330766 }, - new LatLngLiteral(){ Lng = 175.053218, Lat = -39.927193 }, - new LatLngLiteral(){ Lng = 174.865694, Lat = -41.330162 }, - new LatLngLiteral(){ Lng = 147.439506, Lat = -42.734358 }, - new LatLngLiteral(){ Lng = 147.501315, Lat = -42.734358 }, - new LatLngLiteral(){ Lng = 147.438, Lat = -42.735258 }, - new LatLngLiteral(){ Lng = 170.463352, Lat = -43.999792 }, - }; - - var markers = await GetMarkers(coordinates, map1.InteropObject); - - await MarkerClustering.CreateAsync(map1.JsRuntime, map1.InteropObject, markers); - - //initMap - //await JsObjectRef.InvokeAsync("initMap", map1.InteropObject.Guid.ToString(), markers); - } - - private async Task> GetMarkers(IEnumerable coords, Map map) - { - var result = new List(coords.Count()); - var index = 1; - foreach (var latLngLiteral in coords) - { - var marker = await AdvancedMarkerView.CreateAsync(map1.JsRuntime, new AdvancedMarkerViewOptions() - { - Position = latLngLiteral, - Map = map, - Content = $"Test {index++}", - //Icon = new Icon() - //{ - // Url = "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png" - //} - //Icon = "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png" - }); - - result.Add(marker); - } - - return result; - } - - private async Task AddMarker2() - { - var coordinates = new List() - { - new LatLngLiteral(){ Lng = 145.128708, Lat = -37.759859 }, - new LatLngLiteral(){ Lng = 145.133858, Lat = -37.765015 }, - new LatLngLiteral(){ Lng = 145.143299, Lat = -37.770104 }, - new LatLngLiteral(){ Lng = 145.145187, Lat = -37.7737 }, - new LatLngLiteral(){ Lng = 145.137978, Lat = -37.774785 }, - new LatLngLiteral(){ Lng = 144.968119, Lat = -37.819616 }, - new LatLngLiteral(){ Lng = 144.695692, Lat = -38.330766 }, - new LatLngLiteral(){ Lng = 175.053218, Lat = -39.927193 }, - new LatLngLiteral(){ Lng = 174.865694, Lat = -41.330162 }, - new LatLngLiteral(){ Lng = 147.439506, Lat = -42.734358 }, - new LatLngLiteral(){ Lng = 147.501315, Lat = -42.734358 }, - new LatLngLiteral(){ Lng = 147.438, Lat = -42.735258 }, - new LatLngLiteral(){ Lng = 170.463352, Lat = -43.999792 }, - }; - await AddMarkersGroup(coordinates); - } - - private async Task AddMarker1() - { - var coordinates = new List() - { - new LatLngLiteral(){ Lng = 147.154312, Lat = -31.56391 }, - new LatLngLiteral(){ Lng = 150.363181, Lat = -33.718234 }, - new LatLngLiteral(){ Lng = 150.371124, Lat = -33.727111 }, - new LatLngLiteral(){ Lng = 151.209834, Lat = -33.848588 }, - new LatLngLiteral(){ Lng = 151.216968, Lat = -33.851702 }, - new LatLngLiteral(){ Lng = 150.863657, Lat = -34.671264 }, - new LatLngLiteral(){ Lng = 148.662905, Lat = -35.304724 }, - new LatLngLiteral(){ Lng = 175.699196, Lat = -36.817685 }, - new LatLngLiteral(){ Lng = 175.790222, Lat = -36.828611 }, - new LatLngLiteral(){ Lng = 145.116667, Lat = -37.75 }, - }; - - - for (int index = 0; index < 200; index++) - { - var dif = (index * 0.001); - coordinates.Add(new LatLngLiteral() { Lng = 145.116667 + dif, Lat = -37.75 + dif }); - } - - await AddMarkersGroup(coordinates); - } - - private async Task AddMarkersGroup(IEnumerable coordinates) - { - if (_markerList == null) - { - _markerList = await AdvancedMarkerList.CreateAsync( - map1.JsRuntime, - coordinates.ToDictionary(s => Guid.NewGuid().ToString(), y => new AdvancedMarkerViewOptions() - { - Position = new LatLngLiteral() { Lng = y.Lng, Lat = y.Lat }, - Map = map1.InteropObject, - //Icon = new Icon() { Url = s.MarkerIconPath, ScaledSize = iconSize, Anchor = iconAnchor }, - Clickable = true, - Title = Guid.NewGuid().ToString(), - Visible = true - }) - ); - } - else - { - var cordDic = coordinates.ToDictionary(s => Guid.NewGuid().ToString(), y => new AdvancedMarkerViewOptions() - { - Position = new LatLngLiteral() { Lng = y.Lng, Lat = y.Lat }, - Map = map1.InteropObject, - //Icon = new Icon() { Url = s.MarkerIconPath, ScaledSize = iconSize, Anchor = iconAnchor }, - Clickable = true, - Title = Guid.NewGuid().ToString(), - Visible = true - }); - - await _markerList.AddMultipleAsync(cordDic); - } - - foreach (var latLngLiteral in coordinates) - { - await bounds.Extend(latLngLiteral); - } - - await FitBounds(); - } - - private async Task RemoveMarkers() - { - foreach (var markerListMarker in _markerList.Markers) - { - await markerListMarker.Value.SetMap(null); - } - - await _markerList.RemoveAllAsync(); - } - - private async Task RemoveMarker() - { - if (!markers.Any()) - { - return; - } - - var lastMarker = markers.Pop(); - await lastMarker.SetMap(null); - } - - private async Task Recenter() - { - if (!markers.Any()) - { - return; - } - - var lastMarker = markers.Peek(); - var center = await map1.InteropObject.GetCenter(); - await lastMarker.SetPosition(center); - } - - private async Task FitBounds() - { - if (await this.bounds.IsEmpty()) - { - return; - } - - var boundsLiteral = await bounds.ToJson(); - await map1.InteropObject.FitBounds(boundsLiteral, OneOf.OneOf.FromT0(5)); - } -} \ No newline at end of file