-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
905 lines (812 loc) · 29 KB
/
map.js
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
Skip to content
Search or jump to…
Pull requests
Issues
Marketplace
Explore
@zhouxiangyi
0
0 0 zhouxiangyi/openlayersdemo Private
Code Issues 0 Pull requests 0 Projects 0 Security Insights Settings
openlayersdemo/src/js/map.js
@zhouxiangyi zhouxiangyi 空间查询的完成
048fcfd 19 days ago
886 lines (798 sloc) 28.6 KB
import { Map, View } from 'ol';
import TileLayer from 'ol/layer/Tile';
import ImageLayer from 'ol/layer/Image'
import ImageWMS from 'ol/source/ImageWMS'
import { defaults as defaultControls, ScaleLine } from 'ol/control';
import { transform } from 'ol/proj'
import XYZ from 'ol/source/XYZ';
import 'ol/ol.css';
import { mapconfig } from '../config/mapconfig'
import { OSM, TileArcGISRest, WMTS } from 'ol/source.js';
import Feature from 'ol/Feature.js';
import Point from 'ol/geom/Point.js';
import VectorLayer from 'ol/layer/Vector.js';
import VectorSource from 'ol/source/Vector.js';
import { Icon, Style, Circle as CircleStyle, Fill, Stroke } from 'ol/style.js';
import Overlay from 'ol/Overlay.js';
import { toStringHDMS } from 'ol/coordinate.js';
import { fromLonLat, toLonLat } from 'ol/proj.js';
import $ from 'jquery'
import { unByKey } from 'ol/Observable.js';
import { getArea, getLength } from 'ol/sphere.js';;
import { LineString, Polygon } from 'ol/geom.js';
import Draw from 'ol/interaction/Draw.js';
import conmonMethods from '../common/js/commonMethods.js'
import {
equalTo as equalToFilter,
like as likeFilter,
and as andFilter
} from 'ol/format/filter.js';
import { WFS, GeoJSON } from 'ol/format.js';
import EqualTo from 'ol/format/filter/EqualTo';
import TileWMS from 'ol/source/TileWMS.js';
import { getWidth, getTopLeft } from 'ol/extent.js';
import { get as getProjection } from 'ol/proj.js';
// import WMTS from 'ol/source/WMTS.js';
import WMTSTileGrid from 'ol/tilegrid/WMTS.js';
import Intersects from 'ol/format/filter/Intersects';
import AMap from 'AMap'
/**
* 地图操作的主函数
*/
/**
* 初始化olMap对象
* 基础地图类
* @author 周祥毅
*/
class BaseMap {
//初始化class的时候,默认执行
constructor() {
this.map = null
return this.map
//初始化地图
//this.initMap(this.layers);
}
/**
* 初始化地图,传入参数为图层数组
* @param {*} layers
*/
initMap() {
// 创建地图
this.map = new Map({
// 让id为map的div作为地图的容器
target: 'map',
// 设置地图图层
layers: [
this.addTdTlayerWMTS('img_c', mapconfig.TDTtoken, 'img'),
//添加天地图矢量地图
this.addTdTlayerWMTS('vec_c', mapconfig.TDTtoken, 'vec'),
//添加标注
this.addTdTlayerWMTS('cva_c', mapconfig.TDTtoken, 'cva'),
// this.addTdTlayerWMTS('cva_w',mapconfig.TDTtoken,'cva'),
//绘制层
this.addVeclaysLayer()
],
// 设置显示地图的视图
view: new View({
//transform 进行投影转换,此处4326=>3857
// center: transform([113.732703, 34.812677], 'EPSG:4326', 'EPSG:3857'),
center: [113.732703, 34.812677],
// center:[],
projection: 'EPSG:4326',
zoom: 3
}),
controls: defaultControls({
zoom: false,
rotate: false,
attribution: false
})
});
}
/**
* @name addTdTlayer
* 加载天地图 xyz
* @author:周祥毅
* @param {String} lys
* @param {String} tk
* tk是天地图的密钥,请于天地图官网自行申请
* @return layer 返回一个layer
*/
addTdTlayer(lys, tk) {
const urls = `http://t{0-7}.tianditu.gov.cn/DataServer?T=${lys}&x={x}&y={y}&l={z}&tk=${tk}`
const layer = new TileLayer({
source: new XYZ({
url: urls
}),
name: lys
})
return layer
}
/**
* addTdTlayerWMTS
* 加载天地图 wmts
* @param {*} lys
* @param {*} tk
* @param {*} layertype
*/
addTdTlayerWMTS(lys, tk, layertype) {
var projection = getProjection("EPSG:4326");
var projectionExtent = projection.getExtent();
var size = getWidth(projectionExtent) / 256;
var resolutions = [];
for (var z = 2; z < 19; ++z) {//计算比例尺
resolutions[z] = size / Math.pow(2, z);
}
return new TileLayer({//矢量地图
source: new WMTS({
url: `http://t0.tianditu.gov.cn/${lys}/wmts?tk=${tk}`,//链接需要添加自己申请的密钥
layer: layertype,
style: "default",
matrixSet: "c",
format: "tiles",
wrapX: true,
tileGrid: new WMTSTileGrid({
origin: getTopLeft(projectionExtent),
//resolutions: res.slice(0, 15),
resolutions: resolutions,
matrixIds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
})
}),
name: lys
})
}
addVeclaysLayer() {
return new VectorLayer({
source: new VectorSource(),
style: new Style({
fill: new Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new Stroke({
color: '#ffcc33',
width: 2
}),
image: new CircleStyle({
radius: 7,
fill: new Fill({
color: '#ffcc33'
})
})
}),
name: 'drawfeature'
})
}
}
/**
* @author 周祥毅
* layer类
* geojson,ArcgisMapserver,(未来的GeoServer发布的地图服务)
* 注:目前还不知道如何添加单一图层
*/
class Layer {
constructor(map) {
this.baseMap = map
}
/**
* 添加Arcgis的地图服务
* @param {} url
* url是地图服务的地址
*/
addArcGisMapserver(url) {
//创建图层
let arcgisLayer = new TileLayer({
source: new TileArcGISRest({
url: url
})
})
//this.map.layers.push(arcgisLayer)
console.log(this.map)
//添加图层
this.baseMap['map'].addLayer(arcgisLayer)
console.log(this.baseMap['map'].layers)
}
addWMTSlayer() {
let geoserverlayer = new TileLayer({
extent: [-74.047185, 40.679648,
-73.90782, 40.882078],
source: new TileWMS({
url: 'http://localhost:9527/geoserver/tiger/wms',
params: {
'LAYERS': 'tiger:poly_landmarks',
'TILED': true,
},
serverType: 'geoserver',
projection: "EPSG:4326"
})
})
// this.baseMap['map'].addLayer(geoserverlayer)
this.baseMap['map'].addLayer(geoserverlayer)
var bounds = [-74.047185, 40.679648,
-73.90782, 40.882078];
//视角转移
this.baseMap['map'].getView().fit(bounds, this.baseMap['map'].getSize());
}
}
/**
* 点类
* @author 周祥毅
*/
class point {
constructor(map) {
this.baseMap = map
}
/**
* 添加点位
* @param data 传入的json数据
* @param layer 图层类型
*
*/
addPoint(data, layertype) {
const map = this.baseMap['map']
//数据处理
//当没有传入数据的时候
if (!data) {
console.log('请传入点位数据')
return
}
//当数据存在时,对其进行处理
let feature, geometry, iconurl, iconsize;
let features = []
//样式处理
if (layertype == 'air') {
//空气站点
//图标地址
iconurl = '/static/img/air-point.png'
iconsize = [18, 18]
} else if (layertype == 'pollute') {
//污染源站点
iconurl = '/static/img/pollute-point.png'
iconsize = [18, 18]
} else {
//默认设置
iconurl = '/static/img/default-point.png'
iconsize = [18, 25]
}
let iconStyle = new Style({
image: new Icon(({
size: iconsize,
src: iconurl
}))
});
for (let item of data) {
//新建点要素
debugger
const lon = Number(item.lon)
const lat = Number(item.lat)
//geometry = new Point(transform([lon, lat], 'EPSG:4326', 'EPSG:3857'), "XY")
geometry = new Point([lon, lat])
feature = new Feature(geometry);
//给feature赋予属性
feature.setProperties(item)
//设置点位样式
feature.setStyle(iconStyle);
//将点位依次传入数据容器
features.push(feature)
}
//新建数据源
const vectorSource = new VectorSource({
features: features
});
//更新图层的数据并重新渲染
//判断是否存在VectorLayer,存在则清空所有该图层数据源,并重新渲染
//获取所有的图层
const maplayers = map.getLayers()
console.log(maplayers)
let vector = maplayers.array_.filter((item) => {
//如果id存在pointlayer,则做处理
if (item.values_.id == 'pointlayer') {
return true
}
})
console.log(vector)
if (vector.length > 0) {
vector.source = []
vector.source = vectorSource
//重新渲染地图
map.render()
} else {
//不存在的时候创建新图层
vector = new VectorLayer({
id: 'pointlayer',
source: vectorSource
})
//在地图上添加此图层
map.addLayer(vector)
}
}
}
/**
* 地图事件
*/
class Map_Mouseover {
constructor(map) {
this.baseMap = map
}
addclickshowPop() {
const map = this.baseMap['map']
//创建弹窗框容器
var container = document.getElementById("popup");
var content = document.getElementById("popup-content");
var popupCloser = document.getElementById("popup-closer");
console.log(container)
//当新建Overlay后会自动删除该容器div在页面上
var overlayPop = new Overlay({
//设置弹出框的容器
element: container,
//是否自动平移,即假如标记在屏幕边缘,弹出时自动平移地图使弹出框完全可见
autoPan: true,
autoPanAnimation: {
duration: 250
}
});
map.on('click', function (e) {
//在点击时获取像素区域
var pixel = map.getEventPixel(e.originalEvent);
console.log(pixel)
//交叉区域事件
map.forEachFeatureAtPixel(pixel, function (feature) {
//coodinate存放了点击时的坐标信息
var coodinate = e.coordinate;
console.log(feature)
//设置弹出框内容,可以HTML自定义
//content.innerHTML = "<p>点位名称:" + feature.values_.SiteName + "</p>";
$("#popup .content .title span").html(feature.values_.SiteName)
content.innerHTML = `<iframe src="${feature.values_.Panelurl}?name=${feature.values_.SiteName}&id=${feature.values_.id}&${feature.values_.lon}&lat=${feature.values_.lat}" frameborder="0"></iframe>`;
//设置overlay的显示位置
overlayPop.setPosition(coodinate);
//显示overlay
map.addOverlay(overlayPop);
//显示容器,因为刚开始是隐藏的所以需要显示
$("#popup").show()
});
popupCloser.addEventListener('click', function () {
overlayPop.setPosition(undefined);
});
/**
* 为map添加鼠标移动事件监听,当指向标注时改变鼠标光标状态
*/
map.on('pointermove', function (e) {
var pixel = map.getEventPixel(e.originalEvent);
var hit = map.hasFeatureAtPixel(pixel);
map.getTargetElement().style.cursor = hit ? 'pointer' : '';
})
});
}
}
/**
* 地图工具栏类
*/
class Map_Tools {
constructor(map) {
this.baseMap = map
}
Measure(measureType) {
const map = this.baseMap['map']
//map.getOverlays().clear()
/**
* Currently drawn feature.
* @type {module:ol/Feature~Feature}
*/
var sketch;
/**
* The help tooltip element.
* @type {Element}
*/
var helpTooltipElement;
/**
* Overlay to show the help messages.
* @type {module:ol/Overlay}
*/
var helpTooltip;
/**
* The measure tooltip element.
* @type {Element}
*/
var measureTooltipElement;
/**
* Overlay to show the measurement.
* @type {module:ol/Overlay}
*/
var measureTooltip;
/**
* Message to show when the user is drawing a polygon.
* @type {string}
*/
var continuePolygonMsg = '继续点击绘制多边形';
/**
* Message to show when the user is drawing a line.
* @type {string}
*/
var continueLineMsg = '继续点击绘制线';
createMeasureTooltip();
createHelpTooltip();
/**
* Handle pointer move.
* @param {module:ol/MapBrowserEvent~MapBrowserEvent} evt The event.
*/
var pointerMoveHandler = function (evt) {
if (evt.dragging) {
return;
}
/** @type {string} */
var helpMsg = '请点击开始绘制';
if (sketch) {
var geom = (sketch.getGeometry());
if (geom instanceof Polygon) {
helpMsg = continuePolygonMsg;
} else if (geom instanceof LineString) {
helpMsg = continueLineMsg;
}
}
helpTooltipElement.innerHTML = helpMsg;
helpTooltip.setPosition(evt.coordinate);
helpTooltipElement.classList.remove('hidden');
};
map.on('pointermove', pointerMoveHandler);
map.getViewport().addEventListener('mouseout', function () {
helpTooltipElement.classList.add('hidden');
});
var draw;
var formatLength = function (line) {
var length = getLength(line);
var output;
if (length > 100) {
output = (Math.round(length / 1000 * 100) / 100) +
' ' + 'km';
} else {
output = (Math.round(length * 100) / 100) +
' ' + 'm';
}
return output;
};
var formatArea = function (polygon) {
var area = getArea(polygon);
var output;
if (area > 10000) {
output = (Math.round(area / 1000000 * 100) / 100) +
' ' + 'km<sup>2</sup>';
} else {
output = (Math.round(area * 100) / 100) +
' ' + 'm<sup>2</sup>';
}
return output;
};
var source;
// // var layer ;
// 获取存放feature的vectorlayer层。map初始化的时候可以添加好了
for (let layerTmp of map.getLayers().getArray()) {
if (layerTmp.get("name") == "drawfeature") {
source = layerTmp.getSource();
}
}
function addInteraction() {
var type = (measureType == 'area' ? 'Polygon' : 'LineString');
draw = new Draw({
source: source,
type: type,
style: new Style({
fill: new Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new Stroke({
color: 'rgba(0, 0, 0, 0.5)',
lineDash: [10, 10],
width: 2
}),
image: new CircleStyle({
radius: 5,
stroke: new Stroke({
color: 'rgba(0, 0, 0, 0.7)'
}),
fill: new Fill({
color: 'rgba(255, 255, 255, 0.2)'
})
})
})
});
map.addInteraction(draw);
var listener;
draw.on('drawstart',
function (evt) {
// set sketch
sketch = evt.feature;
/** @type {module:ol/coordinate~Coordinate|undefined} */
var tooltipCoord = evt.coordinate;
listener = sketch.getGeometry().on('change', function (evt) {
var geom = evt.target;
var output;
if (geom instanceof Polygon) {
output = formatArea(geom);
tooltipCoord = geom.getInteriorPoint().getCoordinates();
} else if (geom instanceof LineString) {
output = formatLength(geom);
tooltipCoord = geom.getLastCoordinate();
}
measureTooltipElement.innerHTML = output;
measureTooltip.setPosition(tooltipCoord);
});
}, this);
draw.on('drawend',
function () {
measureTooltipElement.className = 'tooltip tooltip-static';
measureTooltip.setOffset([0, -7]);
// unset sketch
sketch = null;
// unset tooltip so that a new one can be created
measureTooltipElement = null;
createMeasureTooltip();
unByKey(listener);
map.un('pointermove', pointerMoveHandler);
map.removeInteraction(draw);
helpTooltipElement.classList.add('hidden');
}, this);
}
// draw.on('drawend',
// function() {
// measureTooltipElement.className = 'tooltip tooltip-static';
// measureTooltip.setOffset([0, -7]);
// // unset sketch
// sketch = null;
// // unset tooltip so that a new one can be created
// measureTooltipElement = null;
// createMeasureTooltip();
// unByKey(listener);
// }, this);
// }
function createHelpTooltip() {
if (helpTooltipElement) {
helpTooltipElement.parentNode.removeChild(helpTooltipElement);
}
helpTooltipElement = document.createElement('div');
helpTooltipElement.className = 'tooltip hidden';
helpTooltip = new Overlay({
element: helpTooltipElement,
offset: [15, 0],
positioning: 'center-left'
});
map.addOverlay(helpTooltip);
}
function createMeasureTooltip() {
if (measureTooltipElement) {
measureTooltipElement.parentNode.removeChild(measureTooltipElement);
}
measureTooltipElement = document.createElement('div');
measureTooltipElement.className = 'tooltip tooltip-measure';
measureTooltip = new Overlay({
element: measureTooltipElement,
offset: [0, -15],
positioning: 'bottom-center'
});
map.addOverlay(measureTooltip);
}
// 量测调用
addInteraction();
}
Clear() {
const map = this.baseMap['map']
//获取绘制图层
const layerTmp = conmonMethods.getWantedLayer('drawfeature', map)
console.log(layerTmp)
//数据清空
layerTmp.setSource(null)
$(".tooltip").remove()
//获取查询图层
const layersearch = conmonMethods.getWantedLayer('searchfeature', map)
layersearch.setSource(null)
const layerTmps = conmonMethods.getWantedLayer('vec_c', map)
layerTmps.setVisible(true)
}
/**底图切换 */
Basemapchange(type) {
const map = this.baseMap['map']
const Vecbase = conmonMethods.getWantedLayer('vec_c', map)
const Imgbase = conmonMethods.getWantedLayer('img_c', map)
if (type == 'vector') {
Imgbase.setVisible(true)
Vecbase.setVisible(false)
} else {
Vecbase.setVisible(true)
Imgbase.setVisible(false)
}
}
location() {
const map = this.baseMap['map']
console.log(AMap)
var options = {
'showButton': false,//是否显示定位按钮
/* LT LB RT RB */
'buttonOffset': new AMap.Pixel(10, 20),//定位按钮距离对应角落的距离
'showMarker': false,//是否显示定位点
'markerOptions': {//自定义定位点样式,同Marker的Options
'offset': new AMap.Pixel(-18, -36),
},
'showCircle': false,//是否显示定位精度圈
}
AMap.plugin(["AMap.Geolocation"], function () {
var geolocation = new AMap.Geolocation(options);
geolocation.getCurrentPosition(function (status, result) {
if (status == "complete") {
let lon = result.position.lng
let lat = result.position.lat
// let pointxy = transform([lon, lat], 'EPSG:4326', 'EPSG:3857')
console.log(status)
console.log(result)
let Posname = result.formattedAddress;
map.getView().setCenter([lon, lat])
map.getView().setZoom(14)
let iconStyle = new Style({
image: new Icon(({
size: [18, 25],
src: '/static/img/default-point.png'
}))
});
let geometry = new Point([lon, lat])
let feature = new Feature(geometry);
let features = []
//设置点位样式
feature.setStyle(iconStyle);
features.push(feature)
//判断有没有图层,有的话清除
const layerlocation = conmonMethods.getWantedLayer('locationlayer', map)
if (typeof (layerlocation) != "undefined") {
console.log('进来了')
layerlocation.setSource(null)
layerlocation.setSource(new VectorSource({ features: features }))
} else {
let locationlayer = new VectorLayer({
style: function (feature) {
return feature.get('style');
},
source: new VectorSource({ features: features }),
name: 'locationlayer'
})
map.addLayer(locationlayer)
}
alert(`您当前的位置为${Posname}`)
}
});
//AMap.event.addListener(geolocation, 'complete', onComplete);
});
}
}
/**
* 查询类
*/
class Search {
constructor(map) {
this.baseMap = map
}
/**
* attrSearch
* @param {*} keys 关键字
* 属性查询
*/
attrSearch(keys) {
const map = this.baseMap['map']
//新建查询图层
let vectorSource = new VectorSource();
const vector = new VectorLayer({
source: vectorSource,
style: new Style({
stroke: new Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
}),
fill: new Fill({
color: 'rgba(255, 255, 0, 0.6)'
})
}),
name: 'searchfeature'
});
//添加到地图
map.addLayer(vector)
//查询地址与条件
var featureRequest = new WFS().writeGetFeature({
srsName: 'EPSG:4326',
featureNS: 'http://www.criskamap.com',//工作区url
featurePrefix: 'zxymap',//工作区名称
featureTypes: ['zxymap:w2016_china'],//需要查询的图层
outputFormat: 'application/json',
filter:
// likeFilter('CJMC', keys),
// equalTo('CJMC', keys)
//ol.format.filter.equalTo('CJMC',keys)
new EqualTo('MC', keys, false)
// equalToFilter('CJMC', keys)
//EqualTo('CJMC',keys,false)
});
fetch('/search/wfs', {
method: 'POST',
body: new XMLSerializer().serializeToString(featureRequest)
}).then(function (response) {
return response.json();
}).then(function (json) {
// console.log(json)
var features = new GeoJSON().readFeatures(json);
vectorSource.addFeatures(features);
//定位并放大到查询处
map.getView().fit(vectorSource.getExtent());
console.log(features)
});
fetch({
method: 'post',
url: 'http://localhost:9527/geoserver/' + 'wfs',
body: new XMLSerializer().serializeToString(featureRequest)
}).then(function (response) {
return response.json();
}).then(function (json) {
var features = new GeoJSON().readFeatures(json);
console.log(features)
});
}
geoSearch() {
const map = this.baseMap['map']
//新建查询图层
let vectorSource = new VectorSource();
const vector = new VectorLayer({
source: vectorSource,
style: new Style({
stroke: new Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
}),
fill: new Fill({
color: 'rgba(255, 255, 0, 0.6)'
})
}),
name: 'searchfeature'
});
//添加到地图
map.addLayer(vector)
var draw; // global so we can remove it later
function addInteraction() {
let source;
// // var layer ;
// 获取存放feature的vectorlayer层。map初始化的时候可以添加好了
for (let layerTmp of map.getLayers().getArray()) {
if (layerTmp.get("name") == "drawfeature") {
source = layerTmp.getSource();
}
}
let drawsearch = new Draw({
source: source,
type: 'Polygon'
});
console.log(drawsearch)
map.addInteraction(drawsearch);
drawsearch.on('drawend', function (e) {
console.log(e)
map.removeInteraction(draw);
//console.log(e.feature.geometry())
//查询地址与条件
let featureRequests = new WFS().writeGetFeature({
srsName: 'EPSG:4326',
featureNS: 'http://www.criskamap.com',//工作区url
featurePrefix: 'zxymap',//工作区名称
featureTypes: ['zxymap:w2016_china'],//需要查询的图层
outputFormat: 'application/json',
// geometryName: "the_geom",
filter: new Intersects('the_geom', e.feature.getGeometry())
});
fetch('/search/wfs', {
method: 'POST',
body: new XMLSerializer().serializeToString(featureRequests)
}).then(function (response) {
return response.json();
}).then(function (json) {
var features = new GeoJSON().readFeatures(json);
vectorSource.addFeatures(features);
//定位并放大到查询处
map.getView().fit(vectorSource.getExtent());
console.log(features)
});
}, this);
}
addInteraction()
}
}
export { BaseMap, Layer, point, Map_Mouseover, Map_Tools, Search }