Mapa de polilínea geográfica Angular
En el componente de mapa Angular, puede usar IgxGeographicPolylineSeriesComponent
para mostrar datos geoespaciales usando polilíneas en un contexto geográfico. Este tipo de serie geográfica se utiliza a menudo para representar carreteras o conexiones entre ubicaciones geográficas como ciudades o aeropuertos.
Angular Geographic Polyline Map Example
IgxGeographicPolylineSeriesComponent
funciona de manera muy similar a IgxGeographicShapeSeriesComponent
, excepto que los datos geoespaciales se representan con polilíneas en lugar de polígonos.
Data Requirements
De forma similar a otros tipos de series geográficas en el control, el IgxGeographicPolylineSeriesComponent
tiene la ItemsSource
propiedad que se puede enlazar a una matriz de objetos. Además, cada elemento de datos de este objeto debe tener una columna de datos que almacene una o varias formas mediante una matriz de matrices de objetos con valores x e y que representen ubicaciones geográficas. A continuación, esta columna de datos se asigna a la shapeMemberPath
propiedad. Utiliza IgxGeographicPolylineSeriesComponent
puntos de esta columna de datos asignados para trazar polígonos en el control.
Code Snippet
El siguiente código muestra cómo vincular IgxGeographicPolylineSeriesComponent
a ubicaciones de ciudades cargadas desde un archivo de forma usando IgxShapeDataSource
.
<div className="sampleRoot" >
<igx-geographic-map #map
width="700px"
height="500px"
zoomable="true"
>
</igx-geographic-map>
</div>
<ng-template let-series="series" let-item="item" #template>
<div>
<span>
{{item.country}} {{item.type}}
</span>
<br />
<span>
Length: {{item.length}} miles
</span>
</div>
</ng-template>
import { AfterViewInit, Component, EmbeddedViewRef, TemplateRef, ViewChild} from "@angular/core";
import { IgxShapeDataSource } from 'igniteui-angular-core';
import { IgxIgxGeographicMapComponent } from 'igniteui-angular-maps';
import { IgxGeographicPolylineSeriesComponent } from 'igniteui-angular-maps';
@Component({
selector: "app-map-geographic-shape-polyline-series",
styleUrls: ["./map-geographic-shape-polyline-series.component.scss"],
templateUrl: "./map-geographic-shape-polyline-series.component.html"
})
export class MapTypeShapePolylineSeriesComponent implements AfterViewInit {
@ViewChild ("map")
public map: IgxGeographicMapComponent;
@ViewChild("template")
public tooltip: TemplateRef<object>;
constructor() {
}
public ngAfterViewInit(): void {
this.map.windowRect = { left: 0.195, top: 0.325, width: 0.2, height: 0.1 };
const sds = new IgxShapeDataSource();
sds.shapefileSource = "/assets/Shapes/AmericanRoads.shp";
sds.databaseSource = "/assets/Shapes/AmericanRoads.dbf";
sds.dataBind();
sds.importCompleted.subscribe(() => this.onDataLoaded(sds, ""));
}
public onDataLoaded(sds: IgxShapeDataSource, e: any) {
const shapeRecords = sds.getPointData();
console.log("loaded /Shapes/AmericanRoads.shp " + shapeRecords.length);
const roadsUSA: any[] = [];
const roadsMEX: any[] = [];
const roadsCAN: any[] = [];
// filtering records of loaded shapefile
for (const record of shapeRecords) {
// reading field values loaded from DBF file
const type = record.fieldValues.RoadType;
const road = {
country: record.fieldValues.Country,
length: record.fieldValues.RoadLength / 10,
points: record.points,
type: type === 1 ? "Highway" : "Road"
};
// grouping road items by country names
if (type === 1 || type === 2) {
if (road.country === "USA") {
roadsUSA.push(road);
} else if (road.country === "MEX") {
roadsMEX.push(road);
} else if (road.country === "CAN") {
roadsCAN.push(road);
}
}
}
// creating polyline series for roads of each country
this.addSeriesWith(roadsCAN, "rgba(252, 32, 32, 0.9)");
this.addSeriesWith(roadsUSA, "rgba(3, 121, 231, 0.9)");
this.addSeriesWith(roadsMEX, "rgba(14, 194, 14, 0.9)");
}
public addSeriesWith(shapeData: any[], shapeBrush: string) {
const lineSeries = new IgxGeographicPolylineSeriesComponent ();
lineSeries.dataSource = shapeData;
lineSeries.shapeMemberPath = "points";
lineSeries.shapeFilterResolution = 2.0;
lineSeries.shapeStrokeThickness = 2;
lineSeries.shapeStroke = shapeBrush;
lineSeries.tooltipTemplate = this.tooltip;
this.map.series.add(lineSeries);
}
}
API References
IgxGeographicPolylineSeriesComponent
IgxGeographicShapeSeriesComponent
ItemsSource
IgxShapeDataSource