private void AddEntitiesIcons()
        {
            var lat = this.currentLatitude;
            var lng = this.currentLongitude;

            if (this.parameters.ShowSingleEntity)
            {
                this.currentEntity = this.parameters.Entity;
                AddEntityIconToMap(this.currentEntity);

                lat = this.currentEntity.Latitude;
                lng = this.currentEntity.Longitude;
            }
            else
            {
                if (!this.parameters.ShowSearchResults)
                {
                    // show more than one entity
                    if (this.parameters.ShowAllGroups)
                    {
                        ApplicationState.Groups.ForEach(g => g.TopItems.ForEach(AddEntityIconToMap));
                        var closest = ApplicationState.Groups.First().TopItems.First();
                        lat = closest.Latitude;
                        lng = closest.Longitude;
                    }
                    else
                    {
                        this.parameters.ShowGroup.Items.ForEach(AddEntityIconToMap);
                        var closest = this.parameters.ShowGroup.Items.First();
                        lat = closest.Latitude;
                        lng = closest.Longitude;
                    }
                }
                else
                {
                    // show search matches on the map
                    this.parameters.ShowGroup.Items.ForEach(AddEntityIconToMap);
                    var closest = this.parameters.ShowGroup.Items.First();
                    lat = closest.Latitude;
                    lng = closest.Longitude;
                }
            }

            CenterMap(lat, lng, DefaultZoomLevel);

            // zoom to closest
            this.map.SetView(
                             new LocationRect(
                                     new Location(
                                             Math.Max(this.currentLatitude, lat) + ViewPaddingCoeficient,
                                             Math.Min(this.currentLongitude, lng) - ViewPaddingCoeficient),
                                     new Location(
                                             Math.Min(this.currentLatitude, lat) - ViewPaddingCoeficient,
                                             Math.Max(this.currentLongitude, lng) + ViewPaddingCoeficient)));
        }
        protected override void LoadState(object navigationParameter, Dictionary<string, object> pageState)
        {
            this.entity = navigationParameter as EntityDataItem;
            if (this.entity == null)
            {
                return;
            }

            DefaultViewModel["Entity"] = this.entity;

            var s = MapHelper.CreateMiniMap(this.entity.Latitude, this.entity.Longitude, 15, 500, 300);
            this.mapSnapshot.Source = new BitmapImage(new Uri(s));

            SetIconOpacity();
        }
        public static EntityDataItem ConvertToDataItem(this Entity entity, EntityDataGroup group)
        {
            var result = new EntityDataItem(
                    entity.Id.ToString(),
                    entity.Title,
                    entity.DistanceView,
                    entity.Chain,
                    entity.Country,
                    entity.Address,
                    entity.Description,
                    entity.Latitude,
                    entity.Longitude,
                    group)
                             {
                                     CommissionWithdrawal = entity.ShowCommissionWithdrawalSign,
                                     CashDirection = entity.CashDirection,
                                     EntityType = entity.EntityType
                             };

            return result;
        }
        private void AddEntityIconToMap(EntityDataItem entity)
        {
            var entityPushpin = new Image { Source = entity.MapImage, Stretch = Stretch.None };
            this.map.Children.Add(entityPushpin);
            entityPushpin.Tapped += (sender, args) => Frame.Navigate(typeof(EntityDetailsPage), entity);

            MapLayer.SetPosition(entityPushpin, new Location(entity.Latitude, entity.Longitude));
            MapLayer.SetPositionAnchor(entityPushpin, new Point(27, 27));
        }