Google Maps Subgurim - Polygons are not working an

2020-06-29 08:01发布

问题:

I'm developing a Geolocalisation application based on ASP.NET and Google Maps Subgurim .

However , since this morning , the Polygons on my application stop showing .

I thought it was my code , until i saw that the polygons and the official website are not working themself .

Official Example of Polygon Has anyone an idea why it stoped ? Or even a solution ? I don't know how to contact Subgurim ...

( Also if you inspect page with subgurim control , the javascript return this error "Uncaught InvalidValueError: at index 0: not a LatLng or LatLngLiteral: in property lat: not a number")

EDIT : I've changed all the "GPolygon" to "GPolyline" , it works fine . But it will be impossible to fill the GPolyLine they can only make up by showing the contours of an area .

回答1:

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