When I do labeling, my polyline features will only work when it is in Google-Mercator projection. Anybody have the same experience? I use:
if (sf.ShapefileType == ShpfileType.SHP_POLYLINE) {
sf.Labels.Generate("[" + labelFiledName + “]”, tkLabelPositioning.lpFirstSegment,false);
But When I change the map projection before label, with this:
axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
axMap1.ZoomToLayer(layerHandle);
The map zoom to the original point (that is 0 and 0, in Atlantic Ocean right below central Africa). Even with the ZoomToLayer, it won’t change. Any ideas?
Add the shapefile to map, set:
axMap1.GrabProjectionFromData = true;
Then I have a button to createKMLFromShapefile, the input has to be lat, long. My shapefile is in WGS84, but the KML function reading shapefile based on the map projection, not by the shapefile internal projection( why?), so I have to reproject the map to WGS84 before doing the conversion.
axMap1.Projection = tkMapProjection.PROJECTION_WGS84;
Right after this code, the map is rezoomed and recentered to somewhere else, nowhere.
If I first set the map to WGS84, then reproject it to webMercator, it’ll zoom to the original point of the projection(in Atlantic ocean, right below Africa). What did I do wrong?
GrabProjectionFromData is intended to set the projection from the first layer added, if the map has no projection. Since you are pre-setting the Projection to Google Mercator, your call to GrabProjectionFromData has no effect, since the projection is already set.
As a result, when you add the Shapefile, it follows the ReprojectLayersOnAdding setting, and reprojects your shapefile into Google Mercator. So the createKMLFromShapefile is likely using the in-memory shapefile, which is no longer in WGS84, but Google Mercator.
Depending upon what you want to end up with, you have a couple choices.
Load your shapefile before setting the Projection. It will remain in WGS84. Then do your createKML call.
Another option may be to create your KML from the file-based shapefile rather than the in-memory shapefile. Then add it to the Google Mercator map afterwards, which will force a reprojection, which may be acceptable at this point. I don’t know if this a realistic option for you or not.
If you need the projection in Google Mercator (e.g for proper display of imagery), then perhaps it can be set after the fact (I’m not actually sure what will happen, i.e. what the affect will be on the already-added layers). You may have to call ReprojectShapefile on existing layers? I can’t fully advise on this since I have not tried it before (although others likely have). Please let us know how it goes.