/// <summary> /// Tests interpreting all data from a given pbf source. /// </summary> /// <param name="name"></param> /// <param name="scene"></param> /// <param name="interpreter"></param> /// <param name="pbfSource"></param> public static Stream TestInterpret(string name, MapCSSInterpreter interpreter, Scene2D scene, string pbfSource) { StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget( interpreter, scene, new WebMercator()); FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfSource)); Stream stream = testFile.OpenRead(); OsmStreamSource source = new PBFOsmStreamSource(stream); OsmStreamFilterProgress progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); target.RegisterSource(progress); PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name)); performanceInfo.Start(); performanceInfo.Report("Interpreting style with objects from {0}...", pbfSource.ToString()); target.Pull(); performanceInfo.Stop(); Console.Write("", scene.BackColor); stream.Dispose(); return(testFile.OpenRead()); }
/// <summary> /// Raises the OnLoad event. /// </summary> /// <param name="e"></param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter( new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\static\default.mapcss").OpenRead(), new MapCSSDictionaryImageSource()); // initialize map. var map = new OsmSharp.UI.Map.Map(); //// initialize router. //_router = Router.CreateLiveFrom(new OsmSharp.Osm.PBF.Streams.PBFOsmStreamSource( // new FileInfo(@"kempen.osm.pbf").OpenRead()), new OsmRoutingInterpreter()); var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] { 16, 14, 12, 10 })); var target = new StyleOsmStreamSceneTarget( mapCSSInterpreter, scene, new WebMercator()); var source = new XmlOsmStreamSource( new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead()); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); target.RegisterSource(progress); target.Pull(); //var merger = new Scene2DObjectMerger(); //scene = merger.BuildMergedScene(scene); map.AddLayer(new LayerScene(scene)); //var dataSource = MemoryDataSource.CreateFromXmlStream( // new FileInfo(@"D:\Dropbox\Dropbox\SharpSoftware\Projects\Eurostation ReLive\Server_Dropbox\OSM\relive_mechelen\mechelen_new.osm").OpenRead()); //map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection)); //var layerTile = new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg", 200); //layerTile.MinZoom = 12; //layerTile.MaxZoom = 13; //map.AddLayer(layerTile); //map.AddLayer(new LayerScene( // Scene2D.Deserialize(new FileInfo(@"default.map").OpenRead(), // true))); // initialize route/points layer. _layerRoute = new LayerRoute(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerRoute); _layerPrimitives = new LayerPrimitives(new OsmSharp.Math.Geo.Projections.WebMercator()); map.AddLayer(_layerPrimitives); // set control properties. this.mapControl1.Map = map; this.mapControl1.MapCenter = new GeoCoordinate(51.0167, 4.4914); // wechel this.mapControl1.MapZoom = 14; this.mapControl1.MapMouseClick += mapControl1_MapMouseClick; this.mapControl1.MapMouseMove += mapControl1_MapMouseMove; }
public static void Main(string[] args) { Native.Initialize(); // enable logging and use the console as output. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener( new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener()); // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Tiles.Sample.SelfHost.custom.mapcss"), new MapCSSDictionaryImageSource()); var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] { 16, 14, 12, 10 })); var target = new StyleOsmStreamSceneTarget( mapCSSInterpreter, scene, new WebMercator()); var source = new PBFOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Tiles.Sample.SelfHost.kempen.osm.pbf")); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(source); target.RegisterSource(progress); target.Pull(); var merger = new Scene2DObjectMerger(); scene = merger.BuildMergedScene(scene); // create a new instance (with a cache). var instance = new RenderingInstance(); instance.Map.AddLayer(new LayerScene(scene)); // add a default test instance. ApiBootstrapper.AddInstance("default", instance); // start hosting this! using (var host = new NancyHost(new Uri("http://*****:*****@ http://localhost:1234"); System.Diagnostics.Process.Start("http://localhost:1234/default"); Console.ReadLine(); } }
/// <summary> /// Builds a tile server instance based on the given osm source and mapcss styles file. /// </summary> /// <param name="name">The name of the instance-to-be.</param> /// <param name="source">The osm source stream.</param> /// <param name="mapCSSfile">The stream containing the mapcss.</param> /// <param name="cacheFolder"></param> private static void BuildTileServer(string name, OsmStreamSource source, Stream mapCSSfile, string cacheFolder) { try { // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter(mapCSSfile, new MapCSSDictionaryImageSource()); var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] { 16, 14, 12, 10 })); var target = new StyleOsmStreamSceneTarget( mapCSSInterpreter, scene, new WebMercator()); target.RegisterSource(source); target.Pull(); //var merger = new Scene2DObjectMerger(); //scene = merger.BuildMergedScene(scene); OsmSharp.Service.Tiles.RenderingInstance instance = null; if (string.IsNullOrWhiteSpace(cacheFolder)) { // no cache. instance = new OsmSharp.Service.Tiles.RenderingInstance(); } else { // use cache. var instanceCacheFolder = Path.Combine(cacheFolder, name); var instanceCacheDirectoryInfo = new DirectoryInfo(instanceCacheFolder); if (!instanceCacheDirectoryInfo.Exists) { // create the directory if it doesn't exists. instanceCacheDirectoryInfo.Create(); } var instanceCache = new OsmSharp.Service.Tiles.Cache.TileCache(new DirectoryInfo(instanceCacheFolder)); instanceCache.Clear(); instance = new OsmSharp.Service.Tiles.RenderingInstance(instanceCache); } instance.Map.AddLayer(new LayerScene(scene)); // add a default test instance. OsmSharp.Service.Tiles.ApiBootstrapper.AddInstance(name, instance); } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("Bootstrapper.BuildTileServer", OsmSharp.Logging.TraceEventType.Error, "Failed to setup tile service: " + ex.Message); } }