<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xaml.Interactivity;
using PocketCampus.Map.Models;
using PocketCampus.Map.ViewModels;
using ThinMvvm;
using Windows.ApplicationModel;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Maps;
using Windows.UI.Xaml.Media.Imaging;

namespace PocketCampus.Map
{
    // HACK: The way children are set/accessed is ugly, slow and brittle
    // HACK: The way the ViewModel is accessed is just as ugly and brittle
    // TODO: Apply some basic SwEng :) split it into multiple parts, avoid hacks, etc.
    public sealed class EpflMapBehavior : DependencyObject, IBehavior
    {
        #region ItemTemplate
        public DataTemplate ItemTemplate
        {
            get { return (DataTemplate) GetValue( ItemTemplateProperty ); }
            set { SetValue( ItemTemplateProperty, value ); }
        }

        public static readonly DependencyProperty ItemTemplateProperty =
            DependencyProperty.Register( "ItemTemplate", typeof( DataTemplate ), typeof( EpflMapBehavior ), new PropertyMetadata( null ) );
        #endregion

        #region ItemAnchorX
        public double ItemAnchorX
        {
            get { return (double) GetValue( ItemAnchorXProperty ); }
            set { SetValue( ItemAnchorXProperty, value ); }
        }

        public static readonly DependencyProperty ItemAnchorXProperty =
            DependencyProperty.Register( "ItemAnchorX", typeof( double ), typeof( EpflMapBehavior ), new PropertyMetadata( 0.0 ) );
        #endregion

        #region ItemAnchorY
        public double ItemAnchorY
        {
            get { return (double) GetValue( ItemAnchorYProperty ); }
            set { SetValue( ItemAnchorYProperty, value ); }
        }

        public static readonly DependencyProperty ItemAnchorYProperty =
            DependencyProperty.Register( "ItemAnchorY", typeof( double ), typeof( EpflMapBehavior ), new PropertyMetadata( 0.0 ) );
        #endregion

        #region DisabledItemOpacity
        public double DisabledItemOpacity
        {
            get { return (double) GetValue( DisabledItemOpacityProperty ); }
            set { SetValue( DisabledItemOpacityProperty, value ); }
        }

        public static readonly DependencyProperty DisabledItemOpacityProperty =
            DependencyProperty.Register( "DisabledItemOpacity", typeof( double ), typeof( EpflMapBehavior ), new PropertyMetadata( 1.0 ) );
        #endregion


        private MainViewModel _vm;
        private MapControl _map;
        private MapProperties _properties;
        private Image _labelsOverlay;


        public DependencyObject AssociatedObject { get; private set; }

        public void Attach( DependencyObject associatedObject )
        {
            if ( DesignMode.DesignModeEnabled )
            {
                return;
            }

            AssociatedObject = associatedObject;
            _map = (MapControl) associatedObject;
            _labelsOverlay = new Image();
            _labelsOverlay.ImageOpened += ( _, __ ) =>
            {
                Geopoint topLeft;
                _map.GetLocationFromOffset( new Point( 0, 0 ), out topLeft );
                MapControl.SetLocation( _labelsOverlay, topLeft );
                _labelsOverlay.Visibility = Visibility.Visible;
            };
            _map.Children.Add( _labelsOverlay );

            _map.Loaded += ( _, __ ) =>
            {
                _vm = (MainViewModel) _map.DataContext;

                OnFloorChanged( _vm.Properties.Floor );
                OnItemsChanged( _vm.SearchResults );

                _properties = _vm.Properties;

                _vm.Properties.ListenToProperty( x => x.Center, UpdateLabelsOverlay );
                _vm.Properties.ListenToProperty( x => x.Floor, UpdateLabelsOverlay );
                _vm.Properties.ListenToProperty( x => x.ZoomLevel, UpdateLabelsOverlay );
                UpdateLabelsOverlay();

                _vm.Properties.ListenToProperty( x => x.Floor, () => OnFloorChanged( _vm.Properties.Floor ) );
                _vm.ListenToProperty( x => x.SearchResults, () => OnItemsChanged( _vm.SearchResults ) );

                var buildingsDataSource = EpflTileSources.GetForBuildings( _vm.Properties );
                _map.TileSources.Add( new MapTileSource( buildingsDataSource ) );
            };
        }

