Creating rectangles, circles, polylines, and polygons in maps
The gmap
component supports the drawing of rectangles, circles, polylines, and polygons on the map canvas.
How to do it…
All drawings can be implemented as an instance of DefaultMapModel
, as stated here:
private MapModel rectangleModel = new DefaultMapModel(); private MapModel circleModel = new DefaultMapModel(); private MapModel polylineModel = new DefaultMapModel(); private MapModel polygonModel = new DefaultMapModel();
All models contain instances of LatLng
, where they define the points for the drawings. The rectangle model can be defined with two points, upper-left and lower-right, which are wrapped in an instance of LatLngBounds
. This is shown in the following code:
rectangleModel.addOverlay(new Rectangle(new LatLngBounds( new LatLng(41.073399, 29.051971), new LatLng(41.118418, 29.134026))));
The circle model accepts a point and the radius value to be defined:
Circle circle =new Circle(new LatLng(41.073399, 29.051971...