|
@@ -30,9 +30,12 @@ import { getPointsCenter, mergeGeoJsonPolygons } from '@/utils/gisUtils';
|
|
|
import { Cluster } from 'ol/source';
|
|
|
import CircleStyle from 'ol/style/Circle';
|
|
|
import Overlay from 'ol/Overlay';
|
|
|
-import { Select } from 'ol/interaction';
|
|
|
+import { Draw, Select } from 'ol/interaction';
|
|
|
import { click } from 'ol/events/condition';
|
|
|
+import Circle from 'ol/geom/Circle';
|
|
|
+import { hexToRgba } from '@/utils';
|
|
|
|
|
|
+const tk = 'a8df87f1695d224d2679aa805c1268d9';
|
|
|
const commonUrl = import.meta.env.VITE_APP_BASE_API2 + 'api/oneShare/proxyHandler/gd/';
|
|
|
// proj4.defs('EPSG:4490', '+proj=longlat +ellps=GRS80 +no_defs +type=crs');
|
|
|
proj4.defs('EPSG:4490', 'GEOGCS["China Geodetic Coordinate System 2000",DATUM["China_2000",SPHEROID["CGCS2000",6378137,298.257222101,AUTHORITY["EPSG","1024"]],AUTHORITY["EPSG","1043"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4490"]]');
|
|
@@ -43,8 +46,8 @@ const projection = new Projection({
|
|
|
units: 'degrees',
|
|
|
axisOrientation: 'neu'
|
|
|
});
|
|
|
-projection.setExtent([-180, -90, 180, 90])
|
|
|
-projection.setWorldExtent([-180, -90, 180, 90])
|
|
|
+projection.setExtent([-180, -90, 180, 90]);
|
|
|
+projection.setWorldExtent([-180, -90, 180, 90]);
|
|
|
const projectionExtent = [-180, -90, 180, 90];
|
|
|
const size = getWidth(projectionExtent) / 256;
|
|
|
const resolutions = [];
|
|
@@ -66,6 +69,8 @@ export class olMap {
|
|
|
strokeStyle: 'solid'
|
|
|
};
|
|
|
private plot;
|
|
|
+ private drawVector;
|
|
|
+ private drawTool;
|
|
|
private vectorLayer;
|
|
|
// 边界遮罩图层
|
|
|
private maskLayer;
|
|
@@ -146,6 +151,7 @@ export class olMap {
|
|
|
options.onMarkerClick(extData);
|
|
|
} else {
|
|
|
// 聚合要素
|
|
|
+ this.select.getFeatures().clear();
|
|
|
const currentZoom = this.map.getView().getZoom();
|
|
|
this.map.getView().setZoom(currentZoom + 1);
|
|
|
const points = [];
|
|
@@ -160,8 +166,6 @@ export class olMap {
|
|
|
this.map.getView().setCenter(newFeature.geometry.coordinates);
|
|
|
event.selected = [];
|
|
|
}
|
|
|
- } else {
|
|
|
-
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -175,6 +179,8 @@ export class olMap {
|
|
|
await this.formatXml(layer.id, layer.minZoom, layer.maxZoom, layer.zIndex, layer.visible); // 等待当前 layer 处理完成
|
|
|
}
|
|
|
}
|
|
|
+ } else if (options.id === 'tianditu') {
|
|
|
+ await this.formatXml2();
|
|
|
} else if (options.id) {
|
|
|
// 如果 options.id 不是数组,但确实是一个图层,则直接处理
|
|
|
await this.formatXml(options.id, options.minZoom, options.maxZoom, options.zIndex, options.visible);
|
|
@@ -190,7 +196,30 @@ export class olMap {
|
|
|
this.options.onLoadCompleted(this.map);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ formatXml2() {
|
|
|
+ const baseUrl = 'https://t{0-7}.tianditu.gov.cn/';
|
|
|
+ const vecType = 'vec'; // 矢量图层类型
|
|
|
+ const projType = 'w'; // 投影类型:web mercator
|
|
|
+ const reqParams = {
|
|
|
+ SERVICE: 'WMTS',
|
|
|
+ REQUEST: 'GetTile',
|
|
|
+ VERSION: '1.0.0',
|
|
|
+ LAYER: '',
|
|
|
+ STYLE: 'default',
|
|
|
+ TILEMATRIXSET: projType,
|
|
|
+ FORMAT: 'tiles',
|
|
|
+ TILECOL: '{x}',
|
|
|
+ TILEROW: '{y}',
|
|
|
+ TILEMATRIX: '{z}',
|
|
|
+ tk: key,
|
|
|
+ };
|
|
|
+ const newParams = Object.assign({}, params, { LAYER: dataType });
|
|
|
+ let paramsStr = '';
|
|
|
+ for (let [k, v] of Object.entries(newParams)) {
|
|
|
+ paramsStr += `${k}=${v}&`;
|
|
|
+ }
|
|
|
+ return `${baseUrl}${dataType}_${projType}/wmts?${paramsStr.slice(0, -1)}`;
|
|
|
+ }
|
|
|
formatXml(code: string, minZoom?: number, maxZoom?: number, zIndex?: number, visible?: boolean) {
|
|
|
const xml = new WMTSCapabilities();
|
|
|
return this.getCapabilities(code).then((lists) => {
|
|
@@ -251,11 +280,13 @@ export class olMap {
|
|
|
fillOpacity: options.drawType === '1' ? 0 : 0.5,
|
|
|
strokeStyle: 'solid'
|
|
|
};
|
|
|
- // this.plot = new olPlot(this.map, {
|
|
|
- // zoomToExtent: true,
|
|
|
- // ...this.drawOptions
|
|
|
- // });
|
|
|
- // this.plot.plotDraw.on('drawEnd', this.onDrawEnd.bind(this));
|
|
|
+ // 创建矢量图层用于绘制
|
|
|
+ this.drawVector = new Vector({
|
|
|
+ source: new VectorSource({
|
|
|
+ features: []
|
|
|
+ })
|
|
|
+ });
|
|
|
+ this.map.addLayer(this.drawVector);
|
|
|
}
|
|
|
|
|
|
// 绘制结束事件
|
|
@@ -282,10 +313,54 @@ export class olMap {
|
|
|
this.plot.plotDraw.activate('FreePolygon');
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ // 空间分析绘制图形
|
|
|
+ drawGraphics2(newOptions: MouseTool) {
|
|
|
+ const typeList = {
|
|
|
+ circle: 'Circle',
|
|
|
+ // rectangle: 'Rectangle',
|
|
|
+ polygon: 'Polygon'
|
|
|
+ };
|
|
|
+ if (!!typeList[newOptions.graphicsType]) {
|
|
|
+ this.drawOptions = {
|
|
|
+ type: newOptions.graphicsType,
|
|
|
+ strokeColor: newOptions.color,
|
|
|
+ strokeOpacity: 1,
|
|
|
+ strokeWeight: 1,
|
|
|
+ fillColor: newOptions.color,
|
|
|
+ fillOpacity: newOptions.drawType === '1' ? 0 : 0.5,
|
|
|
+ strokeStyle: 'solid'
|
|
|
+ };
|
|
|
+ this.closeDraw();
|
|
|
+ // 创建绘制交互
|
|
|
+ const style = new Style({
|
|
|
+ stroke: new Stroke({
|
|
|
+ color: hexToRgba(this.drawOptions.strokeColor, this.drawOptions.strokeOpacity),
|
|
|
+ width: this.drawOptions.strokeWeight
|
|
|
+ }),
|
|
|
+ fill: new Fill({
|
|
|
+ color: hexToRgba(this.drawOptions.fillColor, this.drawOptions.fillOpacity)
|
|
|
+ })
|
|
|
+ });
|
|
|
+ this.drawTool = new Draw({
|
|
|
+ source: this.drawVector.getSource(),
|
|
|
+ type: typeList[newOptions.graphicsType],
|
|
|
+ style: style
|
|
|
+ });
|
|
|
+ // 添加绘制交互到地图
|
|
|
+ this.map.addInteraction(this.drawTool);
|
|
|
+ // 监听绘制结束事件
|
|
|
+ this.drawTool.on('drawend', (event) => {
|
|
|
+ const feature = event.feature;
|
|
|
+ // 获取几何对象
|
|
|
+ feature.setStyle(style);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
// 关闭绘制
|
|
|
closeDraw() {
|
|
|
- this.plot.plotDraw.deactivate();
|
|
|
+ if (!this.drawTool) return;
|
|
|
+ this.map.removeInteraction(this.drawTool);
|
|
|
+ // this.drawTool.abortDrawing();
|
|
|
}
|
|
|
|
|
|
// 切换图层
|
|
@@ -637,7 +712,7 @@ export class olMap {
|
|
|
zIndex: 99999,
|
|
|
strokeStyle: new Stroke({ // 用于绘制刻度线的样式
|
|
|
color: '#dcdcdc', // 线条颜色
|
|
|
- width: 1, // 线条宽度
|
|
|
+ width: 1 // 线条宽度
|
|
|
}),
|
|
|
lonLabelStyle: new Text({
|
|
|
font: '12px Calibri,sans-serif',
|
|
@@ -681,4 +756,7 @@ export class olMap {
|
|
|
getMap() {
|
|
|
return this.map;
|
|
|
}
|
|
|
+ getMouseTool() {
|
|
|
+ return this.drawTool;
|
|
|
+ }
|
|
|
}
|