-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatasigma.html
More file actions
1276 lines (1127 loc) · 39.7 KB
/
datasigma.html
File metadata and controls
1276 lines (1127 loc) · 39.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8" />
<title>نظام استخراج بيانات OpenStreetMap - المغرب</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="أداة متقدمة لاستخراج وتحليل بيانات OSM للمملكة المغربية" />
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: {
50: '#eff6ff',
100: '#dbeafe',
500: '#3b82f6',
600: '#2563eb',
700: '#1d4ed8',
},
secondary: {
500: '#10b981',
600: '#059669',
}
},
fontFamily: {
'cairo': ['Cairo', 'sans-serif'],
}
}
}
}
</script>
<!-- OpenLayers -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v10.7.0/ol.css" />
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
<style>
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;500;600;700;800&display=swap');
:root {
--color-primary: #3b82f6;
--color-primary-dark: #1d4ed8;
--color-secondary: #10b981;
}
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: 'Cairo', sans-serif;
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}
#app {
height: 100vh;
display: flex;
flex-direction: row-reverse;
overflow: hidden;
}
/* الشريط الجانبي المحسّن */
.sidebar {
width: 420px;
min-width: 420px;
background: linear-gradient(to bottom, #1e293b 0%, #0f172a 100%);
border-right: 1px solid rgba(255,255,255,0.1);
box-shadow: -5px 0 25px rgba(0,0,0,0.2);
z-index: 100;
display: flex;
flex-direction: column;
}
.sidebar-header {
background: rgba(15, 23, 42, 0.95);
border-bottom: 1px solid rgba(255,255,255,0.05);
padding: 1.5rem;
}
.sidebar-content {
flex: 1;
overflow-y: auto;
padding: 1.5rem;
}
.sidebar-footer {
background: rgba(15, 23, 42, 0.95);
border-top: 1px solid rgba(255,255,255,0.05);
padding: 1.5rem;
}
/* الخريطة */
#map {
flex: 1;
position: relative;
}
/* عناصر التحكم في الخريطة */
.map-controls {
position: absolute;
top: 1rem;
left: 1rem;
z-index: 10;
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.control-btn {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem 1.25rem;
background: white;
border: 1px solid #e2e8f0;
border-radius: 12px;
font-family: 'Cairo', sans-serif;
font-weight: 600;
font-size: 0.875rem;
color: #1e293b;
cursor: pointer;
transition: all 0.2s ease;
box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.control-btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}
.control-btn.active {
background: var(--color-primary);
color: white;
border-color: var(--color-primary);
}
.control-btn.danger {
background: #ef4444;
color: white;
border-color: #dc2626;
}
/* بطاقات المعلومات */
.info-card {
background: rgba(30, 41, 59, 0.7);
backdrop-filter: blur(10px);
border-radius: 12px;
border: 1px solid rgba(255,255,255,0.1);
padding: 1.25rem;
margin-bottom: 1.25rem;
}
.info-card h3 {
margin: 0 0 0.75rem 0;
font-size: 1rem;
font-weight: 700;
color: #60a5fa;
display: flex;
align-items: center;
gap: 0.5rem;
}
/* شريط التقدم */
.progress-bar {
height: 4px;
background: rgba(255,255,255,0.1);
border-radius: 2px;
overflow: hidden;
margin: 1rem 0;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #3b82f6, #60a5fa);
width: 0%;
transition: width 0.3s ease;
border-radius: 2px;
}
/* إشعارات */
.notification {
position: fixed;
bottom: 2rem;
left: 50%;
transform: translateX(-50%) translateY(100px);
background: white;
padding: 1rem 1.5rem;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0,0,0,0.15);
display: flex;
align-items: center;
gap: 0.75rem;
z-index: 1000;
opacity: 0;
transition: all 0.3s ease;
}
.notification.show {
transform: translateX(-50%) translateY(0);
opacity: 1;
}
.notification.success {
border-right: 4px solid #10b981;
}
.notification.error {
border-right: 4px solid #ef4444;
}
/* Popup محسن */
.ol-popup {
position: absolute;
background-color: white;
box-shadow: 0 20px 50px -12px rgba(0,0,0,0.25);
padding: 0;
border-radius: 16px;
border: 1px solid #e2e8f0;
min-width: 280px;
max-width: 350px;
font-family: 'Cairo', sans-serif;
}
.popup-header {
padding: 1rem;
background: #f8fafc;
border-bottom: 1px solid #e2e8f0;
border-radius: 16px 16px 0 0;
font-weight: 700;
color: #1e293b;
}
.popup-content {
padding: 1rem;
max-height: 300px;
overflow-y: auto;
}
.property-row {
display: flex;
justify-content: space-between;
padding: 0.5rem 0;
border-bottom: 1px solid #f1f5f9;
}
.property-row:last-child {
border-bottom: none;
}
/* زر الإجراء الرئيسي */
.action-btn {
width: 100%;
padding: 1rem;
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
color: white;
border: none;
border-radius: 12px;
font-family: 'Cairo', sans-serif;
font-weight: 700;
font-size: 0.95rem;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
gap: 0.75rem;
}
.action-btn:hover:not(:disabled) {
transform: translateY(-2px);
box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}
.action-btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.action-btn.success {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}
/* قائمة الطبقات المنسدلة */
.basemap-dropdown {
position: relative;
}
.basemap-menu {
position: absolute;
top: calc(100% + 8px);
right: 0;
background: white;
border-radius: 12px;
box-shadow: 0 10px 25px rgba(0,0,0,0.15);
min-width: 200px;
overflow: hidden;
z-index: 1000;
border: 1px solid #e2e8f0;
}
.basemap-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.75rem 1rem;
cursor: pointer;
transition: background 0.2s;
border-bottom: 1px solid #f1f5f9;
}
.basemap-item:hover {
background: #f8fafc;
}
.basemap-item.active {
background: #eff6ff;
color: #2563eb;
}
/* مؤشر التحميل */
.loader {
width: 50px;
height: 50px;
border: 3px solid #f3f3f3;
border-top: 3px solid #3b82f6;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* إحصائيات */
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.75rem;
margin-top: 1rem;
}
.stat-box {
background: rgba(30, 41, 59, 0.8);
border-radius: 8px;
padding: 0.75rem;
text-align: center;
}
.stat-value {
font-size: 1.25rem;
font-weight: 700;
color: white;
}
.stat-label {
font-size: 0.75rem;
color: #94a3b8;
margin-top: 0.25rem;
}
/* تحسينات للجوال */
@media (max-width: 768px) {
#app {
flex-direction: column;
}
.sidebar {
width: 100%;
min-width: 100%;
height: 50%;
}
.map-controls {
flex-direction: row;
flex-wrap: wrap;
top: auto;
bottom: 1rem;
left: 50%;
transform: translateX(-50%);
}
.control-btn span:not(.icon) {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<!-- الشريط الجانبي -->
<div class="sidebar">
<div class="sidebar-header">
<div class="flex items-center gap-3 mb-2">
<div class="p-2 bg-primary-600 rounded-lg">
<i class="fas fa-map-marked-alt text-white text-xl"></i>
</div>
<div>
<h1 class="text-xl font-bold text-white">مستخرج بيانات OSM</h1>
<p class="text-sm text-slate-300">المملكة المغربية</p>
</div>
</div>
<p class="text-xs text-slate-400 mt-3">
أداة متقدمة لاستخراج وتحليل بيانات OpenStreetMap للمناطق الجغرافية المحددة
</p>
</div>
<div class="sidebar-content">
<!-- حالة النظام -->
<div class="info-card">
<h3><i class="fas fa-info-circle"></i> حالة النظام</h3>
<div class="space-y-2">
<div class="flex justify-between items-center">
<span class="text-slate-300 text-sm">المنطقة المحددة:</span>
<span id="area-status" class="text-sm font-medium text-amber-300">غير محددة</span>
</div>
<div class="flex justify-between items-center">
<span class="text-slate-300 text-sm">عدد المعالم:</span>
<span id="feature-count" class="text-sm font-medium text-emerald-300">0</span>
</div>
<div class="progress-bar">
<div id="progress-fill" class="progress-fill"></div>
</div>
</div>
</div>
<!-- وسوم البحث -->
<div class="info-card">
<h3><i class="fas fa-tags"></i> تصفية الوسوم</h3>
<p class="text-xs text-slate-400 mb-3">
اترك الحقل فارغاً لاستخراج كل البيانات، أو حدد وسوماً محددة
</p>
<div class="space-y-2">
<input
id="tags-input"
type="text"
class="w-full bg-slate-800/50 border border-slate-700 rounded-lg px-3 py-2.5 text-sm text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent"
placeholder="مثال: building, highway, amenity, landuse"
/>
<div class="flex flex-wrap gap-2 mt-2">
<button class="tag-preview" data-tag="building">مباني</button>
<button class="tag-preview" data-tag="highway">طرق</button>
<button class="tag-preview" data-tag="water">مياه</button>
<button class="tag-preview" data-tag="landuse">استخدامات أرض</button>
</div>
</div>
</div>
<!-- إحصائيات البيانات -->
<div class="info-card">
<h3><i class="fas fa-chart-bar"></i> إحصائيات البيانات</h3>
<div class="stats-grid">
<div class="stat-box">
<div id="points-count" class="stat-value">0</div>
<div class="stat-label">نقاط</div>
</div>
<div class="stat-box">
<div id="lines-count" class="stat-value">0</div>
<div class="stat-label">خطوط</div>
</div>
<div class="stat-box">
<div id="polygons-count" class="stat-value">0</div>
<div class="stat-label">مضلعات</div>
</div>
<div class="stat-box">
<div id="total-size" class="stat-value">0 KB</div>
<div class="stat-label">الحجم</div>
</div>
</div>
</div>
<!-- إعدادات متقدمة -->
<div class="info-card">
<h3><i class="fas fa-cog"></i> إعدادات متقدمة</h3>
<div class="space-y-3">
<div>
<label class="text-xs text-slate-300 block mb-1">نوع الملف:</label>
<select id="export-format" class="w-full bg-slate-800/50 border border-slate-700 rounded-lg px-3 py-2 text-sm text-white">
<option value="geojson">GeoJSON</option>
<option value="json">JSON خام</option>
<option value="kml">KML</option>
</select>
</div>
<div>
<label class="text-xs text-slate-300 block mb-1">دقة الاستعلام:</label>
<select id="query-timeout" class="w-full bg-slate-800/50 border border-slate-700 rounded-lg px-3 py-2 text-sm text-white">
<option value="30">سريع (30 ثانية)</option>
<option value="60" selected>متوسط (60 ثانية)</option>
<option value="120">بطيء (120 ثانية)</option>
</select>
</div>
</div>
</div>
</div>
<div class="sidebar-footer">
<button id="action-btn" class="action-btn" disabled>
<i class="fas fa-download"></i>
<span>جلب البيانات</span>
</button>
<p id="hint-text" class="text-xs text-center mt-3 text-slate-400">
<i class="fas fa-info-circle mr-1"></i>
حدد منطقة على الخريطة لبدء الاستخراج
</p>
</div>
</div>
<!-- الخريطة -->
<div id="map">
<!-- عناصر التحكم في الخريطة -->
<div class="map-controls">
<button id="draw-toggle" class="control-btn">
<i class="fas fa-draw-polygon"></i>
<span>رسم منطقة</span>
</button>
<button id="clear-btn" class="control-btn danger">
<i class="fas fa-trash-alt"></i>
<span>مسح الكل</span>
</button>
<div class="basemap-dropdown">
<button id="basemap-toggle" class="control-btn">
<i class="fas fa-layer-group"></i>
<span>الخلفية</span>
<i class="fas fa-chevron-down text-xs"></i>
</button>
<div id="basemap-menu" class="basemap-menu" style="display: none;">
<div class="basemap-item active" data-index="0">
<span>خريطة OSM قياسية</span>
<i class="fas fa-check text-primary-500"></i>
</div>
<div class="basemap-item" data-index="1">
<span>خريطة إنسانية (HOT)</span>
</div>
<div class="basemap-item" data-index="2">
<span>خريطة تضاريس</span>
</div>
<div class="basemap-item" data-index="3">
<span>خريطة ساتلية</span>
</div>
</div>
</div>
<button id="fullscreen-btn" class="control-btn">
<i class="fas fa-expand"></i>
<span>ملء الشاشة</span>
</button>
</div>
<!-- Popup -->
<div id="popup" class="ol-popup" style="display:none;">
<div class="popup-header">
<i class="fas fa-info-circle mr-2"></i>
تفاصيل المعلم
<button id="popup-closer" class="float-left text-slate-400 hover:text-slate-600">
<i class="fas fa-times"></i>
</button>
</div>
<div id="popup-content" class="popup-content"></div>
</div>
<!-- نافذة التحميل -->
<div id="loading-overlay" class="absolute inset-0 bg-slate-900/70 z-[1000] flex items-center justify-center" style="display:none;">
<div class="bg-white p-8 rounded-2xl shadow-2xl max-w-md w-full mx-4">
<div class="flex flex-col items-center">
<div class="loader mb-6"></div>
<h3 class="text-lg font-bold text-slate-800 mb-2">جاري استخراج البيانات</h3>
<p class="text-sm text-slate-600 text-center mb-4" id="loading-message">
جاري الاتصال بخادم Overpass وجلب البيانات...
</p>
<div class="w-full bg-slate-200 rounded-full h-2 mb-2">
<div id="loading-progress" class="bg-primary-600 h-2 rounded-full" style="width: 0%"></div>
</div>
<p class="text-xs text-slate-500" id="loading-details">تقدير الوقت: --</p>
</div>
</div>
</div>
</div>
<!-- إشعارات -->
<div id="notification" class="notification">
<i id="notification-icon" class="fas fa-info-circle text-primary-500"></i>
<div>
<div id="notification-title" class="font-bold text-sm"></div>
<div id="notification-message" class="text-xs text-slate-600"></div>
</div>
</div>
</div>
<!-- importmap -->
<script type="importmap">
{
"imports": {
"ol": "https://esm.sh/ol@10.7.0",
"ol/": "https://esm.sh/ol@10.7.0/",
"osmtogeojson": "https://esm.sh/osmtogeojson@3.0.0-beta.5"
}
}
</script>
<!-- التطبيق الرئيسي -->
<script type="module">
import Map from "ol/Map";
import View from "ol/View";
import TileLayer from "ol/layer/Tile";
import VectorLayer from "ol/layer/Vector";
import VectorSource from "ol/source/Vector";
import OSM from "ol/source/OSM";
import XYZ from "ol/source/XYZ";
import { fromLonLat, toLonLat } from "ol/proj";
import { Draw } from "ol/interaction";
import GeoJSON from "ol/format/GeoJSON";
import { Style, Fill, Stroke, Circle as CircleStyle } from "ol/style";
import Overlay from "ol/Overlay";
import osmtogeojson from "osmtogeojson";
import { getArea } from "ol/sphere";
// DOM Elements
const elements = {
map: document.getElementById("map"),
popup: document.getElementById("popup"),
popupContent: document.getElementById("popup-content"),
popupCloser: document.getElementById("popup-closer"),
drawToggle: document.getElementById("draw-toggle"),
clearBtn: document.getElementById("clear-btn"),
actionBtn: document.getElementById("action-btn"),
loadingOverlay: document.getElementById("loading-overlay"),
loadingProgress: document.getElementById("loading-progress"),
loadingMessage: document.getElementById("loading-message"),
loadingDetails: document.getElementById("loading-details"),
tagsInput: document.getElementById("tags-input"),
basemapToggle: document.getElementById("basemap-toggle"),
basemapMenu: document.getElementById("basemap-menu"),
notification: document.getElementById("notification"),
notificationIcon: document.getElementById("notification-icon"),
notificationTitle: document.getElementById("notification-title"),
notificationMessage: document.getElementById("notification-message"),
areaStatus: document.getElementById("area-status"),
featureCount: document.getElementById("feature-count"),
pointsCount: document.getElementById("points-count"),
linesCount: document.getElementById("lines-count"),
polygonsCount: document.getElementById("polygons-count"),
totalSize: document.getElementById("total-size"),
exportFormat: document.getElementById("export-format"),
queryTimeout: document.getElementById("query-timeout"),
fullscreenBtn: document.getElementById("fullscreen-btn"),
hintText: document.getElementById("hint-text")
};
// App State
const state = {
drawInteraction: null,
selectedPolygon: null,
osmData: null,
isDrawing: false,
stats: {
points: 0,
lines: 0,
polygons: 0,
area: 0
}
};
// Data Sources
const drawSource = new VectorSource();
const resultsSource = new VectorSource();
// Popup Overlay
const popupOverlay = new Overlay({
element: elements.popup,
autoPan: { animation: { duration: 250 } },
});
// Base Layers
const baseLayers = [
new TileLayer({
title: "OSM Standard",
visible: true,
source: new OSM()
}),
new TileLayer({
title: "HOT Humanitarian",
visible: false,
source: new XYZ({
url: "https://tile-{a-c}.openstreetmap.fr/hot/{z}/{x}/{y}.png",
attributions: "© OpenStreetMap contributors, Tiles style by HOT"
})
}),
new TileLayer({
title: "Topographic",
visible: false,
source: new XYZ({
url: "https://{a-c}.tile.opentopomap.org/{z}/{x}/{y}.png",
attributions: "© OpenStreetMap contributors, SRTM | OpenTopoMap",
maxZoom: 17
})
}),
new TileLayer({
title: "Satellite",
visible: false,
source: new XYZ({
url: "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
attributions: "© Esri, Maxar, Earthstar Geographics"
})
})
];
// Map Setup
const map = new Map({
target: elements.map,
layers: [
...baseLayers,
new VectorLayer({
source: drawSource,
style: new Style({
fill: new Fill({
color: "rgba(59, 130, 246, 0.15)"
}),
stroke: new Stroke({
color: "#3b82f6",
width: 3,
lineDash: [5, 5]
})
}),
zIndex: 100
}),
new VectorLayer({
source: resultsSource,
style: (feature) => {
const geometry = feature.getGeometry();
const type = geometry.getType();
if (type === "Point" || type === "MultiPoint") {
return new Style({
image: new CircleStyle({
radius: 6,
fill: new Fill({ color: "#ef4444" }),
stroke: new Stroke({ color: "#fff", width: 2 })
})
});
} else if (type === "LineString" || type === "MultiLineString") {
return new Style({
stroke: new Stroke({
color: "#10b981",
width: 3
})
});
} else {
return new Style({
fill: new Fill({
color: "rgba(59, 130, 246, 0.2)"
}),
stroke: new Stroke({
color: "#3b82f6",
width: 2
})
});
}
},
zIndex: 50
})
],
overlays: [popupOverlay],
view: new View({
center: fromLonLat([-7.1, 31.8]),
zoom: 6,
minZoom: 5,
maxZoom: 18
})
});
// Notification System
const notification = {
show: (type, title, message, duration = 3000) => {
elements.notification.className = "notification";
elements.notification.classList.add(type);
elements.notification.classList.add("show");
if (type === "success") {
elements.notificationIcon.className = "fas fa-check-circle text-emerald-500";
} else if (type === "error") {
elements.notificationIcon.className = "fas fa-exclamation-circle text-rose-500";
} else {
elements.notificationIcon.className = "fas fa-info-circle text-primary-500";
}
elements.notificationTitle.textContent = title;
elements.notificationMessage.textContent = message;
setTimeout(() => {
elements.notification.classList.remove("show");
}, duration);
}
};
// Drawing Management
function toggleDrawing() {
if (state.drawInteraction) {
stopDrawing();
} else {
startDrawing();
}
}
function startDrawing() {
state.isDrawing = true;
elements.drawToggle.classList.add("active");
elements.drawToggle.innerHTML = '<i class="fas fa-times"></i><span>إيقاف الرسم</span>';
drawSource.clear();
resultsSource.clear();
state.selectedPolygon = null;
state.osmData = null;
updateUI();
const draw = new Draw({
source: drawSource,
type: "Polygon",
style: new Style({
fill: new Fill({
color: "rgba(59, 130, 246, 0.3)"
}),
stroke: new Stroke({
color: "#3b82f6",
width: 3
})
})
});
draw.on("drawend", (event) => {
const geometry = event.feature.getGeometry();
const coords = geometry.getCoordinates()[0];
// Calculate area
const area = getArea(geometry);
state.stats.area = Math.round(area / 1000000); // Convert to km²
// Convert to lat/lon array for Overpass
const lonLatCoords = coords.map((c) => {
const ll = toLonLat(c);
return [ll[1], ll[0]]; // [lat, lon]
});
state.selectedPolygon = lonLatCoords;
state.osmData = null;
resultsSource.clear();
stopDrawing();
updateUI();
notification.show("success", "تم تحديد المنطقة", `مساحة المنطقة: ${state.stats.area} كم²`);
});
map.addInteraction(draw);
state.drawInteraction = draw;
}
function stopDrawing() {
if (state.drawInteraction) {
map.removeInteraction(state.drawInteraction);
state.drawInteraction = null;
}
state.isDrawing = false;
elements.drawToggle.classList.remove("active");
elements.drawToggle.innerHTML = '<i class="fas fa-draw-polygon"></i><span>رسم منطقة</span>';
}
// Data Fetching
async function fetchOSMData() {
if (!state.selectedPolygon) return;
const polyStr = state.selectedPolygon.map(coord => `${coord[0]} ${coord[1]}`).join(" ");
const tags = elements.tagsInput.value
.split(",")
.map(t => t.trim())
.filter(t => t.length > 0);
let filter = "";
if (tags.length === 0) {
filter = `nwr(poly:"${polyStr}");`;
} else {
const tagFilters = tags.map(tag => `nwr["${tag}"](poly:"${polyStr}");`).join("\n");
filter = `(\n${tagFilters}\n);`;
}
const timeout = parseInt(elements.queryTimeout.value);
const query = `
[out:json][timeout:${timeout}];
${filter}
out body;
>;
out skel qt;
`;
showLoading(true, "جاري إعداد الاستعلام...");
try {
const url = `https://overpass-api.de/api/interpreter?data=${encodeURIComponent(query)}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`خطأ في الخادم: ${response.status}`);
}
const text = await response.text();
showLoading(true, "جاري معالجة البيانات...");
let data;
try {
data = JSON.parse(text);
} catch (e) {
throw new Error("استجابة غير صالحة من الخادم");
}
if (data.elements && data.elements.length === 0) {
throw new Error("لا توجد بيانات في المنطقة المحددة");
}
const geojson = osmtogeojson.default ? osmtogeojson.default(data) : osmtogeojson(data);
state.osmData = geojson;
// Update statistics
updateStatistics(geojson);
// Add features to map
const format = new GeoJSON({ featureProjection: "EPSG:3857" });
resultsSource.clear();
resultsSource.addFeatures(format.readFeatures(geojson));
showLoading(false);
updateUI();
notification.show(
"success",
"تم استخراج البيانات",
`تم استخراج ${state.stats.points + state.stats.lines + state.stats.polygons} معلم`
);
} catch (error) {
showLoading(false);
notification.show("error", "خطأ في الاستخراج", error.message);
console.error("Fetch error:", error);
}
}
function updateStatistics(geojson) {
if (!geojson || !geojson.features) return;
state.stats.points = 0;
state.stats.lines = 0;
state.stats.polygons = 0;
geojson.features.forEach(feature => {
const type = feature.geometry?.type;
if (type === "Point" || type === "MultiPoint") {
state.stats.points++;
} else if (type === "LineString" || type === "MultiLineString") {
state.stats.lines++;
} else if (type === "Polygon" || type === "MultiPolygon") {
state.stats.polygons++;
}
});
// Update UI
elements.pointsCount.textContent = state.stats.points;
elements.linesCount.textContent = state.stats.lines;
elements.polygonsCount.textContent = state.stats.polygons;
elements.featureCount.textContent = state.stats.points + state.stats.lines + state.stats.polygons;
// Calculate data size
const dataSize = JSON.stringify(geojson).length;
const sizeKB = (dataSize / 1024).toFixed(1);
elements.totalSize.textContent = `${sizeKB} KB`;
}
// Export Functionality
function exportData() {
if (!state.osmData) return;
const format = elements.exportFormat.value;
let data, filename, mimeType;
switch (format) {
case "json":
data = JSON.stringify(state.osmData, null, 2);
filename = "osm_data.json";
mimeType = "application/json";
break;