Yale:
I am attaching my coe of how I am invoking the connection. I have switched to using a checkbox to toggle the google overlay on and off, and I am still getting the The remote server returned an error: (403) Forbidden error. I have verified that the network connection is correct, and I have only loaded less than 25 view of the google map overlay.
How do I trap this error, and how to I correct for it?
Elisa
public GoogleMapsOverlay googleoverlay;
public InMemoryFeatureLayer highlightDistance;
public InMemoryFeatureLayer highlightPoint;
public InMemoryFeatureLayer highlightNext;
public InMemoryFeatureLayer highlightLine;
public InMemoryFeatureLayer highlightAdd;
public InMemoryFeatureLayer highlightRemove;
public ShapeFileFeatureLayer roadsLayer;
public ShapeFileFeatureLayer highwayLayer;
public ShapeFileFeatureLayer resourceLayer;
public ShapeFileFeatureLayer errorLayer;
public GoogleMapsOverlay googleMapsOverlay;
public RectangleShape backExtent = new RectangleShape();
public RectangleShape roadextent = new RectangleShape();
public void LoadLayers()
{
//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 = new GoogleMapsOverlay();
googleMapsOverlay.MapType = GoogleMapsMapType.Hybrid;
winformsMap1.Overlays.Add("google",googleMapsOverlay);
//Projection to go from Geodetic (Longitude/Latitude) to Google Map projection (Spherical Mercator).
Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); //Geodetic projection (Longitude/Latitude).
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
ShapeFileFeatureLayer.BuildIndexFile(shapedir + "\\" + roadfile, shapedir + "\\" + roadfile.Replace(".shp", ".idx"),
"MAPVIEW", "OTHER", BuildIndexMode.Rebuild);
ShapeFileFeatureLayer.BuildIndexFile(shapedir + "\\" + viewfile, shapedir + "\\highway.idx",
"MAPVIEW", "HWY", BuildIndexMode.Rebuild);
ShapeFileFeatureLayer.BuildIndexFile(shapedir + "\\" + viewfile, shapedir + "\\resource.idx",
"MAPVIEW", "RESOURCE", BuildIndexMode.Rebuild);
roadsLayer = new ShapeFileFeatureLayer(shapedir + "\\" + roadfile, shapedir + "\\" + roadfile.Replace(".shp", ".idx"),ShapeFileReadWriteMode.ReadWrite);
roadsLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.MediumBlue, 2, false));
roadsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
roadsLayer.FeatureSource.Projection = proj4;
highwayLayer = new ShapeFileFeatureLayer(shapedir + "\\" + viewfile, shapedir + "\\highway.idx");
highwayLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Black, 3, false));
highwayLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highwayLayer.FeatureSource.Projection = proj4;
resourceLayer = new ShapeFileFeatureLayer(shapedir + "\\" + viewfile, shapedir + "\\resource.idx");
resourceLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.DarkGray, 1, false));
resourceLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
resourceLayer.FeatureSource.Projection = proj4;
ShapeFileFeatureLayer.BuildIndexFile( shapedir + "\\errors.shp", shapedir + "\\errors.idx",BuildIndexMode.Rebuild);
errorLayer = new ShapeFileFeatureLayer(shapedir + "\\errors.shp", ShapeFileReadWriteMode.ReadWrite);
errorLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle,
new GeoSolidBrush(GeoColor.StandardColors.Red), new GeoPen(GeoColor.StandardColors.Black), 6);
errorLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10;
errorLayer.ZoomLevelSet.ZoomLevel11.DefaultPointStyle = new PointStyle(PointSymbolType.Circle,
new GeoSolidBrush(GeoColor.StandardColors.Red), new GeoPen(GeoColor.StandardColors.Black), 8);
errorLayer.ZoomLevelSet.ZoomLevel11.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level13;
errorLayer.ZoomLevelSet.ZoomLevel14.DefaultPointStyle = new PointStyle(PointSymbolType.Circle,
new GeoSolidBrush(GeoColor.StandardColors.Red), new GeoPen(GeoColor.StandardColors.Black), 10);
errorLayer.ZoomLevelSet.ZoomLevel14.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
errorLayer.FeatureSource.Projection = proj4;
highlightLine = new InMemoryFeatureLayer();
highlightLine.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Green, 5, false);
highlightLine.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highlightAdd = new InMemoryFeatureLayer();
highlightAdd.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Blue, 6, false);
highlightAdd.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highlightRemove = new InMemoryFeatureLayer();
highlightRemove.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 6, false);
highlightRemove.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highlightPoint = new InMemoryFeatureLayer();
highlightPoint.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle,
new GeoSolidBrush(GeoColor.StandardColors.Green), new GeoPen(GeoColor.StandardColors.Black), 11);
highlightPoint.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highlightDistance = new InMemoryFeatureLayer();
highlightDistance.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle,
new GeoSolidBrush(GeoColor.StandardColors.Orange), new GeoPen(GeoColor.StandardColors.Black), 6);
highlightDistance.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highlightNext = new InMemoryFeatureLayer();
highlightNext.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Orange, 4, false);
highlightNext.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
staticOverlay.Layers.Add("roads", roadsLayer);
staticOverlay.Layers.Add("highway", highwayLayer);
staticOverlay.Layers.Add("resource", resourceLayer);
staticOverlay.Layers.Add("errors", errorLayer);
highlightOverlay.Layers.Add("HighlightNext", highlightNext);
highlightOverlay.Layers.Add("HighlightPoint", highlightPoint);
highlightOverlay.Layers.Add("HighlightLine", highlightLine);
highlightOverlay.Layers.Add("HighlightAdd", highlightAdd);
highlightOverlay.Layers.Add("HighlightRemove", highlightRemove);
highlightOverlay.Layers.Add("HighlightDistance", highlightDistance);
winformsMap1.Overlays.Add(staticOverlay); winformsMap1.Overlays.Add(highlightOverlay);
//Sets the extent of the map as the bounding box of the shapefile layer as projected (Google Map Spherical Mercator).
roadsLayer.Open(); roadextent = roadsLayer.GetBoundingBox(); roadsLayer.Close();
winformsMap1.CurrentExtent = roadextent;
backExtent = roadextent;
winformsMap1.Overlays.Remove(googleMapsOverlay);
winformsMap1.Refresh();
}
private void ckbGoogle_Click(object sender, EventArgs e)
{
if (ckbGoogle.Checked == true)
{
ckbGoogle.Text = "Remove Google Maps Overlay";
winformsMap1.Overlays.Add("google", googleMapsOverlay);
winformsMap1.Overlays.MoveToBottom(winformsMap1.Overlays.IndexOf(googleMapsOverlay));
winformsMap1.Refresh();
}
else
{
ckbGoogle.Text = "Add Google Maps Overlay";
winformsMap1.Overlays.Remove( googleMapsOverlay);
winformsMap1.Refresh();
}
}