166 lines
4.9 KiB
C#
166 lines
4.9 KiB
C#
|
using Microsoft.AspNetCore.Components;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using Telerik.Blazor.Components;
|
|||
|
using TSC2.Components;
|
|||
|
|
|||
|
namespace TSC2.Components.Pages
|
|||
|
{
|
|||
|
public partial class Home
|
|||
|
{
|
|||
|
TelerikMap MapRef { get; set; } = new TelerikMap();
|
|||
|
public double Zoom { get; set; } = 1;
|
|||
|
public static double[] Center = [40.68, 74.04];
|
|||
|
public string MapHeight { get; set; } = "800px";
|
|||
|
|
|||
|
public string ShopName { get; set; } = "";
|
|||
|
public string CSZ { get; set; } = "";
|
|||
|
|
|||
|
public string[] Subdomains { get; set; } = new string[] { "a", "b", "c" };
|
|||
|
public string UrlTemplate { get; set; } = "https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png";
|
|||
|
public string Attribution { get; set; } = "© <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>";
|
|||
|
|
|||
|
private bool initialized = false;
|
|||
|
|
|||
|
|
|||
|
// User info
|
|||
|
string ip = "";
|
|||
|
|
|||
|
protected override void OnInitialized() // Executes every page load; run inexpensive rendering code here
|
|||
|
{
|
|||
|
Console.WriteLine("MapRef null? : " + (MapRef == null ? "yes" : "no"));
|
|||
|
InitializeMapMarkers(Center);
|
|||
|
MapRef?.Refresh();
|
|||
|
Console.WriteLine("Initial refresh");
|
|||
|
|
|||
|
Center = [40.68, 74.04];
|
|||
|
|
|||
|
Zoom = 11;
|
|||
|
Console.WriteLine("Map initialized @ " + Center[0] + " " + Center[1]);
|
|||
|
|
|||
|
InitializeMapMarkers(Center);
|
|||
|
MapRef?.Refresh();
|
|||
|
Console.WriteLine("IsVisible: " + (MapRef == null ? "false" : "true"));
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public void OnMarkerClick(MapMarkerClickEventArgs args)
|
|||
|
{
|
|||
|
|
|||
|
var dataItem = args.DataItem as MarkerModel;
|
|||
|
CurrentSelection = dataItem.Title;
|
|||
|
CurrentBlurb = dataItem.Blurb;
|
|||
|
ToggleModal();
|
|||
|
Console.WriteLine(dataItem.Title);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public List<MarkerModel> MapMarkers { get; set; } = new List<MarkerModel>()
|
|||
|
{
|
|||
|
new MarkerModel()
|
|||
|
{
|
|||
|
Title = ""
|
|||
|
}
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void InitializeMapMarkers(double[] coords)
|
|||
|
{
|
|||
|
// Server call to load map markers into a list of tuples
|
|||
|
List<(double[], string)> localMarkers = MapDriver.InitializeMarkers(coords);
|
|||
|
foreach (var current in localMarkers)
|
|||
|
{
|
|||
|
MapMarkers.Add(new MarkerModel()
|
|||
|
{
|
|||
|
LatLng = current.Item1,
|
|||
|
Title = current.Item2,
|
|||
|
Blurb = string.Format("This is {0}'s blurb. This will be replaced when a lookup is created.", current.Item2)
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public void SubmitLocation()
|
|||
|
{
|
|||
|
string str = String.Format(("Shop Name: {0} \n CSZ: {1}"), ShopName, CSZ);
|
|||
|
Console.WriteLine(str);
|
|||
|
|
|||
|
// Search based on the input provided in the ShopName and CSZ fields
|
|||
|
// TODO
|
|||
|
|
|||
|
// Call Geocoding API to get coordinates for making the map jump
|
|||
|
// TODO
|
|||
|
var jsonString = "{\"latitude\": \"42.295920\",\"longitude\":\"-83.444780\"}";
|
|||
|
LocationDetails? json = JsonConvert.DeserializeObject<LocationDetails>(jsonString);
|
|||
|
|
|||
|
// Move the map
|
|||
|
if (json != null)
|
|||
|
{
|
|||
|
Center = [json.latitude, json.longitude];
|
|||
|
Zoom = 13;
|
|||
|
}
|
|||
|
|
|||
|
InitializeMapMarkers(Center);
|
|||
|
if (MapRef != null)
|
|||
|
MapRef.Refresh();
|
|||
|
}
|
|||
|
|
|||
|
public class MarkerModel
|
|||
|
{
|
|||
|
public double[] LatLng { get; set; } = [42.4649, -83.3684];
|
|||
|
public string Title { get; set; } = "";
|
|||
|
public string Blurb { get; set; } = "";
|
|||
|
}
|
|||
|
|
|||
|
private class LocationDetails
|
|||
|
{
|
|||
|
public string ip { get; set; } = "";
|
|||
|
public string network { get; set; } = "";
|
|||
|
public string version { get; set; } = "";
|
|||
|
public string city { get; set; } = "";
|
|||
|
public string region { get; set; } = "";
|
|||
|
public string region_code { get; set; } = "";
|
|||
|
public string country { get; set; } = "";
|
|||
|
public string country_code { get; set; } = "";
|
|||
|
public string country_code_iso3 { get; set; } = "";
|
|||
|
public string country_capital { get; set; } = "";
|
|||
|
public string country_tld { get; set; } = "";
|
|||
|
public string continent_code { get; set; } = "";
|
|||
|
public bool in_eu { get; set; } = false;
|
|||
|
public string postal { get; set; } = "";
|
|||
|
public double latitude { get; set; } = -1;
|
|||
|
public double longitude { get; set; } = -1;
|
|||
|
public string timezone { get; set; } = "";
|
|||
|
public string utc_offset { get; set; } = "";
|
|||
|
public string country_calling_code { get; set; } = "";
|
|||
|
public string currency { get; set; } = "";
|
|||
|
public string currency_name { get; set; } = "";
|
|||
|
public string languages { get; set; } = "";
|
|||
|
public string country_area { get; set; } = "";
|
|||
|
public string country_population { get; set; } = "";
|
|||
|
public string asn { get; set; } = "";
|
|||
|
public string org { get; set; } = "";
|
|||
|
}
|
|||
|
|
|||
|
public TelerikPopover? Popover { get; set; }
|
|||
|
public string CurrentSelection { get; set; } = "123412341234onetwothreefour";
|
|||
|
public string CurrentBlurb { get; set; } = "This is a blurb for a shop. I believe it is rather dastardly.";
|
|||
|
public bool isVisible = false;
|
|||
|
|
|||
|
public void ToggleModal()
|
|||
|
{
|
|||
|
Console.WriteLine("TOGGLING");
|
|||
|
//await Console.Out.WriteLineAsync("IWNAJNQADJK" + isVisible);
|
|||
|
if (isVisible)
|
|||
|
isVisible = false;
|
|||
|
else
|
|||
|
isVisible = true;
|
|||
|
//await Task.Delay(1);
|
|||
|
|
|||
|
MapRef?.Refresh();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|