agrobot_base/AgroBase/OperationControl/Mapas/Rendering/MapaBordaGnssRenderService.cs

261 lines
6.3 KiB
C#

using Mapsui;
using Mapsui.Layers;
using Mapsui.Nts;
using Mapsui.Projections;
using Mapsui.Styles;
using NetTopologySuite.Geometries;
using OperationControl.Mapas.Editing;
using Brush = Mapsui.Styles.Brush;
using Color = Mapsui.Styles.Color;
using Font = Mapsui.Styles.Font;
using Pen = Mapsui.Styles.Pen;
namespace OperationControl.Mapas.Rendering
{
public sealed class MapaBordaGnssRenderService
{
public const string NomeCamada =
"MapaBordaGnssEdicao";
public MemoryLayer CriarCamada(
MapaEstadoRecorte estado)
{
if (estado == null)
{
throw new ArgumentNullException(
nameof(estado)
);
}
return new MemoryLayer
{
Name =
NomeCamada,
Features =
CriarFeatures(
estado
)
};
}
public void AtualizarCamada(
MemoryLayer camada,
MapaEstadoRecorte estado)
{
if (camada == null)
{
throw new ArgumentNullException(
nameof(camada)
);
}
if (estado == null)
{
throw new ArgumentNullException(
nameof(estado)
);
}
camada.Features =
CriarFeatures(
estado
);
}
private static IEnumerable<IFeature>
CriarFeatures(
MapaEstadoRecorte estado)
{
var features =
new List<IFeature>();
if (
estado.Tipo !=
MapaTipoRecorte.BordaGnss
)
{
return features;
}
/*
* LINHA
*/
if (
estado.Pontos.Count >= 2
)
{
Coordinate[] coordenadas =
estado
.Pontos
.Select(
ponto =>
{
var mercator =
SphericalMercator
.FromLonLat(
ponto.X,
ponto.Y
);
return new Coordinate(
mercator.x,
mercator.y
);
}
)
.ToArray();
var featureLinha =
new GeometryFeature
{
Geometry =
new LineString(
coordenadas
)
};
featureLinha["Tipo"] =
"BordaGnss";
featureLinha.Styles.Add(
new VectorStyle
{
Line =
new Pen(
new Color(
0,
210,
255,
255
),
4
)
}
);
features.Add(
featureLinha
);
}
/*
* PONTOS
*/
for (
int i = 0;
i < estado.Pontos.Count;
i++)
{
Coordinate ponto =
estado.Pontos[i];
var mercator =
SphericalMercator
.FromLonLat(
ponto.X,
ponto.Y
);
var feature =
new PointFeature(
mercator.x,
mercator.y
);
feature["Tipo"] =
"PontoBordaGnss";
feature["Ordem"] =
i + 1;
feature["label"] =
(i + 1).ToString();
feature.Styles.Add(
new SymbolStyle
{
SymbolType =
SymbolType.Ellipse,
SymbolScale =
1.15,
Fill =
new Brush(
new Color(
0,
210,
255,
255
)
),
Outline =
new Pen(
Color.White,
2
)
}
);
feature.Styles.Add(
new LabelStyle
{
LabelColumn =
"label",
ForeColor =
Color.White,
BackColor =
null,
HorizontalAlignment =
LabelStyle
.HorizontalAlignmentEnum
.Center,
VerticalAlignment =
LabelStyle
.VerticalAlignmentEnum
.Center,
Font =
new Font
{
Size = 11
}
}
);
features.Add(
feature
);
}
return features;
}
}
}