Example #1
0
        public static ConfigurationData LoadConfiguration(string configurationName)
        {
            var data = new ConfigurationData();

            using(var ctx = new CityContainer())
            {
                var configuration = ctx.Configurations.Single(c => c.Name == configurationName);

                data.ConfigurationName = configurationName;

                // Load POI circle areas

                var circleAreaObjects = new List<CircleAreaObject>();

            // ReSharper disable LoopCanBeConvertedToQuery
                foreach (var circleArea in configuration.CircleAreas)
            // ReSharper restore LoopCanBeConvertedToQuery
                    circleAreaObjects.Add(new CircleAreaObject(circleArea.Lat, circleArea.Lng, circleArea.Range));

                data.CircleAreas = circleAreaObjects;

                // Load POI types

                data.PoiTypes = configuration.PoiTypes.Select(poiType => poiType.Code).ToList();

                var polygons = new List<MapDistrict>();
                foreach (var district in configuration.Districts)
                {
                    var newPolygon = new MapDistrict {DistrictName = district.Name, Population = district.Population, Locations = new LocationCollection()};

                    foreach (var mapPoint in district.MapPoints)
                        newPolygon.Locations.Add(new Location(mapPoint.Lat, mapPoint.Lng));

                    polygons.Add(newPolygon);
                }

                data.Polygons = polygons;

                // simulation settings
                data.SimulationMethodName = configuration.SelectionMethod.Name;
                data.DemandsPerPersonPerDay = configuration.PersonDemandsPerDay;
                data.SimulationStartDate = configuration.SimulationStartDate;
                data.SimulationEndDate = configuration.SimulationEndDate;

                data.CreditCardBalanceMin = configuration.CreditCardBalanceMin;
                data.CreditCardBalanceMax = configuration.CreditCardBalanceMax;
                data.CreditCardLimitMin = configuration.CreditCardLimitMin;
                data.CreditCardLimitMax = configuration.CreditCardLimitMax;
                data.TransactionValueMin = configuration.TransactionValueMin;
                data.TransactionValueMax = configuration.TransactionValueMax;
            }
            return data;
        }
        private void MyMap_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            districtPopulationTextBox.MoveFocus(new TraversalRequest(new FocusNavigationDirection()));
            Focus();

            if (_polygonLayer.Children.Count <= 0) return;

            var polygons = _polygonLayer.Children.Cast<MapDistrict>();

            var location = MyMap.ViewportPointToLocation(e.GetPosition(MyMap));

            foreach (var polygon in polygons)
            {
                var pointInPolygon = GeoUtilities.IsPointInPolygon(polygon.Locations, location);

                if (pointInPolygon)
                {
                    SelectedPolygon = polygon;
                    return;
                }
            }
            SelectedPolygon = null;
        }
        private void DeleteSelectedPolygon()
        {
            if (MessageBox.Show("Delete selected district?",
                "Delete confirmation", MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;

            _polygonLayer.Children.Remove(SelectedPolygon);
            SelectedPolygon = null;
        }
        private void MyMap_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_lastLinePoints.Count <= 3) return;

            SelectedPolygon = null;

            CreatePolygon();
        }
 private MapDistrict CreatePolygon(LocationCollection locationCollection, string districtName, int population)
 {
     var polygon = new MapDistrict
                       {
                           DistrictName = districtName,
                           Population = population,
                           Fill = new SolidColorBrush(_polygonFillColor),
                           Stroke = new SolidColorBrush(_polygonStrokeColor),
                           StrokeThickness = _polygonStrokeThickness,
                           Opacity = _polygonOpacity,
                           Locations = locationCollection
                       };
     return polygon;
 }