Esempio n. 1
0
        public void AddLayerOsm(Stream stream)
        {
            if (stream == null)
            {
                return;
            }

            // Get assembly
            var assembly = typeof(OsmMap).GetTypeInfo().Assembly;

            // Create the MapCSS image source, which is used as image source for areas of the map
            var imageSource = new MapCSSDictionaryImageSource();

            // Load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(assembly.GetManifestResourceStream("OsmSharp.Forms.MapCSS.Default.mapcss"), imageSource);

            // Load data from pbf file into a memory data source
            var source = MemoryDataSource.CreateFromPBFStream(stream);

            // If there is allready a layer with map, close it
            if (layerMap != null)
            {
                layerMap.Close();
            }

            tileUrl = "";

            // Add new map layer
            layerMap = map?.AddLayerOsm(source, mapCSSInterpreter);
        }
Esempio n. 2
0
        /// <summary>
        /// Raises the OnLoad event.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // create the MapCSS image source.
            var imageSource = new MapCSSDictionaryImageSource();

            imageSource.Add("styles/default/parking.png",
                            Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.images.parking.png"));
            imageSource.Add("styles/default/bus.png",
                            Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.images.bus.png"));
            imageSource.Add("styles/default/postbox.png",
                            Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.images.postbox.png"));

            // load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                new FileInfo(@"C:\Users\xivk\Dropbox\SharpSoftware\Projects\Westtour WOI\wvl.mapcss").OpenRead(),
                imageSource);

            // initialize the data source.
            //var dataSource = MemoryDataSource.CreateFromXmlStream(new FileInfo(@"c:\OSM\bin\wechel.osm").OpenRead());
            var dataSource = MemoryDataSource.CreateFromPBFStream(new FileInfo(@"C:\OSM\bin\wvl.osm.pbf").OpenRead());
            //var dataSource = MemoryDataSource.CreateFromPBFStream(new FileInfo(@"c:\OSM\bin\gent.osm.pbf").OpenRead());
            //var dataSource = MemoryDataSource.CreateFromPBFStream(new FileInfo(@"c:\OSM\bin\lebbeke.osm.pbf").OpenRead());
            //Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.test.osm"));

            // initialize map.
            var map = new OsmSharp.UI.Map.Map();

            map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection));
            //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            //map.AddLayer(new LayerMBTile(@"C:\Users\xivk\Documents\Nostalgeo.mbtiles"));
            //map.AddLayer(
            //    new LayerScene(
            //        Scene2DLayered.Deserialize(new FileInfo(@"c:\OSM\bin\kempen.osm.pbf.scene.layered").OpenRead(), true)));
            //map.AddLayer(
            //    new LayerScene(
            //        Scene2DLayered.Deserialize(new FileInfo(@"c:\OSM\bin\wvl.map").OpenRead(), true)));

            //this.InitializeRouting(map);

            //// create gpx layer.
            //var gpxLayer = new LayerGpx(map.Projection);
            //gpxLayer.AddGpx(
            //    Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.WinForms.UI.Sample.test.gpx"));
            //map.AddLayer(gpxLayer);

            // set control properties.
            this.mapControl1.Map = map;
            //this.mapControl1.Center = new GeoCoordinate(51.26371, 4.7854); //51.26371&lon=4.7854 // wechel.osm
            //this.mapControl1.Center = new GeoCoordinate(50.88672, 3.23899); // lendelede
            //this.mapControl1.Center = new GeoCoordinate(50.9523195, 3.0997436);
            //this.mapControl1.MapCenter = new GeoCoordinate(51.22105, 2.93419); // oostende spoor.
            this.mapControl1.MapCenter = new GeoCoordinate(51.156803, 2.958887); // gistel
            //this.mapControl1.MapCenter = new GeoCoordinate(51.05608, 3.72139); // gent
            //this.mapControl1.Center = new GeoCoordinate(50.9969, 4.1201);
            this.mapControl1.MapZoom = 19;
        }
Esempio n. 3
0
        /// <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(@"dark_roads.mapcss").OpenRead(), new MapCSSDictionaryImageSource());

            // initialize map.
            var map = new OsmSharp.UI.Map.Map();

            //Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List<float>(new float[] {
            //    16, 14, 12, 10 }));
            //StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget(
            //    mapCSSInterpreter, scene, new WebMercator());
            //FileInfo testFile = new FileInfo(@"kempen.osm.pbf");
            //Stream stream = testFile.OpenRead();
            //OsmStreamSource source = new PBFOsmStreamSource(stream);
            //OsmStreamFilterProgress progress = new OsmStreamFilterProgress(source);
            //target.RegisterSource(progress);
            //target.Pull();

            //var merger = new Scene2DObjectMerger();
            //scene = merger.BuildMergedScene(scene);

            //map.AddLayer(new LayerScene(scene));
            var dataSource = MemoryDataSource.CreateFromPBFStream(
                new FileInfo(@"kempen.osm.pbf").OpenRead());

            map.AddLayer(new LayerOsm(dataSource, mapCSSInterpreter, map.Projection));
            ////map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
            //map.AddLayer(new LayerScene(
            //    Scene2D.Deserialize(new FileInfo(@"kempen-big.osm.pbf.scene.layered").OpenRead(),
            //        true)));

            // set control properties.
            this.mapControl1.Map       = map;
            this.mapControl1.MapCenter = new GeoCoordinate(51.26371, 4.7854); // wechel
            this.mapControl1.MapZoom   = 16;
        }