Beispiel #1
0
        public static MapThumb GetDefaultInstance()
        {
            Type classType;

            MapProvider confValue = SettingCommon.Instance.MapThumbnailProvider;

            switch (confValue)
            {
            case MapProvider.OpenStreetMap:
                classType = typeof(MapThumbOSM);
                break;

            case MapProvider.GoogleMaps:
                classType = typeof(MapThumbGoogle);
                break;

            default:
                throw new NotSupportedException("Map Provider '" + confValue + "' is not supported.");
            }

            if (MapThumb.defaultInstance == null || MapThumb.defaultInstance.GetType() != classType)
            {
                MapThumb.defaultInstance = Activator.CreateInstance(classType) as MapThumb;
            }

            return(MapThumb.defaultInstance);
        }
Beispiel #2
0
        public static List <ThumbnailInfo> GetThumbnails(PostClass post)
        {
            var thumbnails = new List <ThumbnailInfo>();

            if (post.Media != null)
            {
                foreach (var media in post.Media)
                {
                    var thumbInfo = ThumbnailGenerator.GetThumbnailInfo(media.Value, post);
                    if (thumbInfo != null)
                    {
                        thumbnails.Add(thumbInfo);
                    }
                }
            }

            if (post.PostGeo != null && !(post.PostGeo.Lat == 0 && post.PostGeo.Lng == 0))
            {
                var map = MapThumb.GetDefaultInstance();
                thumbnails.Add(new ThumbnailInfo()
                {
                    ImageUrl     = map.CreateMapLinkUrl(post.PostGeo.Lat, post.PostGeo.Lng),
                    ThumbnailUrl = map.CreateStaticMapUrl(post.PostGeo.Lat, post.PostGeo.Lng),
                    TooltipText  = null,
                });
            }

            return(thumbnails);
        }
Beispiel #3
0
        public static async Task <IEnumerable <ThumbnailInfo> > GetThumbnailsAsync(PostClass post, CancellationToken token)
        {
            var thumbnails = new List <ThumbnailInfo>();

            if (post.Media != null)
            {
                foreach (var media in post.Media)
                {
                    var thumbInfo = await ThumbnailGenerator.GetThumbnailInfoAsync(media, post, token)
                                    .ConfigureAwait(false);

                    if (thumbInfo != null)
                    {
                        thumbnails.Add(thumbInfo);
                    }

                    token.ThrowIfCancellationRequested();
                }
            }

            if (post.PostGeo != null && !(post.PostGeo.Lat == 0 && post.PostGeo.Lng == 0))
            {
                var map = MapThumb.GetDefaultInstance();
                thumbnails.Add(new ThumbnailInfo()
                {
                    ImageUrl     = map.CreateMapLinkUrl(post.PostGeo.Lat, post.PostGeo.Lng),
                    ThumbnailUrl = map.CreateStaticMapUrl(post.PostGeo.Lat, post.PostGeo.Lng),
                    TooltipText  = null,
                });
            }

            return(thumbnails);
        }
Beispiel #4
0
        public static async Task <IEnumerable <ThumbnailInfo> > GetThumbnailsAsync(PostClass post, CancellationToken token)
        {
            var thumbnails = new List <ThumbnailInfo>();

            var expandedUrls = Enumerable.Concat(
                post.GetExpandedUrls(), post.Media.Select(x => x.Url));

            foreach (var expandedUrl in expandedUrls)
            {
                var thumbInfo = await ThumbnailGenerator.GetThumbnailInfoAsync(expandedUrl, post, token)
                                .ConfigureAwait(false);

                if (thumbInfo != null)
                {
                    thumbnails.Add(thumbInfo);
                }

                token.ThrowIfCancellationRequested();
            }

            if (post.PostGeo != null)
            {
                var map   = MapThumb.GetDefaultInstance();
                var thumb = await map.GetThumbnailInfoAsync(post.PostGeo.Value)
                            .ConfigureAwait(false);

                thumbnails.Add(thumb);
            }

            return(thumbnails);
        }
Beispiel #5
0
        public static MapThumb GetDefaultInstance()
        {
            var confValue = SettingManager.Common.MapThumbnailProvider;
            var classType = confValue switch
            {
                MapProvider.OpenStreetMap => typeof(MapThumbOSM),
                MapProvider.GoogleMaps => typeof(MapThumbGoogle),
                _ => throw new NotSupportedException($"Map Provider '{confValue}' is not supported."),
            };

            if (MapThumb.defaultInstance == null || MapThumb.defaultInstance.GetType() != classType)
            {
                MapThumb.defaultInstance = (MapThumb)Activator.CreateInstance(classType);
            }

            return(MapThumb.defaultInstance);
        }
Beispiel #6
0
        public static MapThumb GetDefaultInstance()
        {
            Type classType;

            MapProvider confValue = SettingCommon.Instance.MapThumbnailProvider;
            switch (confValue)
            {
                case MapProvider.OpenStreetMap:
                    classType = typeof(MapThumbOSM);
                    break;
                case MapProvider.GoogleMaps:
                    classType = typeof(MapThumbGoogle);
                    break;
                default:
                    throw new NotSupportedException("Map Provider '" + confValue + "' is not supported.");
            }

            if (MapThumb.defaultInstance == null || MapThumb.defaultInstance.GetType() != classType)
            {
                MapThumb.defaultInstance = Activator.CreateInstance(classType) as MapThumb;
            }

            return MapThumb.defaultInstance;
        }