2013-04-24 56 views
-1

用户需要绘制圆形图形,在GWT封装中用于Openlayer,我已经使用DrawFeature,ModifyFeature控件,但无法找到用于绘制Circle的控件,或者带有示例欢迎的任何建议。例如:GWT Openlayer绘制圆形矢量功能

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

像这样的圈子的任何绘制功能?

回答

3

您希望为图层启用DrawFeature,或者您想在图层上添加一个圆圈?

  • 要启用DrawFeature为圆:

    //功能选项 DrawFeatureOptions drawFeatureOptions =新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);