|
@@ -71,7 +71,7 @@ export const getBaseDrawConfig = () => {
|
|
|
* @param arr > polyBorderType:styles为空的时候,Polygon的边框类型索引,默认0,实线,取globalLineDash数组索引
|
|
|
* @param arr > polyBorderDash:styles为空的时候,Polygon的边框类型,默认null,优先级比polyBorderType高
|
|
|
*/
|
|
|
-export const drawViews = (map, arr) => {
|
|
|
+export const drawViews = (map, arr, isAuto = true) => {
|
|
|
let _source
|
|
|
const realLayer = map.getLayers().getArray().filter(v => v.get(layerFlag[0]) === layerFlag[1])
|
|
|
if (realLayer[0]) {
|
|
@@ -86,6 +86,7 @@ export const drawViews = (map, arr) => {
|
|
|
map.addLayer(_vector);
|
|
|
}
|
|
|
_source.clear() // 清空标绘
|
|
|
+ const autoPosition: any = []
|
|
|
const features = arr.filter(v => {
|
|
|
try {
|
|
|
new format.WKT().readFeature(v.wkt)
|
|
@@ -97,6 +98,20 @@ export const drawViews = (map, arr) => {
|
|
|
}).map(v => {
|
|
|
const feat: any = new format.WKT().readFeature(v.wkt)
|
|
|
const type = feat.getGeometry().getType()
|
|
|
+ switch (type) {
|
|
|
+ case 'Point': autoPosition.push(feat.getGeometry().getCoordinates())
|
|
|
+ break
|
|
|
+ case 'LineString': autoPosition.push(...feat.getGeometry().getCoordinates())
|
|
|
+ break
|
|
|
+ case 'Polygon': autoPosition.push(...feat.getGeometry().getCoordinates()[0])
|
|
|
+ break
|
|
|
+ }
|
|
|
+ for (const [kVal, vVal] of Object.entries(v)) {
|
|
|
+ // @ts-ignore
|
|
|
+ if (vVal === null || vVal === undefined || (typeof vVal === 'string' && vVal.trim() === '') || (typeof vVal === 'object' && vVal?.length === 0)) {
|
|
|
+ delete v[kVal]
|
|
|
+ }
|
|
|
+ }
|
|
|
const {
|
|
|
textOffsetY = (type === 'Point' ? -30 : 0),
|
|
|
pointIcon, pointScale, pointOffset,
|
|
@@ -170,11 +185,14 @@ export const drawViews = (map, arr) => {
|
|
|
return feat
|
|
|
})
|
|
|
_source.addFeatures(features)
|
|
|
+ if (isAuto) {
|
|
|
+ getShapeView(map, autoPosition)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
let baseDrawTooltipElement;
|
|
|
let baseDrawHelpTooltipElement;
|
|
|
-export const drawEdits = (map, obj, emitWkt) => {
|
|
|
+export const drawEdits = (map, obj, emitWkt, isAuto = true) => {
|
|
|
return new Promise((resolve => {
|
|
|
if (!isValue(obj.textOffsetY)) {
|
|
|
obj.textOffsetY = (obj.featureType === 'Point' ? -30 : 0)
|
|
@@ -285,9 +303,6 @@ export const drawEdits = (map, obj, emitWkt) => {
|
|
|
}
|
|
|
if (!baseDrawTooltipElement) {
|
|
|
reset()
|
|
|
- if (obj.wkt) {
|
|
|
- drawViews(map, [obj])
|
|
|
- }
|
|
|
let _source
|
|
|
const realLayer = map.getLayers().getArray().filter(v => v.get(layerFlag[0]) === layerFlag[1])
|
|
|
if (realLayer[0]) {
|
|
@@ -302,6 +317,23 @@ export const drawEdits = (map, obj, emitWkt) => {
|
|
|
_vector.set(layerFlag[0], layerFlag[1])
|
|
|
map.addLayer(_vector);
|
|
|
}
|
|
|
+ if (obj.wkt) {
|
|
|
+ const feat: any = new format.WKT().readFeature(obj.wkt)
|
|
|
+ _source.addFeature(feat)
|
|
|
+ const autoPosition: any = []
|
|
|
+ const type = feat.getGeometry().getType()
|
|
|
+ switch (type) {
|
|
|
+ case 'Point': autoPosition.push(feat.getGeometry().getCoordinates())
|
|
|
+ break
|
|
|
+ case 'LineString': autoPosition.push(...feat.getGeometry().getCoordinates())
|
|
|
+ break
|
|
|
+ case 'Polygon': autoPosition.push(...feat.getGeometry().getCoordinates()[0])
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if (isAuto) {
|
|
|
+ getShapeView(map, autoPosition)
|
|
|
+ }
|
|
|
+ }
|
|
|
const modifyInteraction = new Modify({
|
|
|
source: _source,
|
|
|
});
|
|
@@ -401,7 +433,49 @@ export const drawEdits = (map, obj, emitWkt) => {
|
|
|
};
|
|
|
const addInteraction = () => {
|
|
|
const id = 'baseDrawName'
|
|
|
+ let drawLastPoint = ''
|
|
|
+ let drawLastPointTimer: any = null
|
|
|
+ let drawCircleDBClickTimer: any = null
|
|
|
const draw = new interaction.Draw({
|
|
|
+ stopClick: true,
|
|
|
+ condition: (e) => {
|
|
|
+ // 圆形单击即触发finishCondition,跳过
|
|
|
+ if (obj.featureType === 'Circle') {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ const str = e.coordinate.join(',')
|
|
|
+ let flag = true
|
|
|
+ // 进行延时判断,避免只要鼠标不移动,单击后间隔很久也会视为双击,
|
|
|
+ if (!drawLastPointTimer && str === drawLastPoint) {
|
|
|
+ flag = false
|
|
|
+ } else {
|
|
|
+ if (drawLastPointTimer) {
|
|
|
+ clearTimeout(drawLastPointTimer)
|
|
|
+ }
|
|
|
+ drawLastPoint = str
|
|
|
+ }
|
|
|
+ drawLastPointTimer = setTimeout(() => {
|
|
|
+ drawLastPointTimer = null
|
|
|
+ }, 1000)
|
|
|
+ return flag
|
|
|
+ },
|
|
|
+ finishCondition: (e) => {
|
|
|
+ if (obj.featureType !== 'Circle') {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ let flag = true
|
|
|
+ // 圆形进行双击延时监听判断
|
|
|
+ if (!drawCircleDBClickTimer) {
|
|
|
+ flag = false
|
|
|
+ }
|
|
|
+ if (drawCircleDBClickTimer) {
|
|
|
+ clearTimeout(drawCircleDBClickTimer)
|
|
|
+ }
|
|
|
+ drawCircleDBClickTimer = setTimeout(() => {
|
|
|
+ drawCircleDBClickTimer = null
|
|
|
+ }, 1000)
|
|
|
+ return flag
|
|
|
+ },
|
|
|
source: _source,//测量绘制层数据源
|
|
|
type: obj.featureType, //几何图形类型
|
|
|
// geometryFunction: typeSelect === 'rectangle' ? createBox() : null,
|
|
@@ -481,9 +555,11 @@ export const drawEdits = (map, obj, emitWkt) => {
|
|
|
// helpMsg = continueMsg; //绘制线时提示相应内容
|
|
|
// }
|
|
|
}
|
|
|
- baseDrawHelpTooltipElement.innerHTML = helpMsg; //将提示信息设置到对话框中显示
|
|
|
- helpTooltip.setPosition(evt.coordinate);//设置帮助提示框的位置
|
|
|
- baseDrawHelpTooltipElement.classList.remove('hidden');//移除帮助提示框的隐藏样式进行显示
|
|
|
+ if (baseDrawHelpTooltipElement) {
|
|
|
+ baseDrawHelpTooltipElement.innerHTML = helpMsg; //将提示信息设置到对话框中显示
|
|
|
+ helpTooltip.setPosition(evt.coordinate);//设置帮助提示框的位置
|
|
|
+ baseDrawHelpTooltipElement.classList.remove('hidden');//移除帮助提示框的隐藏样式进行显示
|
|
|
+ }
|
|
|
};
|
|
|
map.on('pointermove', pointerMoveHandler); //地图容器绑定鼠标移动事件,动态显示帮助提示框内容
|
|
|
//地图绑定鼠标移出事件,鼠标移出时为帮助提示框设置隐藏样式
|
|
@@ -506,4 +582,55 @@ export const drawEdits = (map, obj, emitWkt) => {
|
|
|
// }
|
|
|
})
|
|
|
}))
|
|
|
+}
|
|
|
+export const drawExit = (map) => {
|
|
|
+ if (baseDrawTooltipElement) {
|
|
|
+ baseDrawTooltipElement.parentNode?.removeChild?.(baseDrawTooltipElement);
|
|
|
+ baseDrawTooltipElement = null
|
|
|
+ }
|
|
|
+ if (baseDrawHelpTooltipElement) {
|
|
|
+ baseDrawHelpTooltipElement.parentNode?.removeChild?.(baseDrawHelpTooltipElement);
|
|
|
+ baseDrawHelpTooltipElement = null
|
|
|
+ }
|
|
|
+ const oldLayer = map.getLayers().getArray().filter(v => v.get(layerFlag[0]) === layerFlag[1])
|
|
|
+ if (oldLayer) {
|
|
|
+ map.removeLayer(oldLayer[0])
|
|
|
+ }
|
|
|
+ const oldDraw = map.getInteractions().getArray().filter(v => v.get(drawFlag[0]) === drawFlag[1])
|
|
|
+ if (oldDraw) {
|
|
|
+ map.removeInteraction(oldDraw[0])
|
|
|
+ }
|
|
|
+ const oldModify = map.getInteractions().getArray().filter(v => v.get(modifyFlag[0]) === modifyFlag[1])
|
|
|
+ if (oldModify) {
|
|
|
+ map.removeInteraction(oldModify[0])
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const getShapeView = (map, position, L = 600) => {
|
|
|
+ const center = extent.getCenter(extent.boundingExtent(position))
|
|
|
+ let x = 0
|
|
|
+ let y = 0
|
|
|
+ position.forEach(v => {
|
|
|
+ if (Math.abs(v[0] - center[0]) > x) {
|
|
|
+ x = Math.abs(v[0] - center[0])
|
|
|
+ }
|
|
|
+ if (Math.abs(v[1] - center[1]) > y) {
|
|
|
+ y = Math.abs(v[1] - center[1])
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const resolution = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)) / (L / document.body.clientWidth * document.body.clientHeight)
|
|
|
+ if (map) {
|
|
|
+ if (position.length > 1) {
|
|
|
+ map.getView().animate({
|
|
|
+ center, resolution
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ map.getView().animate({
|
|
|
+ center, zoom: 12
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ center, resolution
|
|
|
+ }
|
|
|
}
|