public double LimitResolution(double resolution, double screenWidth, double screenHeight, IReadOnlyList <double> mapResolutions, MRect?mapEnvelope) { if (ZoomMode == ZoomMode.Unlimited) { return(resolution); } var resolutionExtremes = ZoomLimits ?? GetExtremes(mapResolutions); if (resolutionExtremes == null) { return(resolution); } if (ZoomMode == ZoomMode.KeepWithinResolutions) { if (resolutionExtremes.Min > resolution) { return(resolutionExtremes.Min); } if (resolutionExtremes.Max < resolution) { return(resolutionExtremes.Max); } } return(resolution); }
/// <summary> /// Initializes a new instance of the MemoryProvider /// </summary> /// <param name="feature">Feature to be in this dataSource</param> public MemoryProvider(T feature) { Features = new List <T> { feature }; _boundingBox = GetExtent(Features); }
public bool Intersects(MRect?rect) { if (rect is null) { return(false); } if (rect.Max.X < Min.X) { return(false); } if (rect.Max.Y < Min.Y) { return(false); } if (rect.Min.X > Max.X) { return(false); } if (rect.Min.Y > Max.Y) { return(false); } return(true); }
private static ILayer CreateLayerWithStyleOnLayer(MRect?envelope, int count = 25) { return(new Layer("Style on Layer") { DataSource = new MemoryProvider <PointFeature>(RandomPointGenerator.GenerateRandomPoints(envelope, count).ToFeatures()), Style = CreateBitmapStyle("Images.ic_place_black_24dp.png") }); }
public static IEnumerable <PointFeature> CreateRandomFeatures(MRect?envelope, int count, Random?random = null) { if (random == null) { random = new Random(123); } return(CreateFeatures(GenerateRandomPoints(envelope, count, random))); }
public bool Equals(MRect?other) { if (other is null) { return(false); } return(Min.Equals(other.Min) && Max.Equals(other.Max)); }
public static MemoryProvider CreateProviderWithRandomPoints(MRect?envelope, int count, Random?random = null) { if (random == null) { random = new Random(123); } return(new MemoryProvider(CreateFeatures(GenerateRandomPoints(envelope, count, random)))); }
private static ILayer CreateAtlasLayer(MRect?envelope) { return(new MemoryLayer { Name = AtlasLayerName, Features = CreateAtlasFeatures(RandomPointGenerator.GenerateRandomPoints(envelope, 1000)), Style = null, IsMapInfoLayer = true }); }
private static IEnumerable <IFeature> GenerateRandomFeatures(MRect?envelope, int count, IStyle style) { return(RandomPointGenerator.GenerateRandomPoints(envelope, count, 123) .Select(p => new PointFeature(p) { Styles = new List <IStyle> { style } }).ToList()); }
private static ILayer CreateLayerWithStyleOnFeature(MRect?envelope, int count = 25) { var style = CreateBitmapStyle("Images.loc.png"); return(new Layer("Style on feature") { DataSource = new MemoryProvider <IFeature>(GenerateRandomFeatures(envelope, count, style)), Style = null }); }
private static ILayer CreateSvgLayer(MRect?envelope) { return(new MemoryLayer { Name = "Svg Layer", DataSource = CreateMemoryProviderWithDiverseSymbols(envelope, 2000), Style = null, IsMapInfoLayer = true }); }
private static ILayer CreateStylesLayer(MRect?envelope) { return(new MemoryLayer { Name = "Styles Layer", Features = CreateDiverseFeatures(RandomPointGenerator.GenerateRandomPoints(envelope, 25)), Style = null, IsMapInfoLayer = true }); }
/// <summary> /// Navigate center of viewport to center of extent and change resolution /// </summary> /// <param name="extent">New extent for viewport to show</param> /// <param name="scaleMethod">Scale method to use to determine resolution</param> /// <param name="duration">Duration for animation in milliseconds.</param> /// <param name="easing">The type of easing function used to transform from begin tot end state</param> public void NavigateTo(MRect?extent, ScaleMethod scaleMethod = ScaleMethod.Fit, long duration = -1, Easing?easing = default) { if (extent == null) { return; } var resolution = ZoomHelper.DetermineResolution( extent.Width, extent.Height, _viewport.Width, _viewport.Height, scaleMethod); NavigateTo(extent.Centroid, resolution, duration, easing); }
public MRect Join(MRect?rect) { if (rect is null) { return(Copy()); } return(new MRect( Math.Min(Min.X, rect.Min.X), Math.Min(Min.Y, rect.Min.Y), Math.Max(Max.X, rect.Max.X), Math.Max(Max.Y, rect.Max.Y))); }
public override IEnumerable <IFeature> GetFeatures(MRect?rect, double resolution) { // Safeguard in case BoundingBox is null, most likely due to no features in layer if (rect == null) { return(new List <IFeature>()); } var biggerRect = rect.Grow( SymbolStyle.DefaultWidth * 2 * resolution, SymbolStyle.DefaultHeight * 2 * resolution); return(Features.Where(f => f.Extent?.Intersects(biggerRect) == true)); }
public static MRect?GetExtent(this IEnumerable <IFeature> features) { MRect?result = null; foreach (var feature in features) { if (feature.Extent is null) { continue; } result = result is null ? new MRect(feature.Extent): result.Join(feature.Extent); } return(result); }
public override IEnumerable <IFeature> GetFeatures(MRect?box, double resolution) { // Safeguard in case BoundingBox is null, most likely due to no features in layer if (box == null) { return(new List <IFeature>()); } var biggerBox = box.Grow( SymbolStyle.DefaultWidth * 2 * resolution, SymbolStyle.DefaultHeight * 2 * resolution); var fetchInfo = new FetchInfo(biggerBox, resolution, CRS); return(DataSource?.GetFeatures(fetchInfo) ?? Array.Empty <IFeature>()); }
private static MRect?GetExtent(IReadOnlyList <T> features) { MRect?box = null; foreach (var feature in features) { if (feature.Extent == null) { continue; } box = box == null ? feature.Extent : box.Join(feature.Extent); } return(box); }
/// <summary> /// Create tile layer for given tile source /// </summary> /// <param name="tileSource">Tile source to use for this layer</param> /// <param name="minTiles">Minimum number of tiles to cache</param> /// <param name="maxTiles">Maximum number of tiles to cache</param> /// <param name="dataFetchStrategy">Strategy to get list of tiles for given extent</param> /// <param name="renderFetchStrategy"></param> /// <param name="minExtraTiles">Number of minimum extra tiles for memory cache</param> /// <param name="maxExtraTiles">Number of maximum extra tiles for memory cache</param> /// <param name="fetchTileAsFeature">Fetch tile as feature</param> // ReSharper disable once UnusedParameter.Local // Is public and won't break this now public TileLayer(ITileSource tileSource, int minTiles = 200, int maxTiles = 300, IDataFetchStrategy?dataFetchStrategy = null, IRenderFetchStrategy?renderFetchStrategy = null, int minExtraTiles = -1, int maxExtraTiles = -1, Func <TileInfo, Task <IFeature?> >?fetchTileAsFeature = null) { _tileSource = tileSource ?? throw new ArgumentException($"{tileSource} can not null"); MemoryCache = new MemoryCache <IFeature?>(minTiles, maxTiles); Style = new RasterStyle(); Attribution.Text = _tileSource.Attribution?.Text; Attribution.Url = _tileSource.Attribution?.Url; _extent = _tileSource.Schema?.Extent.ToMRect(); dataFetchStrategy ??= new DataFetchStrategy(3); _renderFetchStrategy = renderFetchStrategy ?? new RenderFetchStrategy(); _minExtraTiles = minExtraTiles; _maxExtraTiles = maxExtraTiles; _tileFetchDispatcher = new TileFetchDispatcher(MemoryCache, _tileSource.Schema, fetchTileAsFeature ?? ToFeatureAsync, dataFetchStrategy); _tileFetchDispatcher.DataChanged += TileFetchDispatcherOnDataChanged; _tileFetchDispatcher.PropertyChanged += TileFetchDispatcherOnPropertyChanged; }
/// <summary> /// Create tile layer for given tile source /// </summary> /// <param name="tileSource">Tile source to use for this layer</param> /// <param name="minTiles">Minimum number of tiles to cache</param> /// <param name="maxTiles">Maximum number of tiles to cache</param> /// <param name="dataFetchStrategy">Strategy to get list of tiles for given extent</param> /// <param name="renderFetchStrategy"></param> /// <param name="minExtraTiles">Number of minimum extra tiles for memory cache</param> /// <param name="maxExtraTiles">Number of maximum extra tiles for memory cache</param> /// <param name="fetchTileAsFeature">Fetch tile as feature</param> // ReSharper disable once UnusedParameter.Local // Is public and won't break this now public TileLayer(ITileSource tileSource, int minTiles = 200, int maxTiles = 300, IDataFetchStrategy?dataFetchStrategy = null, IRenderFetchStrategy?renderFetchStrategy = null, int minExtraTiles = -1, int maxExtraTiles = -1, Func <TileInfo, IFeature?>?fetchTileAsFeature = null) { _tileSource = tileSource ?? throw new ArgumentException($"{tileSource} can not null"); MemoryCache = new MemoryCache <IFeature?>(minTiles, maxTiles); Style = new VectorStyle { Outline = { Color = Color.FromArgb(0, 0, 0, 0) } }; // initialize with transparent outline Attribution.Text = _tileSource.Attribution?.Text; Attribution.Url = _tileSource.Attribution?.Url; _extent = _tileSource.Schema?.Extent.ToMRect(); dataFetchStrategy ??= new DataFetchStrategy(3); _renderFetchStrategy = renderFetchStrategy ?? new RenderFetchStrategy(); _minExtraTiles = minExtraTiles; _maxExtraTiles = maxExtraTiles; _tileFetchDispatcher = new TileFetchDispatcher(MemoryCache, _tileSource.Schema, fetchTileAsFeature ?? ToFeature, dataFetchStrategy); _tileFetchDispatcher.DataChanged += TileFetchDispatcherOnDataChanged; _tileFetchDispatcher.PropertyChanged += TileFetchDispatcherOnPropertyChanged; }
public static IEnumerable <Coordinate> GenerateRandomPoints(MRect?envelope, int count = 25) { var result = new List <Coordinate>(); if (envelope == null) { return(result); } for (var i = 0; i < count; i++) { result.Add(new Coordinate( Random.NextDouble() * envelope.Width + envelope.Left, Random.NextDouble() * envelope.Height + envelope.Bottom)); } result.Add(result[0].Copy()); // close polygon by adding start point. return(result); }
public static IEnumerable <MPoint> GenerateRandomPoints(MRect?envelope, int count = 25, int seed = 192) { _random = new Random(seed); var result = new List <MPoint>(); if (envelope == null) { return(result); } for (var i = 0; i < count; i++) { result.Add(new MPoint( _random.NextDouble() * envelope.Width + envelope.Left, _random.NextDouble() * envelope.Height + envelope.Bottom)); } return(result); }
public IList <IFeature> Get(MRect?extent, double resolution, ITileSchema schema, ITileCache <IFeature?> memoryCache) { var result = new List <IFeature>(); if (extent == null) { return(result); } var tiles = schema.GetTileInfos(extent.ToExtent(), resolution); foreach (var tileInfo in tiles) { var feature = memoryCache.Find(tileInfo.Index); if (feature != null) { result.Add(feature); } } return(result); }
private static ILayer CreateMutatingTriangleLayer(MRect?envelope) { var layer = new MemoryLayer(); var polygon = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3).ToArray())); var feature = new GeometryFeature(polygon); layer.Features = new List <IFeature> { feature }; PeriodicTask.RunAsync(() => { feature.Geometry = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3).ToArray())); // Clear cache for change to show feature.RenderedGeometry.Clear(); // Trigger DataChanged notification layer.DataHasChanged(); }, TimeSpan.FromMilliseconds(1000)); return(layer); }
public double LimitResolution(double resolution, double screenWidth, double screenHeight, IReadOnlyList <double> mapResolutions, MRect?mapEnvelope) { var zoomLimits = ZoomLimits ?? GetExtremes(mapResolutions); if (zoomLimits == null) { return(resolution); } var panLimit = PanLimits ?? mapEnvelope; if (panLimit == null) { return(resolution); } if (zoomLimits.Min > resolution) { return(zoomLimits.Min); } var viewportFillingResolution = CalculateResolutionAtWhichMapFillsViewport(screenWidth, screenHeight, panLimit); if (viewportFillingResolution < zoomLimits.Min) { return(resolution); // Mission impossible. Can't adhere to both restrictions } var limit = Math.Min(zoomLimits.Max, viewportFillingResolution); if (limit < resolution) { return(limit); } return(resolution); }
public void LimitExtent(Viewport viewport, MRect?mapEnvelope) { var maxExtent = PanLimits ?? mapEnvelope; if (maxExtent == null) { // Can be null because both panLimits and Map.Extent can be null. // The Map.Extent can be null if the extent of all layers is null return; } var x = viewport.Center.X; if (viewport.Extent?.Left < maxExtent.Left) { x += maxExtent.Left - viewport.Extent.Left; } else if (viewport.Extent?.Right > maxExtent.Right) { x += maxExtent.Right - viewport.Extent.Right; } var y = viewport.Center.Y; if (viewport.Extent?.Top > maxExtent.Top) { y += maxExtent.Top - viewport.Extent.Top; } else if (viewport.Extent?.Bottom < maxExtent.Bottom) { y += maxExtent.Bottom - viewport.Extent.Bottom; } viewport.CenterX = x; viewport.CenterY = y; }
/// <summary> /// Initializes a new instance of the MemoryProvider /// </summary> /// <param name="features">Features to be included in this dataSource</param> public MemoryProvider(IEnumerable <T> features) { Features = features.ToList(); _boundingBox = GetExtent(Features); }
public void Limit(Viewport viewport, IReadOnlyList <double> mapResolutions, MRect?mapEnvelope) { viewport.Resolution = LimitResolution(viewport.Resolution, viewport.Width, viewport.Height, mapResolutions, mapEnvelope); LimitExtent(viewport, mapEnvelope); }
public static MemoryProvider <PointFeature> CreateProviderWithRandomPoints(MRect?envelope, int count = 25, int seed = 123) { return(new MemoryProvider <PointFeature>(CreateFeatures(GenerateRandomPoints(envelope, count, seed)))); }
public MemoryProvider() { Features = new List <T>(); _boundingBox = GetExtent(Features); }