地图要素和几何图形
GeoMap
具有下列地图要素:
MarkerFeature
标记要素表示使用预定义 PointGeometry 的一个标记元素。在地图组件中显示为一个标记图标。
下面的示例演示了如何在地图中创建并放置一个标记:
@ViewComponent
private GeoMap geoMap;
@Subscribe
public void onInit(final InitEvent event) {
VectorLayer vectorLayer = geoMap.getLayer("vector");
VectorSource vectorSource = vectorLayer.getSource();
addMarker(vectorSource);
}
private void addMarker(VectorSource vectorSource) {
MarkerFeature feature = new MarkerFeature(GeometryUtils.createPoint(40, 40));
vectorSource.addFeature(feature);
}
PointFeature
点要素表示使用预定义 PointGeometry 的一个点。在地图组件中显示为一个默认样式的点。更多内容请参阅 要素文档。
下面的示例演示了如何在地图中创建并放置一个点:
@ViewComponent
private GeoMap geoMap;
@Subscribe
public void onInit(final InitEvent event) {
VectorLayer vectorLayer = geoMap.getLayer("vector");
VectorSource vectorSource = vectorLayer.getSource();
addPoint(vectorSource);
}
protected void addPoint(VectorSource source) {
Point point = GeometryUtils.createPoint(13.046446, 47.797916);
source.addFeature(new PointFeature(point));
}
LineStringFeature
LineStringFeature
表示地图中的线性要素,一般是多段线。使用预定义的 LineStringGeometry。更多内容请参阅 要素文档。
下面的示例演示了如何在地图中创建并放置一条多段线:
@ViewComponent
private GeoMap geoMap;
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@Autowired
private Notifications notifications;
@Subscribe
public void onInit(final InitEvent event) {
VectorLayer vectorLayer = geoMap.getLayer("vector");
VectorSource vectorSource = vectorLayer.getSource();
addLineString(vectorSource);
}
private void addLineString(VectorSource vectorSource) {
LineString lineString = geometries.createLineString(new Coordinate[]{
new Coordinate(13, 20),
new Coordinate(13, 32),
new Coordinate(25, 17)});
LineStringFeature feature = new LineStringFeature(lineString);
vectorSource.addFeature(feature);
}
PolygonFeature
PolygonFeature
表示地图中的封闭几何图形,定义一个区域或地区。这个要素用一组互相连接的点组成一个封闭的图形,一般是多边形。使用预定义的 LineStringGeometry。更多内容请参阅 要素文档。
下面的示例演示了如何在地图中创建并放置一个多边形:
@ViewComponent
private GeoMap geoMap;
private final GeometryFactory geometries = GeometryUtils.getGeometryFactory();
@Autowired
private Notifications notifications;
@Subscribe
public void onInit(final InitEvent event) {
VectorLayer vectorLayer = geoMap.getLayer("vector");
VectorSource vectorSource = vectorLayer.getSource();
addPolygon(vectorSource);
}
private void addPolygon(VectorSource vectorSource) {
LinearRing shell = 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),
});
PolygonFeature feature = new PolygonFeature(geometries.createPolygon(shell));
vectorSource.addFeature(feature);
}
本页是否有帮助?
感谢您的反馈