ThinkGeo.com    |     Documentation    |     Premium Support

MapShapeLayer and mixed projections

I am using the MapShapeLayer from the MapShapes sample. I would like to use the 4236 projection for the layer. However, my base layer is VirtualEarth which uses a different projection. On the web edition discussion forum there is a thread talking about how you can set the FeatureSource.Projection of a layer in order to allow a mixture of projections on the same map. Does this apply to the MapShapeLayer, and what do I need to do specifically to make this work for the MapShapeLayer?


Thanks!



Gregory,


If I am not misunderstanding something, what you are trying to use it the sample from following code project:
code.thinkgeo.com/projects/show/mapshapes
 
Then Just try following updated MapShapeLayer.

    class MapShapeLayer : Layer
    {
        private Dictionary<string, MapShape> mapShapes;
        private Projection projection;

        public MapShapeLayer()
        {
            mapShapes = new Dictionary<string, MapShape>();
        }

        public Projection Projection
        {
            get { return projection; }
            set { projection = value; }
        }

        // Here is where you place all of your map shapes.
        public Dictionary<string, MapShape> MapShapes
        {
            get { return mapShapes; }
        }

        // This is a required overload of the Layer.  As you can see we simply
        // loop through all of our map shapes and then choose the correct zoom level.
        // After that, the zoom level class takes care of the heavy lifiting.  You
        // have to love how easy this framework is to re-use.

        protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
        {
            foreach (string mapShapeKey in mapShapes.Keys)
            {
                MapShape mapShape = mapShapes[mapShapeKey];

                if (projection != null)
                {
                   Feature newFeature = projection.ConvertToExternalProjection(mapShape.Feature);
                   mapShape.Feature = newFeature;
                }

                ZoomLevel currentZoomLevel = mapShape.ZoomLevels.GetZoomLevelForDrawing(canvas.CurrentWorldExtent, canvas.Width,GeographyUnit.Meter);
                if (currentZoomLevel != null)
                {
                    if (canvas.CurrentWorldExtent.Intersects(mapShape.Feature.GetBoundingBox()))
                    {
                        currentZoomLevel.Draw(canvas, new Feature[] { mapShape.Feature }, new Collection<SimpleCandidate>(), labelsInAllLayers);
                    }
                }
            }
        }

 
Use age:

  // Add the worldLayer to the MapEngine
            worldLayer = new ShapeFileFeatureLayer(@"C:\bak\codethinkgeocom\MapShapes_090728\MapShapes\Data\Countries02.shp", ShapeFileReadWriteMode.ReadOnly);
            worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1;
            worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            string str1 = Proj4Projection.GetEpsgParametersString(4326);
            string str2 = Proj4Projection.GetGoogleMapParametersString();

            worldLayer.FeatureSource.Projection = new Proj4Projection(str1, str2);
            mapEngine.StaticLayers.Add("WorldLayer", worldLayer);

            worldLayer.Open();
            mapEngine.CurrentExtent = new RectangleShape(-10000000, 10000000, 10000000, -10000000);
            worldLayer.Close();

            // This is just a code snippet to show you how the new
            // layer should be used.

            // Add the mapShapeLayer to the MapEngine
            MapShapeLayer mapShapeLayer = new MapShapeLayer();

            MapShape mapShape1 = new MapShape(new Feature(-50, 42));
            mapShape1.ZoomLevels.ZoomLevel01.DefaultPointStyle = new PointStyle(new GeoImage(@"C:\bak\codethinkgeocom\MapShapes_090728\MapShapes\Data\Cargo Plane.png"));
            mapShape1.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            mapShapeLayer.MapShapes.Add("1", mapShape1);

            MapShape mapShape2 = new MapShape(new Feature(50, 39));
            mapShape2.ZoomLevels.ZoomLevel01.DefaultPointStyle = new PointStyle(new GeoImage(@"C:\bak\codethinkgeocom\MapShapes_090728\MapShapes\Data\China.png"));
            mapShape2.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            mapShapeLayer.MapShapes.Add("2", mapShape2);

            mapShapeLayer.Projection = new Proj4Projection(str1, str2);
            mapShapeLayer.Projection.Open();

            mapEngine.StaticLayers.Add("MapShapeLayer", mapShapeLayer);

            DrawImage();

 
Of course, a better solution is just rewreite the MapShapeLayer as following way:
1) Change the inheritance for MapShapeLayer from FeatureLayer instead of Layer directly.
2) Add a MapShapeFeatureSource, hook it up to MapShapeLayer.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale