175 lines
3.9 KiB
C#
175 lines
3.9 KiB
C#
using Mapsui;
|
|
using Mapsui.Layers;
|
|
using Mapsui.Nts;
|
|
using Mapsui.Projections;
|
|
using Mapsui.Styles;
|
|
using NetTopologySuite.Geometries;
|
|
using OperationControl.Mapas.Models;
|
|
using Color = Mapsui.Styles.Color;
|
|
using Pen = Mapsui.Styles.Pen;
|
|
|
|
namespace OperationControl.Mapas.Rendering
|
|
{
|
|
public sealed class MapaPredicaoMpcRenderService
|
|
{
|
|
public const string NomeCamada =
|
|
"MapaPredicaoMpcNova";
|
|
|
|
|
|
public MemoryLayer CriarCamada(
|
|
MapaEstadoMovimento estado)
|
|
{
|
|
if (estado == null)
|
|
{
|
|
throw new ArgumentNullException(
|
|
nameof(estado)
|
|
);
|
|
}
|
|
|
|
|
|
return new MemoryLayer
|
|
{
|
|
Name = NomeCamada,
|
|
Features =
|
|
CriarFeatures(
|
|
estado
|
|
),
|
|
Style = null
|
|
};
|
|
}
|
|
|
|
|
|
public void AtualizarCamada(
|
|
MemoryLayer camada,
|
|
MapaEstadoMovimento estado)
|
|
{
|
|
if (camada == null)
|
|
{
|
|
throw new ArgumentNullException(
|
|
nameof(camada)
|
|
);
|
|
}
|
|
|
|
if (estado == null)
|
|
{
|
|
throw new ArgumentNullException(
|
|
nameof(estado)
|
|
);
|
|
}
|
|
|
|
|
|
camada.Features =
|
|
CriarFeatures(
|
|
estado
|
|
);
|
|
}
|
|
|
|
|
|
private static List<IFeature>
|
|
CriarFeatures(
|
|
MapaEstadoMovimento estado)
|
|
{
|
|
var features =
|
|
new List<IFeature>();
|
|
|
|
|
|
foreach (
|
|
var movimento
|
|
in estado.Rovers)
|
|
{
|
|
if (
|
|
movimento.Predicao == null ||
|
|
movimento.Predicao.Count < 2
|
|
)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
var coordenadas =
|
|
new List<Coordinate>();
|
|
|
|
|
|
foreach (
|
|
var ponto
|
|
in movimento.Predicao)
|
|
{
|
|
var mercator =
|
|
SphericalMercator
|
|
.FromLonLat(
|
|
ponto.Longitude,
|
|
ponto.Latitude
|
|
);
|
|
|
|
|
|
coordenadas.Add(
|
|
new Coordinate(
|
|
mercator.x,
|
|
mercator.y
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
if (
|
|
coordenadas.Count < 2
|
|
)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
|
|
var feature =
|
|
new GeometryFeature
|
|
{
|
|
Geometry =
|
|
new LineString(
|
|
coordenadas
|
|
.ToArray()
|
|
)
|
|
};
|
|
|
|
|
|
feature["RoverId"] =
|
|
movimento.RoverId;
|
|
|
|
feature["Tipo"] =
|
|
"Predict";
|
|
|
|
|
|
feature.Styles.Add(
|
|
CriarEstilo()
|
|
);
|
|
|
|
|
|
features.Add(
|
|
feature
|
|
);
|
|
}
|
|
|
|
|
|
return features;
|
|
}
|
|
|
|
|
|
private static VectorStyle
|
|
CriarEstilo()
|
|
{
|
|
return new VectorStyle
|
|
{
|
|
Line =
|
|
new Pen
|
|
{
|
|
Color =
|
|
Color.Lime,
|
|
|
|
Width =
|
|
2,
|
|
|
|
PenStyle =
|
|
PenStyle.Dash
|
|
}
|
|
};
|
|
}
|
|
}
|
|
} |