Help us translate this website and improve this translation and earn free licenses!
Anonymous user  |  Log in  |  Create Account

Polygons

Creating polygons in our maps is very simple with the class "GPolygon". The effect is very similar to the class "GPolyline", with the difference being the GPolygon fills up the interior with the color we choose. It has 6 properties, of which only the first is mandatory:
  • points: generic listing of points (of the GLatLng type). It is the most important part because it will define the layout of the polygon.
  • strokeWeight: width of the line in pixels.
  • strokeOpacity: double between 0 and 1. It defines the opacity of the line.
  • strokeColor: by default it is blue, and if we want to change it we must give the hexadecimal color code.
  • fillColor: color of the inner filling of the polygon. We must give it the hexadecimal color code.
  • fillOpacity: double between 0 and 1. It defines the opacity of the filling of the polygon.
  • clickable: gets or sets if the polygon is clickable.
In addition, we have added two interesting methods to consider:
  • close(): independently of how the points of the polygon are formed, this method will close it, so that the first point agrees with the last one.
  • createPolygon(GLatLng center, int sides, double radius): What this function does is create a polygon on the basis of its initial parameters:
    • center: center of the polygon.
    • sides: sides of the polygon. From 20 it resembles a circle.
    • radius: geographic degrees of radius.
    • inclination: inclination of the first point. It is a double expressed in radians. Its value by default is PI/4.
    It is possible to emphasize polygons based on geographic points. For example, if we created a polygon of 4 degrees it will not be a perfect square on the screen, but a polygon with 4 sides whose distance between the center is the same. Therefore, the more to the poles, the more "deformed" the square will be, and the more to the equator, the more "perfect" the picture will be.
NOTE: for Internet Explorer to work correctly, you must add to the following attribute to your HTML tag:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">




Code.aspx
<cc1:GMap ID="GMap1" runat="server" />
Code.aspx.cs
GLatLng latlng = new GLatLng(46, 21);
GMap1.setCenter(latlng, 4);

List<GLatLng> puntos = new List<GLatLng>();
puntos.Add(latlng + new GLatLng(0, 8));
puntos.Add(latlng + new GLatLng(-0.5, 4.2));
puntos.Add(latlng);
puntos.Add(latlng + new GLatLng(3.5, -4));
puntos.Add(latlng + new GLatLng(4.79, +2.6));
GPolygon poligono = new GPolygon(puntos, "557799", 3, 0.5, "237464", 0.5);
poligono.close();
GMap1.Add(poligono);

List<GLatLng> puntos2 = new List<GLatLng>();
puntos2.Add(latlng + new GLatLng(5, -8));
puntos2.Add(latlng + new GLatLng(5, -6));
puntos2.Add(latlng + new GLatLng(5, -4));
puntos2.Add(latlng);
puntos2.Add(latlng + new GLatLng(-5, 0));
GPolygon poligono2 = new GPolygon(puntos2, "000000", 3, 1, "654321", 1);
GMap1.addPolygon(poligono2);

GPolygon poligono3 = new GPolygon(new List<GLatLng>(), "00ff00", 3, 0, "ff0044", 0);
poligono3.createPolygon(latlng + new GLatLng(-6, -7.5), 7, 4, Math.PI /3);
GMap1.addPolygon(poligono3);
Powered by Subgurim.NET