ThinkGeo.com    |     Documentation    |     Premium Support

Working in GoogleMaps with Projections Adjustments

Hi, so I'd like to be able to work in Google maps but use longitude and latitude coordinates. I've achieved this to a certain degree by creating inmemoryfeaturelayers and adding shapes to the layer. Then changing the projection of the layer to the googlemaps projection. This works if I have world map kit displayed and then reload google maps, but this does not work is I have google maps loaded and want to create a new point, or change the coordinates of a currently existing point. When I try all that happens is the point is placed at the centre of the map. 


What I've done is:


create a googlemapsoverlay and added it to the winformsmap

create a inmemoryfeature layer and set it's projection to the google projection

create a button which will add a point onto the inmemoryfeature layer

start debugging the form 

and when I press the button the point is placed at 0,0 instead of the correct coordinates


Funny thing is, if I create and upload the point before uploading google maps it works. 



Gary,


  Thank you for the description of your problem. What I would do, I would do the projection conversion at the level of the X and Y values of the point, instead of setting the projection at the level of the InMemoryFeatureLayer. I have below some sample code where you set the point at the location Lat 46 N, Long 80 W and by clicking the button the point is placed at Lat 47 N, Long 73 W. This code is at least going to get you going in your project. So you can use that method. In the meantime, I am going to ask the Development team if there is a preferred way to accomplish that task. Thank you.



{
    winformsMap1.MapUnit = GeographyUnit.Meter;

    GoogleMapsOverlay googleMapsOverlay = new GoogleMapsOverlay();
    googleMapsOverlay.MapType = GoogleMapsMapType.RoadMap;

    winformsMap1.Overlays.Add(googleMapsOverlay);

    Proj4Projection proj4 = new Proj4Projection();
    proj4.InternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
    proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

    InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
            
    inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle
                                                                        (GeoColor.SimpleColors.Red, 12, GeoColor.SimpleColors.Black);
    inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

    proj4.Open();
    PointShape pointShape = (PointShape)proj4.ConvertToExternalProjection(new PointShape(-80, 46));
    proj4.Close();

    inMemoryFeatureLayer.InternalFeatures.Add("MyPoint", new Feature(pointShape));

    LayerOverlay dynamicLayerOverlay = new LayerOverlay();
    dynamicLayerOverlay.Layers.Add("MyInMemoryFeatureLayer", inMemoryFeatureLayer);

    winformsMap1.Overlays.Add("MyDynamicLayerOverlay", dynamicLayerOverlay);

    winformsMap1.CurrentExtent = new RectangleShape(-10000000, 7000000, -6000000, 4000000);

    winformsMap1.Refresh();

}

private void button1_Click(object sender, EventArgs e)
{
    LayerOverlay dynamicLayerOverlay = (LayerOverlay)winformsMap1.Overlays["MyDynamicLayerOverlay"];
    InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicLayerOverlay.Layers["MyInMemoryFeatureLayer"];

    PointShape pointShape = (PointShape)inMemoryFeatureLayer.InternalFeatures["MyPoint"].GetShape();

    Proj4Projection proj4 = new Proj4Projection();
    proj4.InternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
    proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();

    proj4.Open();
    Vertex vertex = proj4.ConvertToExternalProjection(-73, 47);
    proj4.Close();

    pointShape.X = vertex.X;
    pointShape.Y = vertex.Y;
    pointShape.Id = "MyPoint";

    inMemoryFeatureLayer.Open();
    inMemoryFeatureLayer.EditTools.BeginTransaction();
    inMemoryFeatureLayer.EditTools.Update(pointShape);
    inMemoryFeatureLayer.EditTools.CommitTransaction();
    inMemoryFeatureLayer.Close();

    winformsMap1.Refresh(dynamicLayerOverlay);
}