-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMicro-Irrigation-Design-0.html
More file actions
965 lines (821 loc) · 44.7 KB
/
Copy pathMicro-Irrigation-Design-0.html
File metadata and controls
965 lines (821 loc) · 44.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>灌溉管道设计</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<!-- 使用最新版本 -->
<link rel="stylesheet" href="https://unpkg.com/leaflet-measure/dist/leaflet-measure.css" />
<!-- Leaflet Draw CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css" />
<!-- ECharts JS -->
<script src="https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.4/dist/chart.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-annotation"></script>
<!-- Leaflet JS -->
<!-- <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script> -->
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<!-- // 使用 jsDelivr CDN 加载最新版本的 JS -->
<script src="https://cdn.jsdelivr.net/npm/leaflet-measure/dist/leaflet-measure.min.js"></script>
<!-- Leaflet Draw JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
<!-- <script src="http://api.tianditu.gov.cn/api?v=4.0&tk=7c00d7bdc4809ba8858fa67c31ca2950"></script> -->
<style>
#map {
height: 500px;
}
#chart {
height: 400px;
}
.input-group {
width: 98%;
grid-template-columns: 1fr;
margin: 5px 5px;
}
input,
select {
width: 18%;
margin: 2px 2px;
padding: 8px;
border: 2px solid #ddd;
border-radius: 5px;
box-sizing: border-box;
}
button {
background: #53708d;
color: white;
padding: 10px 20px;
margin: 5px 5px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background 0.5s;
}
button:hover {
background: #29b9aa;
}
#loadPageButton3 {
background-color: #007BFF;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
#loadPageButton3:hover {
background-color: #0056b3;
}
#loadPageButton3:active {
background-color: #003d80;
}
</style>
</head>
<body>
<button id="collectArea">测量灌溉面积</button>
<button id="layoutPipeline">布置管道</button>
<button id="addTextMarker">添加文字标注</button>
<button onclick="getCurrentLocation()">获取当前位置</button>
<div class="input-group">
<label>高程 (m):</label>
<span id="elevationValue"></span>
</div>
<div class="input-group">
<label>纬度:</label>
<input type="number" id="lngValue" value="25.1222" step="0.001" min="0" placeholder="纬度">
</div>
<div class="input-group">
<label>经度:</label>
<input type="number" id="latValue" value="111.2221" step="0.001" min="0" placeholder="经度">
</div>
<div id="map"></div>
<div class="input-group">
<label for="areaName">灌溉地点名称:</label>
<input type="text" id="areaName" placeholder="地点名称" readonly>
<label for="area">灌溉区域面积 (平方米):</label>
<input type="number" id="area" placeholder="灌溉区域面积" readonly><br>
<label for="microArea">微灌面积占比(扣除面积内的非种植区):</label>
<input type="number" id="microArea" value='0.95'><br>
<label for="microIrrigationArea">微灌灌溉面积 (平方米):</label>
<input type="number" id="microIrrigationArea" placeholder="微灌面积"><br>
<label for="IrrigatedArea">微灌灌溉面积 (亩):</label>
<input type="number" id="IrrigatedArea" placeholder="灌溉面积" readonly><br>
<label for="emitterSpacing">灌水器布置间距 (米):</label>
<input type="number" id="emitterSpacing" value="0.3" step="0.1" placeholder="灌水器布置间距">
<label for="lateralSpacing">毛管间距 (米):</label>
<input type="number" id="lateralSpacing" value="1.0" step="0.1" placeholder="毛管间距">
<label for="wetRate">微灌湿润比:</label>
<input type="number" id="wetRate" value="0.50" step="0.1" placeholder="湿润比">
<label for="pipeEndHead">输水管尾端工作水头 (m):</label>
<input type="number" id="pipeEndHead" value="20" step="1.0" placeholder="尾端水头">
<label for="pipeSegmentNum">输水管段数量:</label>
<input type="number" id="pipeSegmentNum" value="0" placeholder="管段数">
<br>
<label for="cropType">作物类型:</label>
<span>《微灌工程技术规范》(GB/T 50485-2020),确定作物日耗水量(ETc,单位:mm/d)的方法如下:</span>
<br>
<select id="cropType">
<option value="grape">葡萄、树、瓜类</option>
<option value="food">粮、棉、油等植物</option>
<option value="vegetable0">蔬菜(保护地)</option>
<option value="vegetable1">蔬菜(露地)</option>
<option value="grass_w">冷季型草</option>
<option value="grass_s">暖季型草</option>
</select>
<br>
<label for="soilType">土壤类型:</label>
<select id="soilType">
<option value="loam">壤土</option>
<option value="sand">砂土</option>
<option value="clay">黏土</option>
</select>
<br>
<button id="calculateETc">查询设计参数</button><br>
<span>滴头流量范围一般为 1.0~10.0 L/h,需根据土壤质地选择:</span><br>
<span>砂质土:流量较大(如4 - 6 L/h),避免水分快速下渗。</span><br>
<span>壤土:流量(如 2 - 3 L/h),避免水分下渗。</span><br>
<span>粘质土:流量较小(如1 - 2 L/h),防止地表积水。</span><br>
<label for="cropETc">作物日耗水量 (mm/d):</label>
<input type="number" id="cropETc" value='5' placeholder="日耗水量">
<label for="emitterFlow">灌水器流量 (升/小时):</label>
<input type="number" id="emitterFlow" value='2' placeholder="灌水器流量">
<br>
<button id="calculateMaterials">统计材料用量</button>
<button id="calculateWater">计算灌溉流量</button><br>
<div style="width: 100%; height: 2px; background-color: rgb(57, 53, 140); margin-top: 5px;"></div>
<label for="workingTime">灌溉系统每天工作时间 (小时):</label>
<input type="number" id="workingTime" value="20.0" placeholder="工作时间">
<label for="workingGroup">灌溉轮灌组数 (个):</label>
<input type="number" id="workingGroup" value="1" placeholder="轮灌组数">
<label for="pipeDiameter">输水管管径 (mm):</label>
<input type="number" id="pipeDiameter" value="100" placeholder="管径"><span>注意:请选用市场规格的管道内径!!!</span>
<br>
<label for="pipelineLength">布置的输水管道长度 (米):</label>
<input type="number" id="pipelineLength" placeholder="管道长度" readonly>
<br>
<button id="calculateHeadloss">计算水头损失</button><br>
<div style="width: 100%; height: 2px; background-color: rgb(240, 130, 130); margin-top: 5px;"></div>
</div>
<h3 >计算成果:</h3>
<div id="etcResult"></div>
<div id="dripIntensityResult"></div><br>
<div id="materialsResult"></div>
<div id="waterResult"></div><br>
<div id="headlossResult"></div>
<div class="chart-container">
<canvas id="chart"></canvas>
</div>
<!-- <div id="chart"></div> -->
<p>
<br />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</p>
<p>
<br />
</p>
<script>
let map;
const pipeLengths = []; // 管道长度数组
var drawnItems = new L.FeatureGroup();
// 确保 Chart.js 已经加载
if (typeof Chart === 'undefined') {
console.error('Chart.js 未正确加载');
}
// 用于存储当前的 Chart.js 实例
var myChart = null;
// 获取当前地理位置函数
function getCurrentLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
alert("Geolocation is not supported by this browser.");
}
}
// 成功获取位置后的回调函数
function showPosition(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
// 设置地图中心并放大
map.setView([lat, lon], 13);
// 添加标记
L.marker([lat, lon]).addTo(map)
.bindPopup(`Your current location<br>Latitude: ${lat.toFixed(4)}, Longitude: ${lon.toFixed(4)}`)
.openPopup();
}
// 获取位置失败后的回调函数
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
// 土壤入渗率
const soils = {
//"clay": { Ks: 0.0005 },
//"loam": { Ks: 0.005 },
//"sand": { Ks: 0.05 }
"clay": { Ks: 0.0010 }, // 约0.01 mm/min -> m/h
"loam": { Ks: 0.0050 }, // 约0.1 mm/min -> m/h
"sand": { Ks: 0.050 } // 约10 mm/min -> m/h
};
// 计算湿润比核心函数
function calculateWetRatio(Q_lph, soilType, s, l) {
const Q = Q_lph * 0.001; // 转换为 m/h
const Ks = soils[soilType].Ks;
let wet;
// 计算湿润半径
const R = Math.sqrt(Q / (Math.PI * Ks));
// 判断湿润模式
if (s <= 2 * R) {
wet = Math.min(2 * R / l, 1) ;
} else {
wet = Math.min((4 * R * R) / (s * l), 1) ;
}
return [wet, R];
}
// 增强版系统配置 // 在 HTML 中添加一个 canvas 元素用于绘制
const MAP_CONFIG = {
baseLayers: {
"街道地图": L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
"卫星影像": L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'),
"地形图": L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png')
},
initCenter: [25.0, 110.0],
initZoom: 5
};
// 修正参数顺序错误
function calculatedHeadloss(pipeLengths, pipeData, hydraulicData) {
pipeData.length = 0; // 清空数组
hydraulicData.length = 0;
let totalH = parseFloat(document.getElementById('pipeEndHead').value);
let accumulatedLength = 0;
pipeData.push(accumulatedLength);
hydraulicData.push(totalH);
var v=0;
for (let i = 0; i < pipeLengths.length; i++) {
const length = pipeLengths[i];
const [hf, pipeVelocity] = calculHeadloss(length);
const localHeadLoss = hf + 0.1 * Math.pow(pipeVelocity, 2) / (2 * 9.8);
totalH += localHeadLoss;
accumulatedLength += length;
v=pipeVelocity;
hydraulicData.push(totalH);
pipeData.push(accumulatedLength);
}
return v;
}
// 增强图表管理
function drawHeadLossChart(pipeData, hydraulicData, myChart) {
// 如果之前的图表实例存在,销毁它
if (myChart!== null && myChart!== undefined && myChart instanceof Chart) {
myChart.destroy();
}
// 检查数据是否为空
if (pipeData.length === 0 || hydraulicData.length === 0) {
console.error('管道数据或水头数据为空,无法绘制图表。');
return;
}
// 处理 Math.max 可能出现的 NaN 情况
const maxPipeLength = Math.max(...pipeData);
const maxHydraulicData = Math.max(...hydraulicData);
// 获取 canvas 元素
const ctx = document.getElementById('chart').getContext('2d');
// 合并 pipeData 和 hydraulicData 为点数组
const nodes = pipeData.map((pipe, index) => ({
x: pipe,
y: hydraulicData[index]
}));
// 创建 Chart.js 图表
myChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: [{
label: '水头高度 (m)',
data: nodes.map(point => ({ x: point.x, y: point.y })),
borderColor: '#f9090a',
backgroundColor: 'rgba(5, 92, 102, 0.1)',
showLine: true,
pointRadius: 4,
pointBackgroundColor: 'red',
pointBorderColor: 'blue',
borderDash: [5, 2, 6], // 设置为点划线
tension: 0.2,
borderWidth: 2,
fill: true
}]
},
options: {
scales: {
x: {
title: {
display: true,
text: '管道长度 (m)'
},
beginAtZero: true,
type: 'linear',
position: 'bottom'
},
y: {
title: {
display: true,
text: '总水头线 (m)'
},
beginAtZero: true,
type: 'linear',
position: 'left'
}
}
}
});
return myChart;
}
function calculHeadloss(pipeLength) {
var pipediameter = parseFloat(document.getElementById("pipeDiameter").value);
var emitterFlow = parseFloat(document.getElementById('emitterFlow').value);
var emitterSpacing = parseFloat(document.getElementById('emitterSpacing').value);
var lateralSpacing = parseFloat(document.getElementById('lateralSpacing').value);
var workingGroup = parseFloat(document.getElementById('workingGroup').value);
var pipeEndHead = parseFloat(document.getElementById('pipeEndHead').value);
var microIrrigationArea = parseFloat(document.getElementById('microIrrigationArea').value);
// 计算灌水器数量
var emitterCount = (microIrrigationArea / (emitterSpacing * lateralSpacing));
var flowRate = emitterCount * emitterFlow / workingGroup;
var density = 1000;
var viscosity = 0.001;
// 计算水力参数
const pipeCrossSectionalArea = Math.PI * (pipediameter * 0.001 / 2) ** 2;
const pipeVelocity = flowRate * 0.001 / 3600 / pipeCrossSectionalArea;
const reynoldsNumber = (density * pipeVelocity * pipediameter * 0.001) / viscosity;
var d = pipediameter;
var l = pipeLength;
var flowq = flowRate;
var f, m, b;
if (d <= 8) {
if (reynoldsNumber <= 2300) {
f = 1.750;
m = 1.00;
b = 4.00;
} else {
f = 0.595;
m = 1.69;
b = 4.69;
}
} else {
f = 0.505;
m = 1.75;
b = 4.75;
}
var headLoss = f * l * Math.pow(flowq, m) / Math.pow(d, b);
return [headLoss, pipeVelocity];
}
document.getElementById('calculateHeadloss').addEventListener('click', function () {
var pipeSegmentNum = parseFloat(document.getElementById("pipeSegmentNum").value);
if (pipeSegmentNum < 1) {
alert(`请先在地图中布置管道。管段 ${pipeSegmentNum} 数不能小于 1 !!`);
return;
}
var microIrrigationArea = parseFloat(document.getElementById('microIrrigationArea').value);
var emitterFlow = parseFloat(document.getElementById('emitterFlow').value);
var emitterSpacing = parseFloat(document.getElementById('emitterSpacing').value);
var lateralSpacing = parseFloat(document.getElementById('lateralSpacing').value);
var workingTime = parseFloat(document.getElementById('workingTime').value);
var wetRate = parseFloat(document.getElementById('wetRate').value);
var workingGroup = parseFloat(document.getElementById('workingGroup').value);
var cropETc = parseFloat(document.getElementById('cropETc').value);
if (isNaN(microIrrigationArea) || isNaN(emitterFlow) || isNaN(emitterSpacing) || isNaN(lateralSpacing)) {
alert('请输入有效的微灌灌溉面积、灌水器流量、灌水器布置间距和毛管间距。');
return;
}
// 计算灌水器数量
var emitterCount = (microIrrigationArea / (emitterSpacing * lateralSpacing));
// 计算灌水流量(L/hr)
var waterFlow = emitterCount * emitterFlow / workingGroup;
// 计算灌溉流量
waterFlow = waterFlow * 0.001; //(L/hr)->(m³/hr)
//cropETc=parseFloat(cropETc);
var emitterIrrigationRate = emitterFlow / (emitterSpacing * lateralSpacing * wetRate); // 滴灌强度(mm/hr)
//var circleNumber =Math.floor(emitterIrrigationRate /cropETc) ;
//D 为管道内径(单位:米),Q 为流量(单位:立方米/秒),v 为经济流速(单位:米/秒)
//var pipeDiameter = Math.sqrt(waterFlow / 3600 * 4 / Math.PI / 1.5) * 1000;
// document.getElementById('pipeDiameter').value = pipeDiameter;
//微灌系统设计流量公式 workingTime
var irriFlow = microIrrigationArea * cropETc * 0.001 / 0.9/workingTime;
irriFlow = irriFlow.toFixed(2);
var pipeData = [];
var hydraulicData = [];
var pipeVelocity=calculatedHeadloss(pipeLengths, pipeData, hydraulicData);
var totalHead = hydraulicData[hydraulicData.length - 1];
var headLoss = totalHead - parseFloat(document.getElementById('pipeEndHead').value);
// 计算灌水量
var pipeDiameter = parseFloat(document.getElementById('pipeDiameter').value);
waterFlow =pipeVelocity*(pipeDiameter*0.001/2)**2*Math.PI;
waterFlow=waterFlow*3600;
var waterVolume = workingTime* waterFlow; //m³/hr->m³/s
waterVolume = waterVolume.toFixed(2);
var waterRate = waterVolume /microIrrigationArea*1000; // m³/day->mm/day
pipeDiameter = pipeDiameter.toFixed(2);
var irrigatedRate = waterRate *0.66667; // mm/day->m³/亩/day
//cropETc=parseFloat(cropETc);
//if (emitterSpacing >= lateralSpacing) {
// wetRate=1.0;
//}
//if ((emitterSpacing /lateralSpacing)>wetRate) {
// wetRate=emitterSpacing /lateralSpacing;
// wetRate=wetRate.toFixed(2);
// document.getElementById('wetRate').value=wetRate;
//}
// var irrigatedRate = waterVolume / 666.67; // m³/day->亩/day
var runArea=microIrrigationArea/workingGroup;
var result = `总的灌水量: ${waterVolume} (立方米/天 m³/d) ,单位灌水量: ${irrigatedRate.toFixed(2)} (立方米/亩/天 m³/亩/day) ,
<br>每天灌水量: ${waterRate.toFixed(2)} ((毫米/天 mm/d) ,每日工作 ${workingTime.toFixed(2)} 小时;<br>灌水强度: ${emitterIrrigationRate.toFixed(2)} (毫米/小时 mm/hr)。
<br>轮灌组面积: ${runArea.toFixed(2)} (平方米 m2)。
<br>计算管径: ${pipeDiameter} (毫米 mm), 注意:请选用市场规格的管道内径!!!再计算水头损失。<br>
<br>按规范从面积计算的流量:${irriFlow} (立方米/小时 m³/hr) 【<=】 从系统管道计算总灌溉流量: ${waterFlow.toFixed(2)} (立方米/小时 m³/hr)。
<p style="color: red;">两者应当接近或相等,如果相差较大,可调整 “轮灌组或每天工作时间” 再进行 “水头损失计算”。</p>`;
document.getElementById('waterResult').innerHTML = result;
// 假设 waterFlow 是以 m³/hr 为单位的水泵总流量
const pumpFlowRate = waterFlow / 3600; // 转换为 m³/s
// 扬程 H 已经有 totalHead,乘以 1.2 可能是为了考虑一些额外的因素
const pumpHead = totalHead * 1.2;
const efficiency = 0.7;
// 计算功率 P = (Q * g * H) / η
const gravity = 9.81; // 重力加速度,单位:m/s^2
const pumpPower = (pumpFlowRate * gravity * pumpHead) / efficiency; // 结果已经是千瓦 (kW)
pipeEndHead= parseFloat( document.getElementById('pipeEndHead').value);
//var result = `管道水头损失: ${headLoss.toFixed(2)} (米 m),尾端需要的工作水头:${} (米 m), <br>
//计算流速: ${pipeVelocity.toFixed(2)} (米/秒 m/s),输水管道总水头: ${totalHead.toFixed(2)} (米 m)。`;
var result = `管道水头损失: ${headLoss.toFixed(2)} (米 m),尾端需要的工作水头:${pipeEndHead} (米 m), <br>
计算流速: ${pipeVelocity.toFixed(2)} (米/秒 m/s),输水管道总水头: ${totalHead.toFixed(2)} (米 m)。<br>
水泵总流量: ${waterFlow.toFixed(2)} (立方米/时 m³/hr),扬程: ${pumpHead.toFixed(2)} (米 m),功率: ${pumpPower.toFixed(2)} (千瓦 kW)。`;
document.getElementById('headlossResult').innerHTML = result;
// drawHeadLossChart(pipeData, hydraulicData, myChart);
});
document.addEventListener('DOMContentLoaded', function () {
try {
// 获取经纬度输入框的值
const initialLat = parseFloat(document.getElementById('latValue').value);
const initialLng = parseFloat(document.getElementById('lngValue').value);
// 检查经纬度值是否有效
if (isNaN(initialLat) || isNaN(initialLng)) {
console.error('经纬度值无效,请检查输入。');
return;
}
// 初始化 Leaflet 地图,使用已有的经纬度定位 Container
map = L.map('map', {
center: MAP_CONFIG.initCenter,
zoom: MAP_CONFIG.initZoom
});
L.control.layers(MAP_CONFIG.baseLayers).addTo(map);
MAP_CONFIG.baseLayers["卫星影像"].addTo(map);
// 添加测量控件
if (typeof L.Control.Measure === 'function') {
const measureControl = new L.Control.Measure({
position: 'topleft',
primaryLengthUnit: 'meters',
secondaryLengthUnit: 'kilometers',
primaryAreaUnit: 'sqmeters',
secondaryAreaUnit: 'hectares'
});
measureControl.addTo(map);
} else {
console.error('Leaflet-measure 插件加载失败,请检查引入的文件。');
}
// 采集灌溉面积按钮事件
document.getElementById('collectArea').addEventListener('click', function () {
const drawControl = new L.Control.Draw({
draw: {
polyline: true,
polygon: true,
circle: false,
rectangle: true,
marker: false
},
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
new L.Draw.Polygon(map, drawControl.options.draw.polygon).enable();
});
// 布置管道按钮事件
document.getElementById('layoutPipeline').addEventListener('click', function () {
// 检查 drawnItems 是否存在
var editConfig = {};
if (typeof drawnItems !== 'undefined') {
editConfig.featureGroup = drawnItems;
}
drawControl = new L.Control.Draw({
draw: {
polyline: false,
polygon: false,
circle: false,
rectangle: false,
marker: false
}})
// edit: editConfig
map.addControl(drawControl);
new L.Draw.Polyline(map, drawControl.options.draw.polyline).enable();
});
// 创建一个显示经纬度和当前位置信息的控件
var locationControl = L.control({ position: 'bottomleft' });
locationControl.onAdd = function (map) {
var div = L.DomUtil.create('div', 'location-info');
div.innerHTML = '<p>经纬度: 暂无<br>当前位置信息: 暂无</p>';
return div;
};
locationControl.addTo(map);
// 创建地图实例
//const map2 = new T.Map('mapDiv');
//map.centerAndZoom(new T.LngLat(116.407, 39.905), 15); // 中心点为北京
// 点击地图获取高程
//map2.addEventListener('click', function(e) {
//const lngLat2 = e.lngLat;
//T.Util.getElevation(lngLat2, function(elevData) {
// if (elevData.status === 'success') {
// console.log(`当前位置高程:${elevData.elevation} 米`);
// }
//});
//});
// 获取位置的函数
async function getLocationFromLatLng(lat, lng) {
const apiKey = '7f6c79b07c8445d787a932bc78109d13'; // Replace with your geocoding API key
const url = `https://api.opencagedata.com/geocode/v1/json?q=${lat}+${lng}&key=${apiKey}`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.results.length > 0) {
return data.results[0].formatted;
} else {
throw new Error('No results found');
}
} catch (error) {
//console.error('获取位置信息出错:', error);
//throw error;
return;
}
}
// 获取高程的函数
async function getElevation(lat, lng) {
const url = `https://api.open-elevation.com/api/v1/lookup?locations=${lat},${lng}`;
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.results && data.results.length > 0) {
return data.results[0].elevation;
} else {
throw new Error('No elevation data found');
}
} catch (error) {
//console.error('获取高程信息出错:', error);
//throw error;
return
}
}
// 监听地图点击事件,更新经纬度、当前位置信息和高程
map.on('click', async function (e) {
var lat = e.latlng.lat.toFixed(6);
var lng = e.latlng.lng.toFixed(6);
var locationInfoDiv = document.querySelector('.location-info p');
locationInfoDiv.innerHTML = `经纬度: ${lat}, ${lng}<br>当前位置信息: 正在查询...`;
document.getElementById('elevationValue').textContent = '正在查询...';
try {
const location = await getLocationFromLatLng(lat, lng);
locationInfoDiv.innerHTML = `经纬度: ${lat}, ${lng}<br>当前位置信息: ${location}`;
document.getElementById('latValue').value = lat;
document.getElementById('lngValue').value = lng;
document.getElementById('areaName').value = location;
const elevation = await getElevation(lat, lng);
document.getElementById('elevationValue').textContent = elevation;
} catch (error) {
locationInfoDiv.innerHTML = `经纬度: ${lat}, ${lng}<br>当前位置信息: 查询出错,错误详情: ${error.message}`;
document.getElementById('elevationValue').textContent = '查询出错';
}
});
// 处理绘制完成事件
map.on(L.Draw.Event.CREATED, function (e) {
var type = e.layerType;
var layer = e.layer;
if (type === 'polygon') {
// 设置多边形样式
layer.setStyle({
color: '#29b9aa', // 多边形线段颜色
fillColor: 'rgba(41, 185, 170, 0.2)', // 多边形填充颜色
fillOpacity: 0.5
});
// 计算灌溉面积
var area = L.GeometryUtil.geodesicArea(layer.getLatLngs()[0]);
area = Math.round(area * 100) / 100;
var microIrrigationArea = area * parseFloat(document.getElementById('microArea').value);
microIrrigationArea = Math.round(microIrrigationArea * 100) / 100;
document.getElementById('area').value = area;
document.getElementById('microIrrigationArea').value = microIrrigationArea;
var mu = area / 666.67;
mu = mu.toFixed(2);
document.getElementById('IrrigatedArea').value = mu;
} else if (type === 'polyline') {
// 设置折线样式
layer.setStyle({
color: '#ff6384', // 折线颜色
weight: 3,
opacity: 1
});
// 计算管线长度
var pipelineLength = 0;
var latlngs = layer.getLatLngs();
for (var i = 0; i < latlngs.length - 1; i++) {
var length = latlngs[i].distanceTo(latlngs[i + 1]);
pipeLengths.push(length);
pipelineLength += length;
}
var pipeSegmentNum = latlngs.length - 1;
document.getElementById('pipeSegmentNum').value = pipeSegmentNum;
pipelineLength = pipelineLength.toFixed(2);
document.getElementById('pipelineLength').value = pipelineLength;
}
drawnItems.addLayer(layer);
map.addLayer(drawnItems);
});
// 添加文字标注按钮事件
document.getElementById('addTextMarker').addEventListener('click', function () {
const text = prompt('请输入标注文字');
if (text) {
map.once('click', function (e) {
L.marker(e.latlng).bindTooltip(text, { permanent: true, direction: 'top' }).addTo(map);
});
}
});
// 计算灌溉材料按钮事件
document.getElementById('calculateMaterials').addEventListener('click', function () {
var microIrrigationArea = parseFloat(document.getElementById('microIrrigationArea').value);
var emitterFlow = parseFloat(document.getElementById('emitterFlow').value);
var pipelineLength = parseFloat(document.getElementById('pipelineLength').value);
var emitterSpacing = parseFloat(document.getElementById('emitterSpacing').value);
var lateralSpacing = parseFloat(document.getElementById('lateralSpacing').value);
if (isNaN(microIrrigationArea) || isNaN(lateralSpacing) || isNaN(emitterSpacing)) {
alert('请输入有效的微灌灌溉面积、布置间距、灌水器流量和管线长度。');
return;
}
// 简单计算,实际计算需根据具体情况调整
var emitterCount = (microIrrigationArea / (emitterSpacing * lateralSpacing));
var lateralTotal = (microIrrigationArea / lateralSpacing);
emitterCount = emitterCount.toFixed(0);
var result = `灌水器数量: ${emitterCount} (个)<br> 毛管总长度: ${lateralTotal.toFixed(2)} (米 m)`;
document.getElementById('materialsResult').innerHTML = result;
});
// 计算灌水量和灌溉流量按钮事件
document.getElementById('calculateWater').addEventListener('click', function () {
var soilType = document.getElementById('soilType').value;
var microIrrigationArea = parseFloat(document.getElementById('microIrrigationArea').value);
var emitterFlow = parseFloat(document.getElementById('emitterFlow').value);
var emitterSpacing = parseFloat(document.getElementById('emitterSpacing').value);
var lateralSpacing = parseFloat(document.getElementById('lateralSpacing').value);
var workingTime = parseFloat(document.getElementById('workingTime').value);
var wetRate = parseFloat(document.getElementById('wetRate').value);
var workingGroup = parseFloat(document.getElementById('workingGroup').value);
var cropETc = parseFloat(document.getElementById('cropETc').value);
if (isNaN(microIrrigationArea) || isNaN(emitterFlow) || isNaN(emitterSpacing) || isNaN(lateralSpacing)) {
alert('请输入有效的微灌灌溉面积、灌水器流量、灌水器布置间距和毛管间距。');
return;
}
// 计算灌水器数量
var emitterCount = (microIrrigationArea / (emitterSpacing * lateralSpacing));
// 计算灌水流量(L/hr)
for(i=1;i<=emitterCount;i++){
var waterFlow = emitterCount * emitterFlow / i;
// 计算灌溉流量
waterFlow = waterFlow * 0.001; //(L/hr)->(m³/hr)
// 计算灌水量(假设灌溉时间为 20 小时)
var waterVolume = workingTime * waterFlow; //m³/hr*h->m³/day
//var waterRate=waterVolume*0.001; // m3/d->mm/d
var waterRate = waterVolume /microIrrigationArea*1000;
if(waterRate<=cropETc){
break;
}
}
var cycleNumber = i-3; //Math.floor(emitterIrrigationRate /workingGroup/cropETc) ;
if (cycleNumber > 1) {
document.getElementById('workingGroup').value=cycleNumber;
}
var irrigatedRate = waterRate *0.66667; // mm/day->m³/亩/day
//console.log(`emitterSpacing ${emitterSpacing} /lateralSpacing ${lateralSpacing} > wetRate ${wetRate}`);
//cropETc=parseFloat(cropETc);
const [wettingRatio, r] = calculateWetRatio(emitterFlow, soilType, emitterSpacing, lateralSpacing);
//if (emitterSpacing >= lateralSpacing*0.9) {
//console.log(`emitterSpacing ${emitterSpacing} >= lateralSpacing`);
// wetRate=1.0;
// document.getElementById('wetRate').value=wettingRatio;
//}
//var wetR=emitterSpacing**2 /lateralSpacing**2;
//var wetR = (Math.abs(emitterSpacing) ** 2) / (Math.abs(lateralSpacing) *Math.abs(emitterSpacing) );
wetR=Math.floor(wettingRatio*100)/100;
if (wetR>wetRate) {
//console.log(`emitterSpacing ${emitterSpacing} /lateralSpacing ${lateralSpacing} > wetRate ${wetRate}`);
wetRate=wetR;
document.getElementById('wetRate').value=wetRate.toFixed(2);
}
var emitterIrrigationRate = emitterFlow / (emitterSpacing * lateralSpacing * wetRate); // 滴灌强度(mm/hr)
//wetRate=wetRate;
waterVolume = waterVolume.toFixed(2);
//wetRate=wetRate.toFixed(2);
//D 为管道内径(单位:米),Q 为流量(单位:立方米/秒),v 为经济流速(单位:米/秒)
var pipeDiameter = Math.sqrt(waterFlow / 3600 * 4 / Math.PI / 1.5) * 1000;
pipeDiameter = pipeDiameter.toFixed(2);
document.getElementById('pipeDiameter').value = pipeDiameter;
//微灌系统设计流量公式 workingTime
var irriFlow = microIrrigationArea * cropETc * 0.001 / 0.9/workingTime;
irriFlow = irriFlow.toFixed(2);
runArea=microIrrigationArea/workingGroup;
var result = `总的灌水量: ${waterVolume} (立方米/天 m³/d) ,单位灌水量: ${irrigatedRate.toFixed(2)} (立方米/亩/天 m³/亩/day) ,
<br>每天灌水量: ${waterRate.toFixed(2)} (毫米/天 mm/d) ,每日工作 ${workingTime.toFixed(2)} 小时;<br>灌水强度: ${emitterIrrigationRate.toFixed(2)} (毫米/小时 mm/hr)。
<br>轮灌组平均面积: ${runArea.toFixed(2)} (平方米 m2),湿润半径: ${r.toFixed(2)} (米 m)。
<br>计算管径: ${pipeDiameter} (毫米 mm), 注意:请选用市场规格的管道内径!!!再计算水头损失。<br>
<br>按规范从面积计算的流量:${irriFlow} (立方米/小时 m³/hr) 【?】 从系统管道计算总灌溉流量: ${waterFlow.toFixed(2)} (立方米/小时 m³/hr)。
<p style="color: red;">从规范到管道两者的计算流量值应当接近或相等,如果相差较大,可 “调整轮灌组或每天工作时间” 再进行计算,或请检查计算参数。</p>`;
document.getElementById('waterResult').innerHTML = result;
});
// 计算作物日耗水量按钮事件
document.getElementById('calculateETc').addEventListener('click', function () {
var cropType = document.getElementById('cropType').value;
var etc;
var wetRate = parseFloat(document.getElementById('wetRate').value);
switch (cropType) {
case 'food':
etc = '4~7 mm/d';
wetRate = 0.70;
break;
case 'grape':
etc = '3~7 mm/d';
wetRate = 0.40;
break;
case 'vegetable0':
// 这里可根据实际情况补充蔬菜的需水量范围
etc = '2~4 mm/d';
wetRate = 0.90;
break;
case 'vegetable1':
// 这里可根据实际情况补充蔬菜的需水量范围
etc = '4~7 mm/d';
wetRate = 0.90;
break;
case 'grass_w':
// 这里可根据实际情况补充蔬菜的需水量范围
etc = '5~8 mm/d';
wetRate = 0.90;
break;
case 'grass_s':
// 这里可根据实际情况补充蔬菜的需水量范围
etc = '3~5 mm/d';
wetRate = 0.95;
break;
default:
etc = '未知作物类型';
}
document.getElementById('wetRate').value = wetRate;
var result = `作物日耗水量 (ETc): ${etc}`;
document.getElementById('etcResult').innerHTML = result;
});
calculateDripIntensity();
} catch (error) {
console.error('地图初始化出错:', error);
}
});
// 计算滴灌强度上限按钮事件document.getElementById('').addEventListener('click',
function calculateDripIntensity(){
var soilType = document.getElementById('soilType').value;
var dripIntensity;
switch (soilType) {
case 'sand':
dripIntensity = ' >= 20 mm/h';
document.getElementById('emitterFlow').value = 4;
break;
case 'clay':
dripIntensity = ' < 5 mm/h';
document.getElementById('emitterFlow').value = 1;
break;
default:
document.getElementById('emitterFlow').value = 2;
dripIntensity = '5 mm/h < 滴灌强度 < 20 mm/h';
}
var result = `滴灌强度: ${dripIntensity}`;
document.getElementById('dripIntensityResult').innerHTML = result;
};
</script>
</body>
</html>