Approximate-location map on aggregated listings (Divar coords)
CI/CD / CI · dotnet build (push) Successful in 1m59s
CI/CD / Deploy · hamkadr (push) Successful in 1m49s

We captured Divar's privacy-fuzzed coords on RawListing but discarded them for
the listings that need them: unnamed-facility shifts/jobs dropped them (to avoid
piling on the shared placeholder) and applicants had no coordinate field at all.

- Add Lat/Lng to Shift, JobOpening, TalentListing (migration ListingApproxCoords).
- Publish stores the source ad's approx coords on each aggregated listing.
- Detail pages render the map from the listing's own coords (fallback: facility),
  and aggregated coords show as a shaded «محدودهٔ تقریبی» circle (not a precise
  pin) via _NeshanMap data-approx, with a disclaimer. Applicants get a map card
  (they had none) + the page now loads the Neshan key.

Only Divar provides coords; the map needs NeshanMapKey set in admin settings.
Existing rows get coords once reprocessed (RawListing already has them).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-20 15:10:05 +03:30
parent 704b68be16
commit 4ab6ce29c9
12 changed files with 1820 additions and 15 deletions
+13 -5
View File
@@ -4,6 +4,10 @@
var j = Model.Job!;
var f = j.Facility!;
var jobContacts = (j.Contacts ?? new List<JobsMedical.Web.Models.ContactMethod>()).ToList();
// Map: listing's own approx coords (aggregated) then facility's; aggregated = approximate area.
var mapLat = j.Lat ?? f.Lat;
var mapLng = j.Lng ?? f.Lng;
var mapApprox = j.Source == JobsMedical.Web.Models.ShiftSource.Aggregated;
ViewData["Title"] = j.Title;
ViewData["Description"] = $"{j.Title} در {f.Name}، {f.City?.Name}. موقعیت استخدامی برای {j.Role?.Name}.";
// Don't let Google index filled/expired openings (avoids dead "Job for jobs" results).
@@ -150,15 +154,15 @@
}
</div>
@if (j.Facility?.Lat is not null && j.Facility?.Lng is not null)
@if (mapLat is not null && mapLng is not null)
{
var latS = j.Facility.Lat.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
var lngS = j.Facility.Lng.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
var latS = mapLat.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
var lngS = mapLng.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
<div class="card card-pad" style="margin-top:16px;">
<h3 style="margin-top:0;">موقعیت مکانی</h3>
@if (!string.IsNullOrEmpty(Model.MapKey))
{
<div id="facmap" data-lat="@latS" data-lng="@lngS" style="height:200px; border-radius:10px; overflow:hidden; border:1px solid var(--line);"></div>
<div id="facmap" data-lat="@latS" data-lng="@lngS" data-approx="@(mapApprox ? "true" : "false")" style="height:200px; border-radius:10px; overflow:hidden; border:1px solid var(--line);"></div>
}
else
{
@@ -166,6 +170,10 @@
🗺️<br /><small class="muted" dir="ltr">@latS، @lngS</small>
</div>
}
@if (mapApprox)
{
<p class="muted" style="font-size:12px; margin:8px 0 0;">📍 محدودهٔ تقریبی (برگرفته از آگهی منبع)؛ موقعیت دقیق نیست.</p>
}
<a class="btn btn-outline btn-block" style="margin-top:8px;" target="_blank" rel="noopener"
href="https://neshan.org/maps/@(latS),@(lngS),16z">مسیریابی در نشان</a>
</div>
@@ -183,7 +191,7 @@
</form>
</div>
@if (!string.IsNullOrEmpty(Model.MapKey) && Model.Job?.Facility?.Lat is not null)
@if (!string.IsNullOrEmpty(Model.MapKey) && mapLat is not null)
{
<partial name="_NeshanMap" model="Model.MapKey" />
}
@@ -12,10 +12,17 @@
if (!el || !window.L) return;
var lat = parseFloat(el.dataset.lat), lng = parseFloat(el.dataset.lng);
if (isNaN(lat) || isNaN(lng)) return;
// Approximate (aggregated) listings show a shaded AREA circle, not a precise pin.
var approx = el.dataset.approx === 'true';
var map = new L.Map('facmap', {
key: '@Model', maptype: 'neshan', poi: true, traffic: false,
center: [lat, lng], zoom: 15
key: '@Model', maptype: 'neshan', poi: !approx, traffic: false,
center: [lat, lng], zoom: approx ? 14 : 15
});
L.marker([lat, lng]).addTo(map);
if (approx) {
var radius = parseInt(el.dataset.radius || '700', 10);
L.circle([lat, lng], { radius: radius, color: '#e07b39', weight: 1, fillColor: '#e07b39', fillOpacity: 0.18 }).addTo(map);
} else {
L.marker([lat, lng]).addTo(map);
}
})();
</script>
@@ -4,6 +4,11 @@
var s = Model.Shift!;
var f = s.Facility!;
var shiftContacts = (s.Contacts ?? new List<JobsMedical.Web.Models.ContactMethod>()).ToList();
// Map: prefer the listing's own approx coords (aggregated ads) then the facility's. Aggregated =
// approximate → shown as an area circle with a disclaimer, never a precise pin.
var mapLat = s.Lat ?? f.Lat;
var mapLng = s.Lng ?? f.Lng;
var mapApprox = s.Source == JobsMedical.Web.Models.ShiftSource.Aggregated;
ViewData["Title"] = $"شیفت {s.SpecialtyRequired} - {f.Name}";
ViewData["Description"] = $"شیفت {s.SpecialtyRequired} در {f.Name}، {f.City?.Name}، تاریخ {JalaliDate.ToLongDate(s.Date)} از ساعت {JalaliDate.Time(s.StartTime)}.";
// Past/filled shifts shouldn't stay in the index as dead pages.
@@ -166,13 +171,13 @@
<div class="card card-pad" style="margin-top:16px;">
<h3 style="margin-top:0;">موقعیت مکانی</h3>
@if (f.Lat is not null && f.Lng is not null)
@if (mapLat is not null && mapLng is not null)
{
var latS = f.Lat.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
var lngS = f.Lng.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
var latS = mapLat.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
var lngS = mapLng.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
@if (!string.IsNullOrEmpty(Model.MapKey))
{
<div id="facmap" data-lat="@latS" data-lng="@lngS" style="height:200px; border-radius:10px; overflow:hidden; border:1px solid var(--line);"></div>
<div id="facmap" data-lat="@latS" data-lng="@lngS" data-approx="@(mapApprox ? "true" : "false")" style="height:200px; border-radius:10px; overflow:hidden; border:1px solid var(--line);"></div>
}
else
{
@@ -180,12 +185,16 @@
🗺️<br /><small class="muted" dir="ltr">@latS، @lngS</small>
</div>
}
@if (mapApprox)
{
<p class="muted" style="font-size:12px; margin:8px 0 0;">📍 محدودهٔ تقریبی (برگرفته از آگهی منبع)؛ موقعیت دقیق نیست.</p>
}
<a class="btn btn-outline btn-block" style="margin-top:8px;" target="_blank" rel="noopener"
href="https://neshan.org/maps/@(latS),@(lngS),16z">مسیریابی در نشان</a>
}
else
{
<p class="muted" style="margin:0;">مختصات این مرکز هنوز ثبت نشده است.</p>
<p class="muted" style="margin:0;">مختصات این آگهی ثبت نشده است.</p>
}
</div>
</aside>
@@ -201,7 +210,7 @@
</form>
</div>
@if (!string.IsNullOrEmpty(Model.MapKey) && Model.Shift?.Facility?.Lat is not null)
@if (!string.IsNullOrEmpty(Model.MapKey) && mapLat is not null)
{
<partial name="_NeshanMap" model="Model.MapKey" />
}
@@ -61,6 +61,31 @@
data-contact-type="talent" data-contact-id="@t.Id">📞 مشاهده راه‌های ارتباطی</button>
<p class="muted" style="font-size:12px; margin:10px 0 0;">با کلیک، شماره تماس و راه‌های ارتباطی نمایش داده می‌شود.</p>
</div>
@if (t.Lat is not null && t.Lng is not null)
{
var latS = t.Lat.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
var lngS = t.Lng.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
<div class="card card-pad" style="margin-top:16px;">
<h3 style="margin-top:0;">موقعیت تقریبی</h3>
@if (!string.IsNullOrEmpty(Model.MapKey))
{
<div id="facmap" data-lat="@latS" data-lng="@lngS" data-approx="true" style="height:200px; border-radius:10px; overflow:hidden; border:1px solid var(--line);"></div>
}
else
{
<div style="background:var(--primary-soft); border-radius:10px; height:140px; display:grid; place-items:center; color:var(--primary-dark); text-align:center; padding:10px;">
🗺️<br /><small class="muted" dir="ltr">@latS، @lngS</small>
</div>
}
<p class="muted" style="font-size:12px; margin:8px 0 0;">📍 محدودهٔ تقریبیِ فعالیت (برگرفته از آگهی منبع)؛ موقعیت دقیق نیست.</p>
</div>
}
</aside>
</div>
</div>
@if (!string.IsNullOrEmpty(Model.MapKey) && t.Lat is not null)
{
<partial name="_NeshanMap" model="Model.MapKey" />
}
@@ -9,9 +9,16 @@ namespace JobsMedical.Web.Pages.Talent;
public class DetailsModel : PageModel
{
private readonly AppDbContext _db;
public DetailsModel(AppDbContext db) => _db = db;
private readonly JobsMedical.Web.Services.Scraping.SettingsService _settings;
public DetailsModel(AppDbContext db, JobsMedical.Web.Services.Scraping.SettingsService settings)
{
_db = db;
_settings = settings;
}
public TalentListing? Item { get; private set; }
public string? MapKey { get; private set; }
public async Task<IActionResult> OnGetAsync(int id)
{
@@ -22,6 +29,7 @@ public class DetailsModel : PageModel
.Include(t => t.Contacts)
.FirstOrDefaultAsync(t => t.Id == id);
if (Item is null) return NotFound();
MapKey = (await _settings.GetAsync()).NeshanMapKey;
return Page();
}
}