-1

stackoverflow 用户,我需要绘制圆,在 Openlayer 的 GWT 包装器中,我使用了 DrawFeature、ModifyFeature 控件,但无法找到绘制圆的控件,或者任何带有示例的建议欢迎。例如:

import org.gwtopenmaps.openlayers.client.control.*;    
Vector vectorLayer = new Vector("Vector Layer");    
ModifyFeature mod = new ModifyFeature(vectorLayer);

像这样是圆的任何绘制功能吗?

4

1 回答 1

3

您想为圆启用 DrawFeature 还是想在您的图层上添加一个圆?

  • 要为圆启用 DrawFeature:

    // 特征选项 DrawFeatureOptions drawFeatureOptions = new DrawFeatureOptions();

    // Handler option for circle
    RegularPolygonHandlerOptions handlerOptions = new RegularPolygonHandlerOptions();
    // 30 side is ok for a circle
    handlerOptions.setSides(30);
    handlerOptions.setSnapAngle(0);
    handlerOptions.setIrregular(false);
    
    // Add the handler option to the DrawFeatureOptions
    drawFeatureOptions.setHandlerOptions(handlerOptions);
    
    // create the draw feature control
    DrawFeature drawCircleFeatureControl = new DrawFeature(geometryFeaturesLayer, new RegularPolygonHandler(),
            drawFeatureOptions);
    
    // Add the control to the map
    map.addControl(drawCircleFeatureControl);
    
  • 在图层上添加圆圈

在 openlayers 中有一个 javascript 方法: OpenLayers.Geometry.Polygon.createRegularPolygon 我无法在 GWT openlayers 中找到它,所以你必须调用 javascript 方法:

    /**
 * Create a regular polygon around a radius. Useful for creating circles and the like.
 * 
 * @param origin {OpenLayers.Geometry.Point} center of polygon.
 * @param radius {Float} distance to vertex, in map units.
 * @param sides {Integer} Number of sides. 20 approximates a circle.
 * @param rotation {Float} original angle of rotation, in degrees.
 * @return Polygon
 */
public static native JSObject jsCreateRegularPolygon(JSObject origin, Float radius, Integer sides, Float rotation)
/*-{
    return $wnd.OpenLayers.Geometry.Polygon.createRegularPolygon(origin, radius, sides, rotation);
}-*/;

然后从您的代码中调用它以创建您的圈子

JSObject polygonJSObject = jsCreateRegularPolygon(point, 100f, 30, 45f); // with 30 sides for a circle
Polygon circle = Polygon.narrowToPolygon(polygonJSObject);
于 2013-05-02T07:50:28.860 回答