#233 displaying poet birth places on the map
This commit is contained in:
parent
031cf3eaa5
commit
ff8483eb83
@ -154,7 +154,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="4">
|
||||
<a role="button" onclick="savePoetMeta(@poet.Id, '@poet.Nickname')" class="actionlink">ذخیره</a>
|
||||
<a role="button" onclick="savePoetMeta(@poet.Id, '@poet.Nickname')" class="actionlink">ذخیرهٔ @poet.Nickname</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -44,42 +44,28 @@
|
||||
|
||||
L.tileLayer.provider('Stamen.Watercolor').addTo(map);
|
||||
|
||||
var oms = new OverlappingMarkerSpiderfier(map, { keepSpiderfied : false});
|
||||
|
||||
var oms = new OverlappingMarkerSpiderfier(map, { keepSpiderfied: false });
|
||||
|
||||
var hafezIcon = L.icon({
|
||||
iconUrl: 'https://ganjgah.ir/api/ganjoor/poet/image/hafez.gif',
|
||||
iconSize: [82, 100],
|
||||
iconAnchor: [82, 100],
|
||||
popupAnchor: [0, -28]
|
||||
});
|
||||
@{
|
||||
foreach (var poet in Model.PoetsWithBirthPlaces)
|
||||
{
|
||||
var url = poet.FullUrl.Substring(1);
|
||||
<text>
|
||||
var @(url)Icon = L.icon({
|
||||
iconUrl: '@($"{GanjooRazor.APIRoot.InternetUrl}{poet.ImageUrl}")',
|
||||
iconSize: [82, 100],
|
||||
iconAnchor: [82, 100],
|
||||
popupAnchor: [0, -28]
|
||||
});
|
||||
|
||||
var hafezMarker = L.marker([29.5926, 52.5836], { icon: hafezIcon });
|
||||
var @(url)Marker = L.marker([@poet.BirthPlaceLatitude, @poet.BirthPlaceLongitude], { icon: @(url)Icon });
|
||||
|
||||
hafezMarker.addTo(map);
|
||||
oms.addMarker(hafezMarker);
|
||||
@(url)Marker.addTo(map);
|
||||
oms.addMarker(@(url)Marker);
|
||||
</text>
|
||||
|
||||
var saadiIcon = L.icon({
|
||||
iconUrl: 'https://ganjgah.ir/api/ganjoor/poet/image/saadi.gif',
|
||||
iconSize: [82, 100],
|
||||
iconAnchor: [82, 100],
|
||||
popupAnchor: [0, -28]
|
||||
});
|
||||
|
||||
var saadiMarker = L.marker([29.5926, 52.5836], { icon: saadiIcon });
|
||||
saadiMarker.addTo(map);
|
||||
oms.addMarker(saadiMarker);
|
||||
|
||||
var ferdousiIcon = L.icon({
|
||||
iconUrl: 'https://ganjgah.ir/api/ganjoor/poet/image/ferdousi.gif',
|
||||
iconSize: [82, 100],
|
||||
iconAnchor: [82, 100],
|
||||
popupAnchor: [0, -28]
|
||||
});
|
||||
|
||||
var ferdousiMarker = L.marker([36.2605, 59.6168], { icon: ferdousiIcon });
|
||||
ferdousiMarker.addTo(map);
|
||||
oms.addMarker(ferdousiMarker);
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@ -1,16 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
|
||||
namespace GanjooRazor.Pages
|
||||
{
|
||||
public class MapModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
/// <summary>
|
||||
/// Poets
|
||||
/// </summary>
|
||||
public List<GanjoorPoetViewModel> PoetsWithBirthPlaces { get; set; }
|
||||
|
||||
private async Task preparePoets()
|
||||
{
|
||||
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets");
|
||||
response.EnsureSuccessStatusCode();
|
||||
var poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorPoetViewModel>>();
|
||||
|
||||
PoetsWithBirthPlaces = poets.Where(p => !string.IsNullOrEmpty(p.BirthPlace)).ToList();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
await preparePoets();
|
||||
return Page();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HttpClient instance
|
||||
/// </summary>
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
/// <summary>
|
||||
/// memory cache
|
||||
/// </summary>
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
/// <summary>
|
||||
/// configration file reader (appsettings.json)
|
||||
/// </summary>
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public MapModel(IConfiguration configuration,
|
||||
HttpClient httpClient,
|
||||
IMemoryCache memoryCache
|
||||
)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_httpClient = httpClient;
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user