简体   繁体   中英

Polygons are not shown on gmap

We have a problem creating polygons, as they do not appear on the map. We have followed this tutorial to implement our solution: http://googlemaps.subgurim.net/ejemplos/ejemplo_94100_Pol%C3%ADgonos.aspx

The application is developed in visual basic. Net framework version 4.

This is part of our code where we are generating the polygon on the map.

Dim latlng As New GLatLng(46, 21)
GMap1.setCenter(latlng, 4)

Dim puntos As New List(Of 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))

Dim poligono As New GPolygon(puntos, "557799", 3, 0.5, "237464", 0.5)
poligono.close()

GMap1.Add(poligono)

We thank who can provide help to solve this problem we have.

Attachment I leave a map image, which if located according to the coordinates given but considering that the polygon is not displayed.

It has something today with the Javascript array definition.

When you call GMap1.Add() you will notice that the polygon.ToString() causes a [[ in the resulting Javascript.

Replacing the [[ with a [ will solve your issue.

If you are using the Add overload accepting a polygon you will need to change your code a bit, to make use of the custom Javascript overload.

To reproduce the first polygon example located on their website at http://en.googlemaps.subgurim.net/ejemplos/ejemplo_94100_Pol%C3%ADgonos.aspx something along the following lines will do:

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();

var objJs = new StringBuilder();
objJs.Append("function addborder" + 0 + "()");
objJs.Append("{");
objJs.Append( poligono.ToString( GMap1.GMap_Id ) );
objJs.Replace("clickable:False", "clickable:false");//  ' Replace incorrect False statement
objJs.Append("}");

GMap1.Add( "addborder" + 0 + "();", true );
var objString = objJs.ToString();
var newstring = objString.Replace( "[[", "[" ).Replace( "]]", "]" );
GMap1.Add( newstring );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM