javagwtgwt-rpcgwt-openlayers

GWT Openlayer draw circle vector feature


stackoverflow users, I need to draw circle, in GWT wrapper for Openlayer, I have used DrawFeature, ModifyFeature controls, but not able to find control for drawing Circle, or any suggestions with example welcome. For example:

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

Like this is the any Draw feature for circle?


Solution

  • You want to enable DrawFeature for circle or you want to add a circle on your Layer ?

    In openlayers there is a javascript method : OpenLayers.Geometry.Polygon.createRegularPolygon I haven't be able to find it in GWT openlayers, so you had to call the javascript method :

        /**
     * 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);
    }-*/;
    

    Then call it from your code in order to create your circle

    JSObject polygonJSObject = jsCreateRegularPolygon(point, 100f, 30, 45f); // with 30 sides for a circle
    Polygon circle = Polygon.narrowToPolygon(polygonJSObject);