Anonymous user  |  Log in  |  Create Account

Lines

In order to add lines to our map, we will use GPolyline.

It is composed of 4 elements, 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 line.
  • weight: width of the line in pixels
  • opacity: double between 0 and 1. It defines the opacity of the line.
  • color: by default it is blue, and to change it we must give the string value of the color in hexadecimal or as a .net Color.
  • clickable: gets or sets if the Polyline is clickable or not.
  • geodesic: draws the line in a geodesic way.
NOTE: for Internet Explorer to work correctly if you are not using HTML5, 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));
GPolyline linea = new GPolyline(puntos, "FF0000", 2);
GMap1.addPolyline(linea);

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));
GPolyline linea2 = new GPolyline(puntos2);
linea2.weight = 4;
GMap1.addPolyline(linea2);

List<GLatLng> puntos3 = new List<GLatLng>();
puntos3.Add(latlng + new GLatLng(5, -20));
puntos3.Add(latlng + new GLatLng(5, 20));
GPolyline linea3 = new GPolyline(puntos3, Color.DarkViolet, 4);
linea3.geodesic = true;
GMap1.addPolyline(linea3);
Powered by Subgurim.NET