Exemple #1
0
        private static bool DisplayAllLayers()
        {
            var ds = new OgrDatasource();

            if (!ds.Open(CONNECTION_STRING))
            {
                Debug.WriteLine("Failed to establish connection: " + ds.GdalLastErrorMsg);
            }
            else
            {
                map.RemoveAllLayers();

                // make sure it matches SRID of the layers (4326 in this case)
                map.Projection = tkMapProjection.PROJECTION_WGS84;

                for (int i = 0; i < ds.LayerCount; i++)
                {
                    var layer = ds.GetLayer(i);
                    if (layer != null)
                    {
                        int handle = map.AddLayer(layer, true);
                        if (handle == -1)
                        {
                            Debug.WriteLine("Failed to add layer to the map: " + map.get_ErrorMsg(map.LastErrorCode));
                        }
                        else
                        {
                            Debug.WriteLine("Layer was added the map: " + layer.Name);
                        }
                    }
                }
                map.ZoomToMaxVisibleExtents();
                ds.Close();
            }
            return(true);
        }