OSM-Maps / Symbols for Points in Memory Provider / Coordinate Transformation

Mar 24, 2011 at 11:31 AM

Hi

I'm developing a Silverlight app concerning natural hazards. There will be a map part which I want to realize using MapSui/Brutile because I really like the usability of the Demo app.

The first step would be to show some points with a label (or ToolTip) on a OSM-Map. I can see the OSM-Layer in my app according to the Demo App.
 
First question - OSM-Maps:
Does anybody know if further OSM maps like OpenCycleMap can also be used as a tile service for free or at what cost? Ore are there other maps with elevation data for free or at low cost. The OpenCycleMap is very nice and would fit what I need.

Second question - Point layer (Memory Provider):
How can I place a bitmap to specific coordintates on the map? I tried the Demo sample:

var pointProvider = new MemoryProvider(GenerateRandomPoints(osmLayer.Envelope));
map.Layers.Add( new Layer("Points") { DataSource = pointProvider });
return map;

But the points are not displayed on the map control. I think I still have to specify which bitmap to display. I tried:

Layer pointLayer = new Layer("Geodan");
pointLayer.DataSource = new MemoryProvider(new SharpMap.Geometries.Point(546919, 6862238)); // lonlat: 4.9130567, 52.3422033
pointLayer.Styles.Add(new SymbolStyle() { Symbol = new Bitmap { data = GetImageStreamFromResource("ZR_WEB_BusinessApp.Bilder.icon.png") } });
map.Layers.Add(pointLayer);

But this doesn't work either. I get a nullreferenceexception for the Bitmap. In Sharpmap V0.9 it was possible to write something like this:
new Bitmap(apppath + @"\Res\icon.png", true);
But it seems not to work here. Any idea?

Third question - Coordinate Transformation:
The OSM map uses Spherical Mercator but I want to use data in Swiss Grid. Is it possible to project/transform points on the fly from one coordinate system to another?
Is there a sample anywhere?

I appreciate any help!

Cheers stefan

Mar 26, 2011 at 9:30 PM
Edited Mar 26, 2011 at 9:31 PM

OSM

The OSM data fall under some license. 

http://wiki.openstreetmap.org/wiki/OpenStreetMap_License

I think there are no guarantees with respect to the tile services. But better to check at openstreetmap.org and opencyclemap.org

Bitmap Points

This could be done like this:

citymin.Symbol = new Bitmap() { data = new FileStream(iconPath, FileMode.Open, FileAccess.Read) };

see the GradientTheme sample used in Mapsui.WinForms

Projections:

I have ported the projection stuff from SharpMap but havents done any testing yet, and didnt make any samples.

Paul

Mar 30, 2011 at 2:43 PM

Hi Paul

Thanks for your reply!

Projection
For the projection stuff I will give it a try. I already used it for a WinForms SharpMap app with more or less success.

OSM
I will contact the OSM people directly.

PointLayer
I tried yesterday for about two hours to access the image but I always got a security exception. Here is the Code

private Map CreateMap()
        {
            var map = new Map();
            var osmLayer = new TileLayer(new OsmTileSource()) { LayerName = "OSM" };
            map.Layers.Add(osmLayer);
            Layer pointLayer = new Layer("Geodan");
            pointLayer.DataSource = new MemoryProvider(new SharpMap.Geometries.Point(546919, 6862238)); // lonlat: 4.9130567, 52.3422033
            pointLayer.Styles.Add(new SymbolStyle() { Symbol = new Bitmap { data = new FileStream("..//Resources/Bilder/icon.png", FileMode.Open, FileAccess.Read) } });
            return map;
        } 

I placed the icon.png as embedded resource inside the web project but it couldn't be loaded. (security exception). I also tried to put it in a folder of the Silverlight app. But this didn't work either. Do you know this problem? How do I need to set the file path? Or do I need to change some user rights? Here is the exception text:

+        InnerException    {System.Security.SecurityException: Dateivorgang ist nicht zulässig. Der Zugriff auf Pfad '..//Resources/Bilder/icon.png' wurde verweigert.
   bei System.IO.FileSecurityState.EnsureState()
   bei System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   bei System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   bei System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
   bei ZR_WEB_BusinessApp.GUIOverlay.CreateMap()
   bei ZR_WEB_BusinessApp.GUIOverlay.SetMap(MapControl mapControl)
   bei ZR_WEB_BusinessApp.MapSui..ctor()}    System.Exception {System.Security.SecurityException}

Thanks for your help!

stefan