// في ملف: constant/country_polygons.dart import 'package:maplibre_gl/maplibre_gl.dart'; class CountryPolygons { // ========================================================== // 1. الأردن: تغطية الممر الحضري الرئيسي (من إربد شمالاً حتى العقبة جنوباً) // حوالي 12 نقطة // ========================================================== static final List jordanBoundary = [ // شمال إربد (قرب الحدود) const LatLng(32.65, 35.80), // شمال شرق المفرق const LatLng(32.35, 37.00), // شرق الزرقاء / الأزرق const LatLng(31.85, 36.80), // جنوب شرق (نهاية الزحف السكاني) const LatLng(31.00, 36.50), // جنوب / معان const LatLng(30.30, 35.75), // العقبة const LatLng(29.50, 35.00), // البحر الأحمر / الحدود الغربية const LatLng(29.50, 34.85), // غرب وادي عربة const LatLng(30.80, 35.25), // منطقة البحر الميت / السلط const LatLng(32.00, 35.50), // العودة عبر وادي الأردن إلى الشمال const LatLng(32.45, 35.60), // العودة لنقطة إربد const LatLng(32.65, 35.80), ]; // ========================================================== // 2. سوريا: تغطية الممر الغربي والساحلي (درعا، دمشق، حمص، حماة، حلب، الساحل) // حوالي 14 نقطة // ========================================================== static final List syriaBoundary = [ // درعا / الجنوب const LatLng(32.65, 35.95), // شرق السويداء (حدود المنطقة المأهولة) const LatLng(32.85, 37.10), // أطراف دمشق الشرقية const LatLng(33.50, 36.65), // تدمر (أقصى امتداد شرقي للمضلع) const LatLng(34.50, 38.30), // الرقة (شمال شرق) const LatLng(35.95, 38.80), // حلب (الشمال) const LatLng(36.45, 37.15), // الحدود الشمالية الغربية (إدلب / تركيا) const LatLng(36.50, 36.50), // اللاذقية (الساحل) const LatLng(35.50, 35.75), // طرطوس (الساحل) const LatLng(34.80, 35.85), // حمص const LatLng(34.70, 36.70), // حماة const LatLng(35.10, 36.70), // العودة إلى منطقة دمشق const LatLng(33.40, 36.30), // العودة إلى درعا const LatLng(32.65, 35.95), ]; // ========================================================== // 3. مصر: تغطية القاهرة الكبرى، الدلتا، والإسكندرية والإسماعيلية // حوالي 10 نقاط // ========================================================== static final List egyptBoundary = [ // جنوب الفيوم (أقصى امتداد جنوبي غربي) const LatLng(29.20, 30.60), // جنوب القاهرة (العياط) const LatLng(29.80, 31.30), // شرق السويس const LatLng(29.95, 32.70), // الإسماعيلية / القناة const LatLng(30.60, 32.25), // بورسعيد / أطراف الدلتا الشمالية الشرقية const LatLng(31.30, 31.80), // دمياط / ساحل الدلتا const LatLng(31.50, 31.25), // الإسكندرية (أقصى الشمال الغربي) const LatLng(31.20, 29.80), // غرب الدلتا const LatLng(30.50, 30.20), // العودة لنقطة البداية const LatLng(29.20, 30.60), ]; // دالة تُرجع رابط API بناءً على اسم الدولة // static String getRoutingApiUrl(String countryName) { // switch (countryName) { // case 'Jordan': // return 'https://routec.intaleq.xyz/route-jo'; // case 'Syria': // return 'https://routec.intaleq.xyz/route'; // case 'Egypt': // return 'https://routec.intaleq.xyz/route-eg'; // default: // // الافتراضي في حالة لم يقع الموقع ضمن أي من المضلعات // return 'https://routec.intaleq.xyz/route'; // } // } /// دالة تحدد اسم الدولة (باللغة الإنجليزية للـ API) بناءً على الإحداثيات static String getCountryName(LatLng? point) { if (point == null) return "jordan"; if (_isPointInPolygon(point, jordanBoundary)) return "jordan"; if (_isPointInPolygon(point, syriaBoundary)) return "syria"; if (_isPointInPolygon(point, egyptBoundary)) return "egypt"; return "jordan"; // الافتراضي } /// خوارزمية Ray Casting للتحقق من وقوع نقطة داخل مضلع static bool _isPointInPolygon(LatLng p, List polygon) { bool isInside = false; int j = polygon.length - 1; for (int i = 0; i < polygon.length; i++) { if (((polygon[i].latitude > p.latitude) != (polygon[j].latitude > p.latitude)) && (p.longitude < (polygon[j].longitude - polygon[i].longitude) * (p.latitude - polygon[i].latitude) / (polygon[j].latitude - polygon[i].latitude) + polygon[i].longitude)) { isInside = !isInside; } j = i; } return isInside; } }