Facility location: click-to-pick Neshan map + 'my current location'
- RegisterFacility: '📍 موقعیت فعلی من' (browser geolocation, always available) + Neshan Leaflet map (click/drag marker → fills lat/lng) when a Neshan web key is set; graceful fallback to manual coords without a key - AppSetting.NeshanMapKey configured in /Admin/Settings (Google Maps is blocked in Iran); migration - Verified: location button + inputs render always; map + SDK render once the key is saved Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -57,11 +57,25 @@
|
||||
<div style="flex:1;"><label>تلفن</label><input type="tel" name="Phone" value="@Model.Phone" dir="ltr" /></div>
|
||||
<div style="flex:1;"><label>شناسه بله</label><input type="text" name="BaleId" value="@Model.BaleId" dir="ltr" /></div>
|
||||
</div>
|
||||
<div class="filter-group" style="display:flex; gap:8px;">
|
||||
<div style="flex:1;"><label>عرض جغرافیایی (اختیاری)</label><input type="number" step="any" name="Lat" value="@Model.Lat" dir="ltr" /></div>
|
||||
<div style="flex:1;"><label>طول جغرافیایی (اختیاری)</label><input type="number" step="any" name="Lng" value="@Model.Lng" dir="ltr" /></div>
|
||||
<div class="filter-group">
|
||||
<label>موقعیت مکانی (برای فیلتر «نزدیک من»)</label>
|
||||
<div style="display:flex; gap:8px; margin-bottom:8px;">
|
||||
<button type="button" id="myLocBtn" class="btn btn-outline" style="flex:1;">📍 موقعیت فعلی من</button>
|
||||
</div>
|
||||
@if (!string.IsNullOrEmpty(Model.MapKey))
|
||||
{
|
||||
<div id="facmap" style="height:280px; border-radius:12px; overflow:hidden; border:1px solid var(--line);"></div>
|
||||
<p class="muted" style="font-size:12px; margin:6px 0 0;">روی نقشه بزن یا نشانگر را بکش تا موقعیت مرکز مشخص شود.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="muted" style="font-size:12px; margin:0;">نقشه پیکربندی نشده؛ از دکمه «موقعیت فعلی من» استفاده کن یا مختصات را دستی وارد کن.</p>
|
||||
}
|
||||
<div style="display:flex; gap:8px; margin-top:8px;">
|
||||
<div style="flex:1;"><label style="font-size:12px;">عرض (Lat)</label><input type="number" step="any" id="latInput" name="Lat" value="@Model.Lat" dir="ltr" /></div>
|
||||
<div style="flex:1;"><label style="font-size:12px;">طول (Lng)</label><input type="number" step="any" id="lngInput" name="Lng" value="@Model.Lng" dir="ltr" /></div>
|
||||
</div>
|
||||
</div>
|
||||
<p class="muted" style="font-size:12px;">مختصات برای نمایش در فیلتر «نزدیک من» استفاده میشود.</p>
|
||||
<div class="filter-group">
|
||||
<label>سؤال امنیتی: حاصل <strong>@Model.CaptchaQuestion</strong> چند میشود؟</label>
|
||||
<input type="text" name="CaptchaAnswer" dir="ltr" inputmode="numeric" autocomplete="off" placeholder="پاسخ" />
|
||||
@@ -70,3 +84,51 @@
|
||||
<button type="submit" class="btn btn-accent btn-block btn-lg">ثبت مرکز و ورود به پنل</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@if (!string.IsNullOrEmpty(Model.MapKey))
|
||||
{
|
||||
<link rel="stylesheet" href="https://static.neshan.org/sdk/leaflet/1.4.0/neshan-sdk/v1.0.8/index.css" />
|
||||
<script src="https://static.neshan.org/sdk/leaflet/1.4.0/neshan-sdk/v1.0.8/index.js"></script>
|
||||
}
|
||||
<script>
|
||||
(function () {
|
||||
var latEl = document.getElementById('latInput');
|
||||
var lngEl = document.getElementById('lngInput');
|
||||
var marker = null, map = null;
|
||||
|
||||
function setCoords(lat, lng) {
|
||||
latEl.value = (+lat).toFixed(6);
|
||||
lngEl.value = (+lng).toFixed(6);
|
||||
}
|
||||
|
||||
var mapKey = '@Model.MapKey';
|
||||
if (mapKey && window.L && document.getElementById('facmap')) {
|
||||
var startLat = parseFloat(latEl.value) || 35.6892; // Tehran default
|
||||
var startLng = parseFloat(lngEl.value) || 51.3890;
|
||||
map = new L.Map('facmap', {
|
||||
key: mapKey, maptype: 'neshan', poi: true, traffic: false,
|
||||
center: [startLat, startLng], zoom: 12
|
||||
});
|
||||
marker = L.marker([startLat, startLng], { draggable: true }).addTo(map);
|
||||
if (!latEl.value) { /* no initial pin until user acts */ }
|
||||
marker.on('dragend', function (e) { var p = e.target.getLatLng(); setCoords(p.lat, p.lng); });
|
||||
map.on('click', function (e) { marker.setLatLng(e.latlng); setCoords(e.latlng.lat, e.latlng.lng); });
|
||||
}
|
||||
|
||||
var btn = document.getElementById('myLocBtn');
|
||||
if (btn) btn.addEventListener('click', function () {
|
||||
if (!navigator.geolocation) { alert('مرورگر شما از موقعیتیابی پشتیبانی نمیکند.'); return; }
|
||||
btn.textContent = 'در حال یافتن موقعیت...'; btn.disabled = true;
|
||||
navigator.geolocation.getCurrentPosition(function (pos) {
|
||||
var lat = pos.coords.latitude, lng = pos.coords.longitude;
|
||||
setCoords(lat, lng);
|
||||
if (map && marker) { marker.setLatLng([lat, lng]); map.setView([lat, lng], 15); }
|
||||
btn.textContent = '📍 موقعیت ثبت شد'; btn.disabled = false;
|
||||
}, function () {
|
||||
alert('دسترسی به موقعیت داده نشد.'); btn.textContent = '📍 موقعیت فعلی من'; btn.disabled = false;
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -16,15 +16,19 @@ public class RegisterFacilityModel : PageModel
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
private readonly CaptchaService _captcha;
|
||||
public RegisterFacilityModel(AppDbContext db, CaptchaService captcha)
|
||||
private readonly JobsMedical.Web.Services.Scraping.SettingsService _settings;
|
||||
public RegisterFacilityModel(AppDbContext db, CaptchaService captcha,
|
||||
JobsMedical.Web.Services.Scraping.SettingsService settings)
|
||||
{
|
||||
_db = db;
|
||||
_captcha = captcha;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public List<City> Cities { get; private set; } = new();
|
||||
public List<District> Districts { get; private set; } = new();
|
||||
public string CaptchaQuestion { get; private set; } = "";
|
||||
public string? MapKey { get; private set; }
|
||||
[BindProperty] public string? CaptchaToken { get; set; }
|
||||
[BindProperty] public string? CaptchaAnswer { get; set; }
|
||||
|
||||
@@ -93,6 +97,7 @@ public class RegisterFacilityModel : PageModel
|
||||
{
|
||||
Cities = await _db.Cities.OrderByDescending(c => c.IsActive).ThenBy(c => c.Name).ToListAsync();
|
||||
Districts = await _db.Districts.Where(d => d.IsActive).OrderBy(d => d.Name).ToListAsync();
|
||||
MapKey = (await _settings.GetAsync()).NeshanMapKey;
|
||||
}
|
||||
|
||||
private void NewCaptcha()
|
||||
|
||||
Reference in New Issue
Block a user