地图要素和几何图形
地图要素
要素是指表示地图上某些元素的基本构建块。要素可以包括点、线、面或其他能在地图上提供空间信息的几何图形。
要素可以有样式,并支持点击交互。要素在创建动态和交互式地图方面发挥着核心作用,开发人员可以通过地图要素有效地表示和操作地理数据。
GeoMap
具有下列地图要素:
MarkerFeature
标记要素表示使用预定义 PointGeometry 的一个标记元素。在地图组件中显示为一个标记图标。
下面的示例演示了如何在地图中创建并放置一个标记:
@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;
@Subscribe
public void onInit(final InitEvent event) {
vectorSource.addFeature(new MarkerFeature
(GeometryUtils.createPoint(40, 40)));
}
PointFeature
点要素表示使用预定义 PointGeometry 的一个点。在地图组件中显示为一个默认样式的点。更多内容请参阅 要素文档。
下面的示例演示了如何在地图中创建并放置一个点:
@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;
@Subscribe
public void onInit(final InitEvent event) {
vectorSource.addFeature(new PointFeature
(GeometryUtils.createPoint(13.046446, 47.797916)));
}
LineStringFeature
LineStringFeature
表示地图中的线性要素,一般是多段线。使用预定义的 LineStringGeometry。更多内容请参阅 要素文档。
下面的示例演示了如何在地图中创建并放置一条多段线:
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;
@Subscribe
public void onInit(final InitEvent event) {
vectorSource.addFeature(new LineStringFeature
(geometries.createLineString(new Coordinate[]{
new Coordinate(13, 20),
new Coordinate(13, 32),
new Coordinate(25, 17)})));
}
PolygonFeature
PolygonFeature
表示地图中的封闭几何图形,定义一个区域或地区。这个要素用一组互相连接的点组成一个封闭的图形,一般是多边形。使用预定义的 LineStringGeometry。更多内容请参阅 要素文档。
下面的示例演示了如何在地图中创建并放置一个多边形:
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@ViewComponent("geoMap.vector.vectorSource")
private VectorSource vectorSource;
@Subscribe
public void onInit(final InitEvent event) {
vectorSource.addFeature(new PolygonFeature
(geometries.createPolygon
(geometries.createLinearRing(new Coordinate[]{
new Coordinate(1.2457020544488762, 42.476628901048684),
new Coordinate(-0.054875980233204155, 52.77260344863316),
new Coordinate(29.858418817454655, 46.105591288830624),
new Coordinate(1.2457020544488762, 42.476628901048684),
}))));
}
MultiMarkerFeature
多标记要素表示使用 MultiPointGeometry 定义的的一组标记元素。在地图组件中展示一组标记。
下面的示例演示了如何在地图中创建并放置一个多标记:
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;
@Subscribe
public void onInit(final InitEvent event) {
MultiPoint multiMarkerPoint = geometries.createMultiPoint(new Point[]{
GeometryUtils.createPoint(25.235641166883457, 39.917862345662456),
GeometryUtils.createPoint(25.36806516981515, 37.08014053731078)});
vSource.addFeature(new MultiMarkerFeature(multiMarkerPoint));
}
MultiPointFeature
多点要素表示使用 MultiPointGeometry 定义的的一组点元素。在地图组件中展示一组默认样式的点。更多详情请参阅: Feature documentation。
下面的示例演示了如何在地图中创建并放置 MultiPointFeature
:
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;
@Subscribe
public void onInit(final InitEvent event) {
MultiPoint multiPoint = geometries.createMultiPoint(new Point[]{
GeometryUtils.createPoint(2.348582286131592, 48.84306719072006),
GeometryUtils.createPoint(-0.1503049900024013, 51.54906255948154)});
vSource.addFeature(new MultiPointFeature(multiPoint));
}
MultiLineStringFeature
MultiLineStringFeature
表示地图上的线段,由一组多段线构成。MultiLineStringFeature
使用预定义的 MultiLineStringGeometry。更多详情请参阅: Feature documentation。
下面的示例演示了如何在地图中创建并放置 MultiLineStringFeature
:
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;
@Subscribe
public void onInit(final InitEvent event) {
LineString lineString1 = geometries.createLineString(new Coordinate[]{
new Coordinate(37.59610278959945, 55.75230701125054),
new Coordinate(24.94409456852425, 60.18627418174103),
new Coordinate(12.483009200616205, 41.87228189777008)});
LineString lineString2 = geometries.createLineString(new Coordinate[]{
new Coordinate(30.799901492251276, 36.89489780945887),
new Coordinate(-3.71329777467964, 40.4106248584977)});
MultiLineString multiLineString = geometries.createMultiLineString(
new LineString[]{lineString1, lineString2});
vSource.addFeature(new MultiLineStringFeature(multiLineString));
}
MultiPolygonFeature
MultiPolygonFeature
表示由一组多边形构成的元素。其中,每个多边形是由一组点定义的闭合图形,这些点通过预定义的 MultiPolygonGeometry 实现。更多详情请参阅: Feature documentation。
下面的示例演示了如何在地图中创建并放置 MultiPolygonFeature
:
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@ViewComponent("geoMap.vectorLayer.vSource")
private VectorSource vSource;
@Subscribe
public void onInit(final InitEvent event) {
Polygon polygon1 = geometries.createPolygon(
geometries.createLinearRing(new Coordinate[]{
new Coordinate(25.095057034220535, 31.6734818426374),
new Coordinate(25.095057034220535, 21.916591864189783),
new Coordinate(36.273764258555126, 21.916591864189783),
new Coordinate(31.711026615969566, 30.893621948904325),
new Coordinate(25.095057034220535, 31.6734818426374)}));
Polygon polygon2 = geometries.createPolygon(
geometries.createLinearRing(new Coordinate[]{
new Coordinate(26.836428848759905, 40.89954566030514),
new Coordinate(26.836428848759905, 35.71188725771292),
new Coordinate(45.08737941910209, 36.265661479563505),
new Coordinate(43.49042124419716, 41.4148387201449),
new Coordinate(26.836428848759905, 40.89954566030514)}));
MultiPolygon multiPolygon = geometries.createMultiPolygon(new Polygon[]
{polygon1, polygon2});
vSource.addFeature(new MultiPolygonFeature(multiPolygon));
}