        public void Detach()
        {
            throw new NotSupportedException();
        }
<commit_msg>[map.wp81] Disable map rotation (EPFL labels can't be rotated).<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xaml.Interactivity;
using PocketCampus.Map.Models;
using PocketCampus.Map.ViewModels;
using ThinMvvm;
using Windows.ApplicationModel;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Maps;
using Windows.UI.Xaml.Media.Imaging;

namespace PocketCampus.Map
{
    // HACK: The way children are set/accessed is ugly, slow and brittle
    // HACK: The way the ViewModel is accessed is just as ugly and brittle
    // TODO: Apply some basic SwEng :) split it into multiple parts, avoid hacks, etc.
    public sealed class EpflMapBehavior : DependencyObject, IBehavior
    {
        #region ItemTemplate
        public DataTemplate ItemTemplate
        {
            get { return (DataTemplate) GetValue( ItemTemplateProperty ); }
            set { SetValue( ItemTemplateProperty, value ); }
        }

        public static readonly DependencyProperty ItemTemplateProperty =
            DependencyProperty.Register( "ItemTemplate", typeof( DataTemplate ), typeof( EpflMapBehavior ), new PropertyMetadata( null ) );
        #endregion

        #region ItemAnchorX
        public double ItemAnchorX
        {
            get { return (double) GetValue( ItemAnchorXProperty ); }
            set { SetValue( ItemAnchorXProperty, value ); }
        }

        public static readonly DependencyProperty ItemAnchorXProperty =
            DependencyProperty.Register( "ItemAnchorX", typeof( double ), typeof( EpflMapBehavior ), new PropertyMetadata( 0.0 ) );
        #endregion

        #region ItemAnchorY
        public double ItemAnchorY
        {
            get { return (double) GetValue( ItemAnchorYProperty ); }
            set { SetValue( ItemAnchorYProperty, value ); }
        }

        public static readonly DependencyProperty ItemAnchorYProperty =
            DependencyProperty.Register( "ItemAnchorY", typeof( double ), typeof( EpflMapBehavior ), new PropertyMetadata( 0.0 ) );
        #endregion

        #region DisabledItemOpacity
        public double DisabledItemOpacity
        {
            get { return (double) GetValue( DisabledItemOpacityProperty ); }
            set { SetValue( DisabledItemOpacityProperty, value ); }
        }

        public static readonly DependencyProperty DisabledItemOpacityProperty =
            DependencyProperty.Register( "DisabledItemOpacity", typeof( double ), typeof( EpflMapBehavior ), new PropertyMetadata( 1.0 ) );
        #endregion


        private MainViewModel _vm;
        private MapControl _map;
        private MapProperties _properties;
        private Image _labelsOverlay;


        public DependencyObject AssociatedObject { get; private set; }

        public void Attach( DependencyObject associatedObject )
        {
            if ( DesignMode.DesignModeEnabled )
            {
                return;
            }

            AssociatedObject = associatedObject;
            _map = (MapControl) associatedObject;
            _labelsOverlay = new Image();
            _labelsOverlay.ImageOpened += ( _, __ ) =>
            {
                Geopoint topLeft;
                _map.GetLocationFromOffset( new Point( 0, 0 ), out topLeft );
                MapControl.SetLocation( _labelsOverlay, topLeft );
                _labelsOverlay.Visibility = Visibility.Visible;
            };
            _map.Children.Add( _labelsOverlay );

            _map.Loaded += ( _, __ ) =>
            {
                _vm = (MainViewModel) _map.DataContext;

                OnFloorChanged( _vm.Properties.Floor );
                OnItemsChanged( _vm.SearchResults );

                _properties = _vm.Properties;

                _vm.Properties.ListenToProperty( x => x.Center, UpdateLabelsOverlay );
                _vm.Properties.ListenToProperty( x => x.Floor, UpdateLabelsOverlay );
                _vm.Properties.ListenToProperty( x => x.ZoomLevel, UpdateLabelsOverlay );
                UpdateLabelsOverlay();

                _vm.Properties.ListenToProperty( x => x.Floor, () => OnFloorChanged( _vm.Properties.Floor ) );
                _vm.ListenToProperty( x => x.SearchResults, () => OnItemsChanged( _vm.SearchResults ) );

                var buildingsDataSource = EpflTileSources.GetForBuildings( _vm.Properties );
                _map.TileSources.Add( new MapTileSource( buildingsDataSource ) );
            };

            // HACK: Force the map to always face North, so that buildings labels are shown properly.
            _map.HeadingChanged += ( _, __ ) => _map.Heading = 0;
        }

        public void Detach()
        {
            throw new NotSupportedException();
        }

{'fraction_non_alphanumeric': 0.08151769582314805, 'fraction_numerical': 0.00201934318205973, 'mean_word_length': 2.312214009151707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '5895320', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2325, 'n_words': 600}