简体   繁体   English

如何在gwt-openlayers中绘制一个矩形?

[英]How can I draw a rectangle in gwt-openlayers?

I see that it is supported for the non-gwt version, here: http://openlayers.org/dev/examples/draw-feature.html (click on "draw box") 我看到非gwt版本支持它,在这里: http : //openlayers.org/dev/examples/draw-feature.html (单击“绘制框”)

However, I can not find a way to access this function via gwt-openlayers. 但是,我找不到通过gwt-openlayers访问此功能的方法。 I am using SmartGWT, but I don't think that matters. 我正在使用SmartGWT,但我认为这并不重要。

This is done using the DrawFeature control using a RegularPolygonHandler. 这是通过使用带有RegularPolygonHandler的DrawFeature控件完成的。

See this showcase : http://demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html?example=Draw%20Regular%20Polygon%20Example 查看此展示柜: http : //demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html? example= Draw%20Regular%20Polygon%20Example

The draw circle button below the map is actaully a toggle button. 地图下方的绘制圆圈按钮实际上是一个切换按钮。 When it is pressed in circles are drawn (which are actually polygons with 40 sides), and when it is not pressed in rectangles are drawn (which are actually polygons with 4 sides). 当按下时,将绘制圆形(实际上是具有40个边的多边形),当未按下时,将绘制矩形(实际上是具有4个边的多边形)。 So when the example is launched, just try to draw on the map and you will see rectangles are drawn. 因此,在启动示例时,只需尝试在地图上绘制,就会看到绘制了矩形。

This is the code you are interested in (for creating boxes) : 这是您感兴趣的代码(用于创建框):

final DrawFeature drawRegularPolygon = new DrawFeature(vectorLayer, new RegularPolygonHandler());
map.addControl(drawRegularPolygon);
drawRegularPolygon.activate();
RegularPolygonHandlerOptions options = new RegularPolygonHandlerOptions();
options.setSides(4);
((RegularPolygonHandler) drawRegularPolygon.getHandler()).setOptions(options);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM