/// <summary> /// Initializes a new instance of the <see cref="OsmSharp.Android.UI.CanvasRenderer2DView"/> class. /// </summary> /// <param name="context">Context.</param> /// <param name="attrs">Attrs.</param> public CanvasRenderer2DView(Context context, IAttributeSet attrs, Scene2D scene) : base(context, attrs) { Initialize (); this.Scene = scene; }
/// <summary> /// Creates a new MapCSS scene target. /// </summary> /// <param name="mapCSSInterpreter"></param> /// <param name="scene"></param> /// <param name="projection"></param> public StyleOsmStreamSceneTarget(StyleInterpreter mapCSSInterpreter, Scene2D scene, IProjection projection) { _projection = projection; _scene = scene; _mapCSSInterpreter = mapCSSInterpreter; }
/// <summary> /// Initializes a new instance of the <see cref="OsmSharp.Android.UI.CanvasRenderer2DView"/> class. /// </summary> /// <param name="context">Context.</param> public CanvasRenderer2DView(Context context, Scene2D scene) : base(context) { Initialize (); this.Scene = scene; }
/// <summary> /// Creates a new MapCSS scene target. /// </summary> /// <param name="styleInterpreter"></param> /// <param name="scene"></param> /// <param name="projection"></param> /// <param name="stream"></param> public StyleOsmStreamSceneStreamTarget(StyleInterpreter styleInterpreter, Scene2D scene, IProjection projection, Stream stream) { _projection = projection; _scene = scene; _styleInterpreter = styleInterpreter; _stream = stream; }
/// <summary> /// Creates a new OSM data layer. /// </summary> /// <param name="dataSource"></param> /// <param name="styleInterpreter"></param> public LayerDynamicGraphLiveEdge(IBasicRouterDataSource<LiveEdge> dataSource, StyleInterpreter styleInterpreter) { _dataSource = dataSource; _styleInterpreter = styleInterpreter; _scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); _interpretedObjects = new Dictionary<int, HashSet<ArcId>>(); }
/// <summary> /// Creates a new OSM data layer. /// </summary> /// <param name="dataSource"></param> /// <param name="styleInterpreter"></param> public LayerGraph(IRoutingAlgorithmData<Edge> dataSource, StyleInterpreter styleInterpreter) { _dataSource = dataSource; _styleInterpreter = styleInterpreter; _scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); _interpretedObjects = new Dictionary<int, HashSet<ArcId>>(); }
/// <summary> /// Tests interpreting all data from a given pbf source. /// </summary> /// <param name="name"></param> /// <param name="mapCSS"></param> /// <param name="scene"></param> /// <param name="pbfSource"></param> public static void TestInterpret(string name, string mapCSS, Scene2D scene, string pbfSource) { FileInfo cssFile = new FileInfo(string.Format(@".\TestFiles\{0}", mapCSS)); Stream cssStream = cssFile.OpenRead(); MapCSSInterpreter interpreter = new MapCSSInterpreter(cssStream, new MapCSSDictionaryImageSource()); MapCSSInterpreterTests.TestInterpret(name, interpreter, scene, pbfSource); cssStream.Dispose(); }
static void Main(string[] args) { // enable logging and use the console as output. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener( new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener()); // create router. using (var source = new FileInfo(@"kempen.osm.pbf").OpenRead()) { var pbfSource = new PBFOsmStreamSource(source); var progress = new OsmStreamFilterProgress(); progress.RegisterSource(pbfSource); var router = Router.CreateFrom(progress, new OsmRoutingInterpreter()); OsmSharp.Service.Routing.ApiBootstrapper.Add("default", router); } // initialize mapcss interpreter. var mapCSSInterpreter = new MapCSSInterpreter( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Routing.Sample.SelfHost.custom.mapcss"), new MapCSSDictionaryImageSource()); using (var source = new FileInfo(@"kempen.osm.pbf").OpenRead()) { var pbfSource = new PBFOsmStreamSource(source); 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 progress = new OsmStreamFilterProgress(); progress.RegisterSource(pbfSource); target.RegisterSource(progress); target.Pull(); // create a new instance (with a cache). var instance = new RenderingInstance(); instance.Map.AddLayer(new LayerScene(scene)); // add a default test instance. OsmSharp.Service.Tiles.ApiBootstrapper.AddInstance("default", instance); } var uri = new Uri("http://*****:*****@ http://localhost:1234"); System.Diagnostics.Process.Start("http://localhost:1234/default"); Console.ReadLine(); } }
/// <summary> /// Tests serializing a stream. /// </summary> /// <param name="name"></param> /// <param name="stream"></param> /// <param name="scene"></param> /// <param name="compress"></param> public static void TestSerialize(string name, Stream stream, Scene2D scene, bool compress) { PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Serialize", name)); performanceInfo.Start(); performanceInfo.Report("Serializing stream..."); scene.Serialize(stream, compress); performanceInfo.Stop(); Console.Write("", scene.BackColor); }
/// <summary> /// Gets all objects in this scene for the specified view. /// </summary> /// <param name="view">View.</param> /// <param name="zoom"></param> public override IEnumerable <Scene2DPrimitive> Get(View2D view, float zoom) { Scene2D scene = this.SearchForScene(zoom); List <IEnumerable <Scene2DPrimitive> > primitives = new List <IEnumerable <Scene2DPrimitive> >(); primitives.Add(_nonSimplifiedScene.Get(view, zoom)); if (scene != null) { primitives.Add(scene.Get(view, zoom)); } return(new Scene2DPrimitiveEnumerable(primitives)); }
/// <summary> /// Creates a new style scene manager. /// </summary> /// <param name="scene">The scene to manage.</param> /// <param name="interpreter">The intepreter converting OSM-objects into scene-objects.</param> public StyleSceneManager(Scene2D scene, StyleInterpreter interpreter) { _scene = scene; _interpreter = interpreter; _interpretedNodes = new LongIndex(); _interpretedWays = new LongIndex(); _interpretedRelations = new LongIndex(); SimpleColor? color = _interpreter.GetCanvasColor(); //this.Scene.BackColor = color.HasValue ? color.Value.Value : SimpleColor.FromArgb(0, 255, 255, 255).Value; }
/// <summary> /// Tests serializing a stream. /// </summary> /// <param name="name"></param> /// <param name="outputFile"></param> /// <param name="scene"></param> /// <param name="compress"></param> public static void TestSerialize(string name, string outputFile, Scene2D scene, bool compress) { FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", outputFile)); Stream stream = testFile.OpenWrite(); Scene2DTests.TestSerialize(name, stream, scene, compress); stream.Dispose(); OsmSharp.Logging.Log.TraceEvent(name, System.Diagnostics.TraceEventType.Information, string.Format("Serialized file: {0}KB", testFile.Length / 1024)); testFile.Delete(); }
/// <summary> /// Tests serializing a stream. /// </summary> /// <param name="name"></param> /// <param name="stream"></param> /// <param name="scene"></param> /// <param name="compress"></param> public static void TestSerialize(string name, Stream stream, Scene2D scene, bool compress) { PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Serialize", name)); performanceInfo.Start(); performanceInfo.Report("Serializing stream..."); TagsCollectionBase metaTags = new TagsCollection(); metaTags.Add("generated_by", "performance_test"); scene.Serialize(stream, compress, metaTags); performanceInfo.Stop(); Console.Write("", scene.BackColor); }
/// <summary> /// Executes the tests. /// </summary> /// <returns>Serialized scene.</returns> public static Stream Test() { // create a layered scene. Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List<float>(new float[] { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6 })); // tests map css interpreter. MapCSSInterpreterTests.TestInterpret("MapCSSInterpreter", @"mapcss\default.mapcss", scene, "kempen-big.osm.pbf"); var merger = new Scene2DObjectMerger(); scene = merger.BuildMergedScene(scene); // tests serialization of the scene. return Scene2DTests.TestSerialize("Scene2DLayered", @"mapcss\default.map", scene, true); }
/// <summary> /// Translates the given OSM objects into corresponding geometries. /// </summary> /// <param name="scene"></param> /// <param name="projection"></param> /// <param name="source"></param> /// <param name="osmGeo"></param> public virtual void Translate(Scene2D scene, IProjection projection, IDataSourceReadOnly source, OsmGeo osmGeo) { switch (osmGeo.Type) { case OsmGeoType.Node: this.Translate(scene, projection, CompleteNode.CreateFrom(osmGeo as Node)); break; case OsmGeoType.Way: this.Translate(scene, projection, CompleteWay.CreateFrom(osmGeo as Way, source)); break; case OsmGeoType.Relation: this.Translate(scene, projection, CompleteRelation.CreateFrom(osmGeo as Relation, source)); break; } }
/// <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 void 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(); PBFOsmStreamSource source = new PBFOsmStreamSource(stream); target.RegisterSource(source); 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(); }
/// <summary> /// Translates the given OSM objects into corresponding geometries. /// </summary> /// <param name="scene"></param> /// <param name="projection"></param> /// <param name="source"></param> /// <param name="osmGeo"></param> public virtual void Translate(Scene2D scene, IProjection projection, IDataSourceReadOnly source, OsmGeo osmGeo) { switch (osmGeo.Type) { case OsmGeoType.Node: var node = osmGeo as Node; if(node.Tags == null) { // make sure that a node has a tag collection by default. node.Tags= new TagsCollection(); } this.Translate(scene, projection, node); break; case OsmGeoType.Way: this.Translate(scene, projection, CompleteWay.CreateFrom(osmGeo as Way, source)); break; case OsmGeoType.Relation: this.Translate(scene, projection, CompleteRelation.CreateFrom(osmGeo as Relation, source)); break; } }
public void TestEmptyCSS() { // create 'test' objects. Node node1 = new Node(); node1.Id = 1; node1.Latitude = 1; node1.Longitude = 1; Node node2 = new Node(); node2.Id = 2; node2.Latitude = 2; node2.Longitude = 2; Way way = new Way(); way.Id = 1; way.Nodes = new List<long>(); way.Nodes.Add(1); way.Nodes.Add(2); // create the datasource. MemoryDataSource dataSource = new MemoryDataSource(); dataSource.AddNode(node1); dataSource.AddNode(node2); dataSource.AddWay(way); // create the projection and scene objects. var mercator = new WebMercator(); Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the interpreter. MapCSSInterpreter interpreter = new MapCSSInterpreter(string.Empty, new MapCSSDictionaryImageSource()); interpreter.Translate(scene, mercator, dataSource, node1); interpreter.Translate(scene, mercator, dataSource, node2); interpreter.Translate(scene, mercator, dataSource, way); // test the scene contents. Assert.AreEqual(0, scene.Count); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, scene.BackColor); }
public void TestMapCSSSimpleEval() { MemoryDataSource source = new MemoryDataSource( Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Way.Create(1, new TagsCollection( Tag.Create("width", "10")), 1, 2, 3, 1)); // test closed way. string css = "way { " + " width: eval(\"tag('width')\"); " + " color: green; " + "} "; // create the projection and scene objects. var mercator = new WebMercator(); Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the projection and scene objects. scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the interpreter. MapCSSInterpreter interpreter = new MapCSSInterpreter(css, new MapCSSDictionaryImageSource()); interpreter.Translate(scene, mercator, source, source.GetWay(1)); // test the scene contents. Assert.AreEqual(1, scene.Count); Primitive2D primitive = scene.Get(0); Assert.IsInstanceOf<Line2D>(primitive); Line2D line = (primitive as Line2D); Assert.AreEqual(10, line.Width); }
/// <summary> /// Initialize the specified defaultMapCenter, defaultMap, defaultMapTilt and defaultMapZoom. /// </summary> /// <param name="defaultMapCenter">Default map center.</param> /// <param name="defaultMap">Default map.</param> /// <param name="defaultMapTilt">Default map tilt.</param> /// <param name="defaultMapZoom">Default map zoom.</param> public void Initialize(GeoCoordinate defaultMapCenter, Map defaultMap, Degree defaultMapTilt, float defaultMapZoom) { // set clip to bounds to prevent objects from being rendered/show outside of the mapview. this.ClipsToBounds = true; _mapCenter = defaultMapCenter; _map = defaultMap; _mapTilt = defaultMapTilt; _mapZoom = defaultMapZoom; _doubleTapAnimator = new MapViewAnimator (this); this.BackgroundColor = UIColor.White; this.UserInteractionEnabled = true; _markers = new List<MapMarker> (); if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) { var panGesture = new UIPanGestureRecognizer (Pan); panGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; // TODO: workaround for xamarin bug, remove later! panGesture.ShouldRequireFailureOf = (a, b) => { return false; }; panGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; this.AddGestureRecognizer (panGesture); var pinchGesture = new UIPinchGestureRecognizer (Pinch); pinchGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; // TODO: workaround for xamarin bug, remove later! pinchGesture.ShouldRequireFailureOf = (a, b) => { return false; }; pinchGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; this.AddGestureRecognizer (pinchGesture); var rotationGesture = new UIRotationGestureRecognizer (Rotate); rotationGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; // TODO: workaround for xamarin bug, remove later! rotationGesture.ShouldRequireFailureOf = (a, b) => { return false; }; rotationGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; this.AddGestureRecognizer (rotationGesture); var singleTapGesture = new UITapGestureRecognizer (SingleTap); singleTapGesture.NumberOfTapsRequired = 1; // TODO: workaround for xamarin bug, remove later! // singleTapGesture.ShouldRequireFailureOf = (a, b) => { return false; }; // singleTapGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; var doubleTapGesture = new UITapGestureRecognizer (DoubleTap); doubleTapGesture.NumberOfTapsRequired = 2; // TODO: workaround for xamarin bug, remove later! // doubleTapGesture.ShouldRequireFailureOf = (a, b) => { return false; }; // doubleTapGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; //singleTapGesture.RequireGestureRecognizerToFail (doubleTapGesture); this.AddGestureRecognizer (singleTapGesture); this.AddGestureRecognizer (doubleTapGesture); } else { var panGesture = new UIPanGestureRecognizer (Pan); panGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; this.AddGestureRecognizer (panGesture); var pinchGesture = new UIPinchGestureRecognizer (Pinch); pinchGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; this.AddGestureRecognizer (pinchGesture); var rotationGesture = new UIRotationGestureRecognizer (Rotate); rotationGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; this.AddGestureRecognizer (rotationGesture); var singleTapGesture = new UITapGestureRecognizer (SingleTap); singleTapGesture.NumberOfTapsRequired = 1; //singleTapGesture.ShouldRecognizeSimultaneously += ShouldRecognizeSimultaneouslySingle; //singleTapGesture.ShouldBeRequiredToFailBy += ShouldRecognizeSimultaneouslySingle; var doubleTapGesture = new UITapGestureRecognizer (DoubleTap); doubleTapGesture.NumberOfTapsRequired = 2; //doubleTapGesture.ShouldRecognizeSimultaneously += ShouldRecognizeSimultaneouslySingle; //doubleTapGesture.ShouldBeRequiredToFailBy += ShouldRecognizeSimultaneouslyDouble; singleTapGesture.RequireGestureRecognizerToFail (doubleTapGesture); this.AddGestureRecognizer (singleTapGesture); this.AddGestureRecognizer (doubleTapGesture); } // set scalefactor. _scaleFactor = this.ContentScaleFactor; // create the cache renderer. _cacheRenderer = new MapRenderer<CGContextWrapper> ( new CGContextRenderer (_scaleFactor)); _cachedScene = new Scene2DSimple (); _cachedScene.BackColor = SimpleColor.FromKnownColor (KnownColor.White).Value; }
public void TestCanvasJOSMSettingsCSS() { // create CSS. string css = "canvas { " + "background-color: white; " + "default-points: true; " + // adds default points for every node (color: black, size: 2). "default-lines: true; " + // adds default lines for every way (color: red, width: 1). "} "; // create 'test' objects. Node node1 = new Node(); node1.Id = 1; node1.Latitude = 1; node1.Longitude = 1; Node node2 = new Node(); node2.Id = 2; node2.Latitude = 2; node2.Longitude = 2; Way way = new Way(); way.Id = 1; way.Nodes = new List<long>(); way.Nodes.Add(1); way.Nodes.Add(2); // create the datasource. MemoryDataSource dataSource = new MemoryDataSource(); dataSource.AddNode(node1); dataSource.AddNode(node2); dataSource.AddWay(way); // create the projection and scene objects. var mercator = new WebMercator(); Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the interpreter. MapCSSInterpreter interpreter = new MapCSSInterpreter(css, new MapCSSDictionaryImageSource()); interpreter.Translate(scene, mercator, dataSource, node1); interpreter.Translate(scene, mercator, dataSource, node2); interpreter.Translate(scene, mercator, dataSource, way); // test the scene contents. Assert.AreEqual(3, scene.Count); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.White).Value, scene.BackColor); // test the scene point 1. Primitive2D primitive = scene.Get(0); Assert.IsNotNull(primitive); Assert.IsInstanceOf<Primitive2D>(primitive); Point2D pointObject = primitive as Point2D; Assert.AreEqual(2, pointObject.Size); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color); Assert.AreEqual(mercator.LongitudeToX(1), pointObject.X); Assert.AreEqual(mercator.LatitudeToY(1), pointObject.Y); // test the scene point 2. primitive = scene.Get(1); Assert.IsNotNull(primitive); Assert.IsInstanceOf<Point2D>(primitive); pointObject = primitive as Point2D; Assert.AreEqual(2, pointObject.Size); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Black).Value, pointObject.Color); Assert.AreEqual(mercator.LongitudeToX(2), pointObject.X); Assert.AreEqual(mercator.LatitudeToY(2), pointObject.Y); // test the scene line 2. primitive = scene.Get(2); Assert.IsNotNull(primitive); Assert.IsInstanceOf<Line2D>(primitive); Line2D line = primitive as Line2D; Assert.AreEqual(1, line.Width); Assert.AreEqual(SimpleColor.FromKnownColor(KnownColor.Red).Value, line.Color); Assert.IsNotNull(line.X); Assert.IsNotNull(line.Y); Assert.AreEqual(2, line.X.Length); Assert.AreEqual(2, line.Y.Length); Assert.AreEqual(mercator.LongitudeToX(1), line.X[0]); Assert.AreEqual(mercator.LatitudeToY(1), line.Y[0]); Assert.AreEqual(mercator.LongitudeToX(2), line.X[1]); Assert.AreEqual(mercator.LatitudeToY(2), line.Y[1]); }
public void TestMapCSSArea() { MemoryDataSource source = new MemoryDataSource( Node.Create(1, 0, 0), Node.Create(2, 1, 0), Node.Create(3, 0, 1), Way.Create(1, new TagsCollection( Tag.Create("area", "yes")), 1, 2, 3, 1)); // test closed way. string css = "area { " + " fill-color: black; " + "} "; // create the projection and scene objects. var mercator = new WebMercator(); Scene2D scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the projection and scene objects. scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), 16); // create the interpreter. MapCSSInterpreter interpreter = new MapCSSInterpreter(css, new MapCSSDictionaryImageSource()); interpreter.Translate(scene, mercator, source, source.GetWay(1)); // test the scene contents. Assert.AreEqual(1, scene.Count); Primitive2D primitive = scene.Get(0); Assert.IsInstanceOf<Polygon2D>(primitive); }
/// <summary> /// Translates a node. /// </summary> /// <param name="scene">The scene to add primitives to.</param> /// <param name="projection">The projection used to convert the objects.</param> /// <param name="node"></param> private void TranslateNode(Scene2D scene, IProjection projection, Node node) { // build the rules. IEnumerable<MapCSSRuleProperties> rules = this.BuildRules(new MapCSSObject(node)); // interpret the results. foreach (var rule in rules) { int zIndex; if (!rule.TryGetProperty<int>("zIndex", out zIndex)) { zIndex = 0; } float minZoom = (float)projection.ToZoomFactor(rule.MinZoom); float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom); uint? pointId = null; int color; if (rule.TryGetProperty<int>("color", out color)) { float width; if (rule.TryGetProperty<float>("width", out width)) { pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude), projection.LatitudeToY(node.Coordinate.Latitude)); scene.AddStylePoint(pointId.Value, this.CalculateSceneLayer(OffsetPoint, zIndex), minZoom, maxZoom, color, width); } else { pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude), projection.LatitudeToY(node.Coordinate.Latitude)); scene.AddStylePoint(pointId.Value, this.CalculateSceneLayer(OffsetPoint, zIndex), minZoom, maxZoom, color, 1); } } byte[] iconImage; if (rule.TryGetProperty("iconImage", out iconImage)) { if (!pointId.HasValue) { pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude), projection.LatitudeToY(node.Coordinate.Latitude)); } // an icon is to be drawn! ushort imageId = scene.AddImage(iconImage); scene.AddIcon(pointId.Value, this.CalculateSceneLayer(OffsetPoint, zIndex), minZoom, maxZoom, imageId); } string text; if (rule.TryGetProperty("text", out text)) { int textColor; if(!rule.TryGetProperty("textColor", out textColor)) { textColor = SimpleColor.FromKnownColor(KnownColor.Black).Value; } int haloColor; int? haloColorNullable = null; if (rule.TryGetProperty("textHaloColor", out haloColor)) { haloColorNullable = haloColor; } int haloRadius; int? haloRadiusNullable = null; if (rule.TryGetProperty("textHaloRadius", out haloRadius)) { haloRadiusNullable = haloRadius; } int fontSize; if (!rule.TryGetProperty("fontSize", out fontSize)) { fontSize = 10; } string fontFamily; if (!rule.TryGetProperty ("fontFamily", out fontFamily)) { fontFamily = "Arial"; // just some default font. } // a text is to be drawn. string value; if (node.Tags.TryGetValue(text, out value)) { if (!pointId.HasValue) { pointId = scene.AddPoint(projection.LongitudeToX(node.Coordinate.Longitude), projection.LatitudeToY(node.Coordinate.Latitude)); } scene.AddText(pointId.Value, this.CalculateSceneLayer(OffsetPointText, zIndex), minZoom, maxZoom, fontSize, value, textColor, haloColorNullable, haloRadiusNullable, fontFamily); } } } }
/// <summary> /// Translates a multipolygon. /// </summary> /// <param name="scene">The scene to add primitives to.</param> /// <param name="projection">The projection used to convert the objects.</param> /// <param name="multiPolygon"></param> private void TranslateMultiPolygon(Scene2D scene, IProjection projection, MultiPolygon multiPolygon) { foreach(Polygon polygon in multiPolygon) { polygon.Attributes = multiPolygon.Attributes; this.TranslatePolygon(scene, projection, polygon); } }
/// <summary> /// Translates a polygon. /// </summary> /// <param name="scene">The scene to add primitives to.</param> /// <param name="projection">The projection used to convert the objects.</param> /// <param name="polygon"></param> private void TranslatePolygon(Scene2D scene, IProjection projection, Polygon polygon) { polygon.Ring.Attributes = polygon.Attributes; this.TranslateLineairRing(scene, projection, polygon.Ring); //// build the rules. //List<MapCSSRuleProperties> rules = // this.BuildRules(new MapCSSObject(polygon)); //// validate what's there. //if (rules.Count == 0) //{ // return; //} }
/// <summary> /// Translates a relation. /// </summary> /// <param name="scene">The scene to add primitives to.</param> /// <param name="projection">The projection used to convert the objects.</param> /// <param name="relation"></param> private void TranslateRelation(Scene2D scene, IProjection projection, CompleteRelation relation) { }
/// <summary> /// Translates the given OSM objects into corresponding geometries. /// </summary> /// <param name="projection">The projection to use.</param> /// <param name="osmGeo">The osm object.</param> /// <param name="scene">The scene to fill with the resulting geometries.</param> /// <returns></returns> public abstract void Translate(Scene2D scene, IProjection projection, ICompleteOsmGeo osmGeo);
/// <summary> /// Translates a way. /// </summary> /// <param name="scene">The scene to add primitives to.</param> /// <param name="projection">The projection used to convert the objects.</param> /// <param name="way"></param> /// <param name="relevantTags"></param> private bool TranslateWay(Scene2D scene, IProjection projection, CompleteWay way, TagsCollectionBase relevantTags) { // build the rules. List<MapCSSRuleProperties> rules = null; if (!_succesfullWays.TryGetValue(relevantTags, out rules)) { rules = this.BuildRules(new MapCSSObject(way)); _succesfullWays.Add(relevantTags, rules); } // validate what's there. if (rules.Count == 0) { return false; } bool success = false; // get x/y. double[] x = null, y = null; if (x == null) { // pre-calculate x/y. x = new double[way.Nodes.Count]; y = new double[way.Nodes.Count]; for (int idx = 0; idx < way.Nodes.Count; idx++) { x[idx] = projection.LongitudeToX( way.Nodes[idx].Coordinate.Longitude); y[idx] = projection.LatitudeToY( way.Nodes[idx].Coordinate.Latitude); } // simplify. if (x.Length > 2) { double[][] simplified = SimplifyCurve.Simplify(new double[][] {x, y}, 0.0001); x = simplified[0]; y = simplified[1]; } } // add the z-index. foreach (var rule in rules) { float minZoom = (float)projection.ToZoomFactor(rule.MinZoom); float maxZoom = (float)projection.ToZoomFactor(rule.MaxZoom); int zIndex ; if (!rule.TryGetProperty<int>("zIndex", out zIndex)) { zIndex = 0; } // interpret the results. if (x != null && x.Length > 1) { // there is a valid interpretation of this way. int color; bool renderAsLine = true; if (way.IsOfType(MapCSSTypes.Area)) { // the way is an area. check if it can be rendered as an area. int fillColor; if (rule.TryGetProperty("fillColor", out fillColor)) { // render as an area. uint? pointsId = scene.AddPoints(x, y); if (pointsId.HasValue) { scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetArea, zIndex), minZoom, maxZoom, fillColor, 1, true); success = true; if (rule.TryGetProperty("color", out color)) { scene.AddStylePolygon(pointsId.Value, this.CalculateSceneLayer(OffsetCasing, zIndex), minZoom, maxZoom, color, 1, false); success = true; } } renderAsLine = false; // was validly rendered als a line. } } if (renderAsLine) { // was not rendered as an area. // the way has to rendered as a line. LineJoin lineJoin; if (!rule.TryGetProperty("lineJoin", out lineJoin)) { lineJoin = LineJoin.Miter; } int[] dashes; if (!rule.TryGetProperty("dashes", out dashes)) { dashes = null; } if (rule.TryGetProperty("color", out color)) { float casingWidth; int casingColor; if (!rule.TryGetProperty("casingWidth", out casingWidth)) { casingWidth = 0; } if (!rule.TryGetProperty("casingColor", out casingColor)) { // casing: use the casing layer. casingColor = -1; } float width; if (!rule.TryGetProperty("width", out width)) { width = 1; } uint? pointsId = scene.AddPoints(x, y); success = true; if (pointsId.HasValue) { if (casingWidth > 0) { // adds the casing scene.AddStyleLine(pointsId.Value, this.CalculateSceneLayer(OffsetCasing, zIndex), minZoom, maxZoom, casingColor, width + (casingWidth * 2), lineJoin, dashes); } if (dashes == null) { // dashes not set, use line offset. scene.AddStyleLine(pointsId.Value, this.CalculateSceneLayer(OffsetLine, zIndex), minZoom, maxZoom, color, width, lineJoin, dashes); } else { // dashes set, use line pattern offset. scene.AddStyleLine(pointsId.Value, this.CalculateSceneLayer(OffsetLinePattern, zIndex), minZoom, maxZoom, color, width, lineJoin, dashes); } int textColor; int fontSize; string nameTag; if (!rule.TryGetProperty("fontSize", out fontSize)) { fontSize = 10; } if (rule.TryGetProperty("text", out nameTag) && rule.TryGetProperty("textColor", out textColor)) { int haloColor; int? haloColorNullable = null; if (rule.TryGetProperty("textHaloColor", out haloColor)) { haloColorNullable = haloColor; } int haloRadius; int? haloRadiusNullable = null; if (rule.TryGetProperty("textHaloRadius", out haloRadius)) { haloRadiusNullable = haloRadius; } string fontFamily; if (!rule.TryGetProperty("fontFamily", out fontFamily)) { fontFamily = "Arial"; // just some default font. } string name; if (way.Tags.TryGetValue(nameTag, out name)) { scene.AddStyleLineText(pointsId.Value, this.CalculateSceneLayer(OffsetLineText, zIndex), minZoom, maxZoom, textColor, fontSize, name, fontFamily, haloColorNullable, haloRadiusNullable); } } } } } } else { // don't report as an error when no nodes. success = true; } } if(!success) { // make sure this sucess is stored. _succesfullWays[relevantTags] = null; } return success; }
/// <summary> /// Initialize implementation from IMapView. /// </summary> /// <param name="mapLayout"></param> void IMapViewSurface.Initialize(MapView mapLayout) { _mapView = mapLayout; this.SetWillNotDraw(false); this.MapMinZoomLevel = 10; this.MapMaxZoomLevel = 20; _renderer = new MapRenderer<global::Android.Graphics.Canvas>( new CanvasRenderer2D()); // initialize the gesture detection. this.SetOnTouchListener(this); _scaleGestureDetector = new ScaleGestureDetector( this.Context, this); _rotateGestureDetector = new RotateGestureDetector( this.Context, this); _moveGestureDetector = new MoveGestureDetector( this.Context, this); _tagGestureDetector = new TapGestureDetector( this.Context, this); _makerLayer = new LayerPrimitives( new WebMercator()); // initialize all the caching stuff. _cacheRenderer = new MapRenderer<global::Android.Graphics.Canvas>( new CanvasRenderer2D()); _scene = new Scene2DSimple(); _scene.BackColor = SimpleColor.FromKnownColor(KnownColor.White).Value; new Timer(InvalidateSimple, null, 0, 50); }
/// <summary> /// Creates a new primitives layer. /// </summary> public LayerPrimitives(IProjection projection) { _projection = projection; _scene = new Scene2D(projection, 16); }
/// <summary> /// Dispose the specified disposing. /// </summary> /// <param name="disposing">If set to <c>true</c> disposing.</param> protected override void Dispose(bool disposing) { base.Dispose (disposing); _cachedScene.Clear (); _cachedScene = null; _renderingThread.Abort (); _renderingThread = null; _bytescache = null; }