|
|
|
|
@ -12,6 +12,10 @@ import { |
|
|
|
|
getArea, |
|
|
|
|
getLength |
|
|
|
|
} from 'ol/sphere.js'; |
|
|
|
|
import { |
|
|
|
|
LineString |
|
|
|
|
} from "ol/geom"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const serverUrl = 'https://app.hycdyzt.com'; |
|
|
|
|
const geoserverUrl = 'http://47.109.60.82:8080'; |
|
|
|
|
@ -31,6 +35,76 @@ const formatArea = function(polygon) { |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
}; |
|
|
|
|
const formatLength = function(line) { |
|
|
|
|
const length = getLength(line, { |
|
|
|
|
projection: 'EPSG:4326' |
|
|
|
|
}); |
|
|
|
|
let output; |
|
|
|
|
if (length > 100) { |
|
|
|
|
output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km'; |
|
|
|
|
} else { |
|
|
|
|
output = Math.round(length * 100) / 100 + ' ' + 'm'; |
|
|
|
|
} |
|
|
|
|
return output; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const generateStyle = (feature, { |
|
|
|
|
fillOpt, |
|
|
|
|
strokeOpt |
|
|
|
|
}) => { |
|
|
|
|
let area = 0; |
|
|
|
|
const geom = feature.getGeometry(); |
|
|
|
|
let lineStyle; |
|
|
|
|
if (geom.getType() === 'Polygon') { |
|
|
|
|
area = formatArea(geom); |
|
|
|
|
const lineString = new LineString(geom.getCoordinates()[0]); |
|
|
|
|
const length = formatLength(lineString); |
|
|
|
|
lineStyle = new Style({ |
|
|
|
|
geometry: lineString, |
|
|
|
|
text: new TextStyle({ |
|
|
|
|
text: length, |
|
|
|
|
"textBaseline": "middle", |
|
|
|
|
"font": "bold 10px/1 Verdana", |
|
|
|
|
"offsetX": 0, |
|
|
|
|
"offsetY": 0, |
|
|
|
|
fill: new Fill({ |
|
|
|
|
color: 'rgba(255, 255, 255, 1)', |
|
|
|
|
}), |
|
|
|
|
stroke: new Stroke({ |
|
|
|
|
width: 2, |
|
|
|
|
color: 'rgba(0, 0, 0, 1)', |
|
|
|
|
}), |
|
|
|
|
"placement": "line", |
|
|
|
|
"maxAngle": 0.7853981633974483, |
|
|
|
|
"overflow": true, |
|
|
|
|
"rotation": 0 |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
return [new Style({ |
|
|
|
|
fill: new Fill({ |
|
|
|
|
...fillOpt |
|
|
|
|
}), |
|
|
|
|
stroke: new Stroke({ |
|
|
|
|
width: 2, |
|
|
|
|
...strokeOpt |
|
|
|
|
}), |
|
|
|
|
text: geom.getType() !== 'Polygon' ? undefined : new TextStyle({ |
|
|
|
|
text: area, |
|
|
|
|
"textBaseline": "middle", |
|
|
|
|
"font": "bold 10px/1 Verdana", |
|
|
|
|
"offsetX": 0, |
|
|
|
|
"offsetY": 0, |
|
|
|
|
fill: new Fill({ |
|
|
|
|
color: 'rgba(0, 0, 0, 0.9)', |
|
|
|
|
}), |
|
|
|
|
"placement": "point", |
|
|
|
|
"maxAngle": 0.7853981633974483, |
|
|
|
|
"overflow": true, |
|
|
|
|
"rotation": 0 |
|
|
|
|
}) |
|
|
|
|
}), lineStyle].filter(item => item); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const startMeasure = (map, callback) => { |
|
|
|
|
map.removeLayer(map.getAllLayers().find(l => l.get('id') === 'draw-layer')); |
|
|
|
|
@ -40,31 +114,17 @@ const startMeasure = (map, callback) => { |
|
|
|
|
id: 'draw-layer', |
|
|
|
|
source: source, |
|
|
|
|
style: feature => { |
|
|
|
|
const area = formatArea(feature.getGeometry()); |
|
|
|
|
return new Style({ |
|
|
|
|
fill: new Fill({ |
|
|
|
|
return generateStyle(feature, { |
|
|
|
|
fillOpt: { |
|
|
|
|
color: 'rgba(255, 255, 255, 0.4)', |
|
|
|
|
}), |
|
|
|
|
stroke: new Stroke({ |
|
|
|
|
}, |
|
|
|
|
strokeOpt: { |
|
|
|
|
color: '#ffcc33', |
|
|
|
|
width: 2, |
|
|
|
|
}), |
|
|
|
|
text: new TextStyle({ |
|
|
|
|
text: area, |
|
|
|
|
"textBaseline": "middle", |
|
|
|
|
"font": "bold 10px/1 Verdana", |
|
|
|
|
"offsetX": 0, |
|
|
|
|
"offsetY": 0, |
|
|
|
|
fill: new Fill({ |
|
|
|
|
color: 'rgba(0, 0, 0, 0.9)', |
|
|
|
|
}), |
|
|
|
|
"placement": "point", |
|
|
|
|
"maxAngle": 0.7853981633974483, |
|
|
|
|
"overflow": true, |
|
|
|
|
"rotation": 0 |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const draw = new Draw({ |
|
|
|
|
@ -73,32 +133,16 @@ const startMeasure = (map, callback) => { |
|
|
|
|
stopClick: true, |
|
|
|
|
freehand: true, |
|
|
|
|
style: function(feature) { |
|
|
|
|
const area = formatArea(feature.getGeometry()); |
|
|
|
|
console.log(feature.getGeometry().getCoordinates()) |
|
|
|
|
return new Style({ |
|
|
|
|
fill: new Fill({ |
|
|
|
|
return generateStyle(feature, { |
|
|
|
|
fillOpt: { |
|
|
|
|
color: 'rgba(255, 255, 255, 0.2)', |
|
|
|
|
}), |
|
|
|
|
stroke: new Stroke({ |
|
|
|
|
}, |
|
|
|
|
strokeOpt: { |
|
|
|
|
color: 'rgba(0, 0, 0, 0.5)', |
|
|
|
|
lineDash: [10, 10], |
|
|
|
|
width: 2, |
|
|
|
|
}), |
|
|
|
|
text: new TextStyle({ |
|
|
|
|
text: area, |
|
|
|
|
"textBaseline": "middle", |
|
|
|
|
"font": "bold 10px/1 Verdana", |
|
|
|
|
"offsetX": 0, |
|
|
|
|
"offsetY": 0, |
|
|
|
|
fill: new Fill({ |
|
|
|
|
color: 'rgba(0, 0, 0, 0.9)', |
|
|
|
|
}), |
|
|
|
|
"placement": "point", |
|
|
|
|
"maxAngle": 0.7853981633974483, |
|
|
|
|
"overflow": true, |
|
|
|
|
"rotation": 0 |
|
|
|
|
}), |
|
|
|
|
});; |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
map.addInteraction(draw); |
|
|
|
|
@ -116,5 +160,8 @@ export default { |
|
|
|
|
globalMap, |
|
|
|
|
mgServerUrl, |
|
|
|
|
startMeasure, |
|
|
|
|
tempToken: '' |
|
|
|
|
tempToken: '', |
|
|
|
|
formatArea, |
|
|
|
|
formatLength, |
|
|
|
|
generateStyle |
|
|
|
|
} |