<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Mapsui.Layers;
using Mapsui.Projection;
using Mapsui.Providers;
using Mapsui.Rendering.Skia;
using Mapsui.Styles;
using Mapsui.UI;
using Mapsui.Utilities;
using Newtonsoft.Json;
using SkiaSharp;

// ReSharper disable UnusedAutoPropertyAccessor.Local

namespace Mapsui.Samples.Common.Maps
{
    public class CalloutSample : ISample
    {
        private static Random Random = new Random();

        public string Name => "1 Callout";
        public string Category => "Geometries";

        public void Setup(IMapControl mapControl)
        {
            mapControl.Map = CreateMap();
        }

        public static Map CreateMap()
        {
            var map = new Map();

            map.Layers.Add(OpenStreetMap.CreateTileLayer());
            map.Layers.Add(CreatePointLayer());
            map.Home = n => n.NavigateTo(map.Layers[1].Envelope.Centroid, map.Resolutions[5]);
            return map;
        }

        private static MemoryLayer CreatePointLayer()
        {
            return new MemoryLayer
            {
                Name = "Points",
                IsMapInfoLayer = true,
                DataSource = new MemoryProvider(GetCitiesFromEmbeddedResource()),
                Style = new VectorStyle() { }
            };
        }

        private static IEnumerable<IFeature> GetCitiesFromEmbeddedResource()
        {
            var path = "Mapsui.Samples.Common.EmbeddedResources.congo.json";
            var assembly = typeof(PointsSample).GetTypeInfo().Assembly;
            var stream = assembly.GetManifestResourceStream(path);
            var cities = DeserializeFromStream<City>(stream);

            return cities.Select(c =>
            {
                var feature = new Feature();
                var point = SphericalMercator.FromLonLat(c.Lng, c.Lat);
                feature.Geometry = point;
                feature["name"] = c.Name;
                feature["country"] = c.Country;

                var callbackImage = CreateCallbackImage(c);
                var bitmapId = BitmapRegistry.Instance.Register(callbackImage);
                var calloutStyle = CreateCalloutStyle(bitmapId);
                feature.Styles.Add(calloutStyle);

                return feature;
            });
        }

        private static IStyle CreateCalloutStyle(int bitmapId)
        {
            var calloutStyle = new CalloutStyle() { Content = bitmapId, ArrowPosition = Random.Next(1, 9) * 0.1f, RotateWithMap = true };
            switch (Random.Next(0, 4))
            {
                case 0:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Bottom;
                    calloutStyle.Offset = new Offset(0, SymbolStyle.DefaultHeight * 0.5f);
                    break;
                case 1:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Left;
                    calloutStyle.Offset = new Offset(SymbolStyle.DefaultHeight * 0.5f, 0);
                    break;
                case 2:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Top;
                    calloutStyle.Offset = new Offset(0, -SymbolStyle.DefaultHeight * 0.5f);
                    break;
                case 3:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Right;
                    calloutStyle.Offset = new Offset(-SymbolStyle.DefaultHeight * 0.5f, 0);
                    break;
            }
            calloutStyle.RectRadius = 10; // Random.Next(0, 9);
            calloutStyle.ShadowWidth = 4; // Random.Next(0, 9);
            calloutStyle.StrokeWidth = 0;
            return calloutStyle;<commit_msg>Removed a bug where Callout wasn't visible in WPF sample anymore<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Mapsui.Layers;
using Mapsui.Projection;
using Mapsui.Providers;
using Mapsui.Rendering.Skia;
using Mapsui.Styles;
using Mapsui.UI;
using Mapsui.Utilities;
using Newtonsoft.Json;
using SkiaSharp;

// ReSharper disable UnusedAutoPropertyAccessor.Local

namespace Mapsui.Samples.Common.Maps
{
    public class CalloutSample : ISample
    {
        private static Random Random = new Random();

        public string Name => "1 Callout";
        public string Category => "Geometries";

        public void Setup(IMapControl mapControl)
        {
            mapControl.Map = CreateMap();
        }

        public static Map CreateMap()
        {
            var map = new Map();

            map.Layers.Add(OpenStreetMap.CreateTileLayer());
            map.Layers.Add(CreatePointLayer());
            map.Home = n => n.NavigateTo(map.Layers[1].Envelope.Centroid, map.Resolutions[5]);
            return map;
        }

        private static MemoryLayer CreatePointLayer()
        {
            return new MemoryLayer
            {
                Name = "Points",
                IsMapInfoLayer = true,
                DataSource = new MemoryProvider(GetCitiesFromEmbeddedResource()),
                Style = new VectorStyle() { }
            };
        }

        private static IEnumerable<IFeature> GetCitiesFromEmbeddedResource()
        {
            var path = "Mapsui.Samples.Common.EmbeddedResources.congo.json";
            var assembly = typeof(PointsSample).GetTypeInfo().Assembly;
            var stream = assembly.GetManifestResourceStream(path);
            var cities = DeserializeFromStream<City>(stream);

            return cities.Select(c =>
            {
                var feature = new Feature();
                var point = SphericalMercator.FromLonLat(c.Lng, c.Lat);
                feature.Geometry = point;
                feature["name"] = c.Name;
                feature["country"] = c.Country;

                var callbackImage = CreateCallbackImage(c);
                var bitmapId = BitmapRegistry.Instance.Register(callbackImage);
                var calloutStyle = CreateCalloutStyle(bitmapId);
                feature.Styles.Add(calloutStyle);

                return feature;
            });
        }

        private static IStyle CreateCalloutStyle(int bitmapId)
        {
            var calloutStyle = new CalloutStyle() { Content = bitmapId, ArrowPosition = Random.Next(1, 9) * 0.1f, RotateWithMap = true, Type = CalloutType.Custom };
            switch (Random.Next(0, 4))
            {
                case 0:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Bottom;
                    calloutStyle.Offset = new Offset(0, SymbolStyle.DefaultHeight * 0.5f);
                    break;
                case 1:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Left;
                    calloutStyle.Offset = new Offset(SymbolStyle.DefaultHeight * 0.5f, 0);
                    break;
                case 2:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Top;
                    calloutStyle.Offset = new Offset(0, -SymbolStyle.DefaultHeight * 0.5f);
                    break;
                case 3:
                    calloutStyle.ArrowAlignment = ArrowAlignment.Right;
                    calloutStyle.Offset = new Offset(-SymbolStyle.DefaultHeight * 0.5f, 0);
                    break;
            }
            calloutStyle.RectRadius = 10; // Random.Next(0, 9);
            calloutStyle.ShadowWidth = 4; // Random.Next(0, 9);
            calloutStyle.StrokeWidth = 0;
            return calloutStyle;
{'fraction_non_alphanumeric': 0.08943305829118978, 'fraction_numerical': 0.008783603939313283, 'mean_word_length': 1.8051511758118701, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368440', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1893, 'n_words': 425}