ThinkGeo.com    |     Documentation    |     Premium Support

Shape File on Google Map Layer

I took the version 9 example of having a shape file overlayed on a google map and coverted it to use MapSuite v10. In addition , I would like to project google maps to the shapefile’s projection. When I run this code however I get a undecipherable error message.

Here is the code that I used and modified from the example

        //We need to set the map unit to meter because we are using Google Map Spherical Mercator projection.
        winformsMap1.MapUnit = GeographyUnit.Meter;

        winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

        //Sets Google Map as the background map.
        GoogleMapsOverlay googleMapsOverlay = new GoogleMapsOverlay();

        winformsMap1.Overlays.Add(googleMapsOverlay);

        // setup proj for google

        Proj4Projection calproj4 = new Proj4Projection();
        string projName = @"..\..\Data\CA_Boundary_WGS84_UTM11N.prj";
        string prjFileText = System.IO.File.ReadAllText(projName);

        calproj4.InternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); //Geodetic projection (Longitude/Latitude).
        calproj4.ExternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(prjFileText);
        googleMapsOverlay.ProjectionFromSphericalMercator = calproj4;






        ShapeFileFeatureLayer calShapeLayer = new ShapeFileFeatureLayer(@"..\..\Data\CA_Boundary_WGS84_UTM11N.shp");
        calShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.StandardColors.Red, GeoColor.StandardColors.Black, 9);
        calShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateMaskTextStyle("NAME", new GeoFont("Arial", 10, DrawingFontStyles.Bold),
        new GeoSolidBrush(GeoColor.StandardColors.Black), new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.LightGoldenrodYellow)), 13, 0);
        calShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
        calShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        //Sets the projection to the shapefile layer.
        //calShapeLayer.FeatureSource.Projection = proj4;



        LayerOverlay staticOverlay = new LayerOverlay();
        staticOverlay.Layers.Add("California", calShapeLayer);

        winformsMap1.Overlays.Add(staticOverlay);

        //Sets the extent of the map as the bounding box of the shapefile layer as projected (Google Map Spherical Mercator).
        calShapeLayer.Open();
        winformsMap1.CurrentExtent = calShapeLayer.GetBoundingBox();
        calShapeLayer.Close();

        winformsMap1.Refresh();

Error I get is

{“The type initializer for ‘fSQ=.8EU=’ threw an exception.”}

Hi Suresh,

Please make sure something as below:

  1. Upgrade all packages to the latest version of V10

  2. Please remove shape file and still keep the GoogleOverlay and the reprojection to see whether it still can be thrown

Please let us know the test result because it looks we don’t met this exception today.

Regards,

Ethan

I get this new exception , when I remove the shape file or keep it there.

The remote server returned an error: (403) Forbidden.
this happens on the winformsMap1.Refresh().

Hi Suresh,

You need provide your API key and make sure you hadn’t excess the limitation of tile request number.

You can view the Google’s documentation for more detail information.

Regards,

Ethan

This works when I use the 9 version of the library without a key. I just upgraded the sample to use version 10 but the error just showed up , it was working before and reviewing google, there is no way I made 50k requests.

Please advise.

Thanks,
Suresh

Hi Suresh,

It looks the request have to attach the key for Google now, so please apply a key from Google for free and try that again.

Regards,

Ethan