|
@@ -83,10 +83,7 @@ class ShipTrack {
|
|
|
this.pointLayer.setVisible(false)
|
|
|
this.directionLayer.setVisible(false)
|
|
|
}
|
|
|
- refreshStyle() {
|
|
|
- this.map.getLayers().getArray().filter(v => [this.uuid + '_direction', this.uuid + '_point'].includes(v.get('layerName'))).forEach(v => {
|
|
|
- this.map.removeLayer(v)
|
|
|
- })
|
|
|
+ getSimplifyData() {
|
|
|
const resolution = this.map.getView().getResolution()
|
|
|
let radio = (30 * resolution);
|
|
|
if (this.map.getView().getZoom() == this.map.getView().getMaxZoom()) {
|
|
@@ -94,14 +91,6 @@ class ShipTrack {
|
|
|
}
|
|
|
const simplifyGeom: any = new geom.LineString([...this.historyPointCoordinates, ...this.realPointCoordinates]).simplify(radio)
|
|
|
const simplifyCoor = simplifyGeom.getCoordinates()
|
|
|
- const trackFeat = this.trackLayer.getSource().getFeatures()[0]
|
|
|
- trackFeat.setGeometry(simplifyGeom)
|
|
|
- trackFeat.setStyle(new style.Style({
|
|
|
- stroke: new style.Stroke({
|
|
|
- color: this.color,
|
|
|
- width: 2,
|
|
|
- }),
|
|
|
- }))
|
|
|
const directionFeatures: any = []
|
|
|
const pointFeatures: any = []
|
|
|
simplifyCoor.forEach((v, i) => {
|
|
@@ -120,6 +109,21 @@ class ShipTrack {
|
|
|
feat.set('type_', 'track-point')
|
|
|
pointFeatures.push(feat)
|
|
|
});
|
|
|
+ return {simplifyGeom, pointFeatures, directionFeatures}
|
|
|
+ }
|
|
|
+ refreshStyle() {
|
|
|
+ this.map.getLayers().getArray().filter(v => [this.uuid + '_direction', this.uuid + '_point'].includes(v.get('layerName'))).forEach(v => {
|
|
|
+ this.map.removeLayer(v)
|
|
|
+ })
|
|
|
+ const {simplifyGeom, pointFeatures, directionFeatures} = this.getSimplifyData()
|
|
|
+ const trackFeat = this.trackLayer.getSource().getFeatures()[0]
|
|
|
+ trackFeat.setGeometry(simplifyGeom)
|
|
|
+ trackFeat.setStyle(new style.Style({
|
|
|
+ stroke: new style.Stroke({
|
|
|
+ color: this.color,
|
|
|
+ width: 2,
|
|
|
+ }),
|
|
|
+ }))
|
|
|
this.pointLayer = new layer.WebGLPoints({
|
|
|
zIndex: this.zIndex + 2,
|
|
|
source: new source.Vector({
|
|
@@ -163,33 +167,9 @@ class ShipTrack {
|
|
|
this.map.addLayer(this.directionLayer)
|
|
|
}
|
|
|
refreshData() {
|
|
|
- const resolution = this.map.getView().getResolution()
|
|
|
- let radio = (30 * resolution);
|
|
|
- if (this.map.getView().getZoom() == this.map.getView().getMaxZoom()) {
|
|
|
- radio = 0
|
|
|
- }
|
|
|
- const simplifyGeom: any = new geom.LineString([...this.historyPointCoordinates, ...this.realPointCoordinates]).simplify(radio)
|
|
|
- const simplifyCoor = simplifyGeom.getCoordinates()
|
|
|
+ const {simplifyGeom, pointFeatures, directionFeatures} = this.getSimplifyData()
|
|
|
const trackFeat = this.trackLayer.getSource().getFeatures()[0]
|
|
|
trackFeat.setGeometry(simplifyGeom)
|
|
|
- const directionFeatures: any = []
|
|
|
- const pointFeatures: any = []
|
|
|
- simplifyCoor.forEach((v, i) => {
|
|
|
- if (i > 0) {
|
|
|
- const last = simplifyCoor[i - 1]
|
|
|
- const dx = v[0] - last[0];
|
|
|
- const dy = v[1] - last[1];
|
|
|
- const rotation = Math.atan2(dy, dx) * -1;
|
|
|
- const directFeat = new format.WKT().readFeature(`POINT(${(v[0] + last[0]) / 2} ${(v[1] + last[1]) / 2})`)
|
|
|
- directFeat.set('rotation_', rotation)
|
|
|
- directionFeatures.push(directFeat)
|
|
|
- }
|
|
|
- const d = this.pointMap.get(`${v[0]}_${v[1]}`)
|
|
|
- const feat: any = new format.WKT().readFeature(`POINT(${v[0]} ${v[1]})`)
|
|
|
- feat.set('data_', d)
|
|
|
- feat.set('type_', 'track-point')
|
|
|
- pointFeatures.push(feat)
|
|
|
- });
|
|
|
this.pointLayer.getSource().clear()
|
|
|
this.pointLayer.getSource().addFeatures(pointFeatures)
|
|
|
this.directionLayer.getSource().clear()
|