jQuery(document).ready(function($) { // آرایه رنگهای متمایز var colors = [ '#FF0000', '#00FF00', '#0000FF', '#FF00FF', '#FFFF00', '#00FFFF', '#FFA500', '#800080', '#008000', '#FFC0CB' ]; // نمایش پیام function showMessage(message, type) { var messageClass = 'notice-' + type; var $notice = $('
'); $('.wrap').prepend($notice); setTimeout(function() { $notice.fadeOut().remove(); }, 5000); } // بررسی وجود Leaflet if (typeof L === 'undefined') { console.error('Leaflet is not loaded.'); $('#map').html('خطا: نقشه لود نشد. لطفاً اتصال اینترنت را بررسی کنید.
'); return; } // ایجاد نقشه var map = L.map('map').setView([35.6892, 51.3890], 11); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap' }).addTo(map); var drawnItems = new L.FeatureGroup(); map.addLayer(drawnItems); var drawControl = new L.Control.Draw({ edit: { featureGroup: drawnItems }, draw: { polygon: true, polyline: false, rectangle: false, circle: false, marker: false, circlemarker: false } }); map.addControl(drawControl); var currentZoneId = null; var currentLayer = null; map.on('draw:created', function(e) { if (currentLayer) { drawnItems.removeLayer(currentLayer); } currentLayer = e.layer; drawnItems.addLayer(currentLayer); }); map.on('draw:edited', function(e) { if (currentLayer) { // بهروزرسانی مختصات هنگام ویرایش console.log('Polygon edited:', currentLayer.toGeoJSON()); } }); // دریافت محدودهها function loadZones() { $.ajax({ url: alaOrData.ajax_url, method: 'POST', data: { action: 'ala_or_get_zones', nonce: alaOrData.nonce }, success: function(response) { console.log('Zones Response:', response); if (response.success && response.data) { $('#zone-list').empty(); response.data.forEach(function(zone, index) { if (zone.coordinates && Array.isArray(zone.coordinates[0])) { var leafletCoords = zone.coordinates[0].map(coord => [coord.lat, coord.lng]); var zoneColor = colors[index % colors.length]; var polygon = L.polygon(leafletCoords, { color: zoneColor }).addTo(map); polygon.bindPopup('منطقه: ' + (zone.zone_name || 'بدون نام') + '