Exemple #1
0
        /// <summary>
        /// 定位至某点
        /// </summary>
        /// <param name="latlng">经纬度</param>
        public void ZoomTo(PointLatLng latlng)
        {
            if (gmapControl.InvokeRequired)
            {
                gmapControl.Invoke(new Action(delegate
                {
                    gmapControl.Overlays.Add(overlay);
                    GMarkerGoogle editMarker = new GMarkerGoogle(latlng, GMarkerGoogleType.arrow);
                    overlay.Markers.Add(editMarker);
                }));
            }
            else
            {
                gmapControl.Overlays.Add(overlay);
                GMarkerGoogle editMarker = new GMarkerGoogle(latlng, GMarkerGoogleType.arrow);
                overlay.Markers.Add(editMarker);
            }

            Thread.Sleep(1500);   // 1.5秒后消失

            if (gmapControl.InvokeRequired)
            {
                gmapControl.Invoke(new Action(delegate
                {
                    gmapControl.Overlays.Remove(overlay);
                }));
            }
            else
            {
                gmapControl.Overlays.Remove(overlay);
            }
        }
Exemple #2
0
        /// <summary>
        /// 移除图层
        /// </summary>
        /// <param name="layerName">图层名称</param>
        /// <returns></returns>
        public bool RemoverLayer(string layerName)
        {
            lock (layerDic)
            {
                if (!layerDic.ContainsKey(layerName))
                {
                    return(true);
                }

                GMapOverlay layer = layerDic[layerName];

                if (mapControl.InvokeRequired)
                {
                    mapControl.Invoke(new Action(delegate
                    {
                        mapControl.Overlays.Remove(layer);
                        mapControl.Refresh();
                    }));
                }
                else
                {
                    mapControl.Overlays.Remove(layer);
                    mapControl.Refresh();
                }

                layerDic.Remove(layerName);
                return(true);
            }
        }
Exemple #3
0
        private void RefreshEx()
        {
            TimeSpan span = DateTime.Now - lastTime;

            if (span.TotalMilliseconds < refreshTimer.Interval)
            {
                refreshTimer.Start();
            }
            else
            {
                // 单位时间内,只执行一次,且是在单位时间结束时执行
                if (mapControl.InvokeRequired)
                {
                    mapControl.Invoke(new Action(delegate
                    {
                        mapControl.Refresh();
                    }));
                }
                else
                {
                    mapControl.Refresh();
                }
            }

            lastTime = DateTime.Now;
        }
Exemple #4
0
        /// <summary>
        /// 定位至某点
        /// </summary>
        /// <param name="lngLat">经纬度</param>
        /// <param name="zoomLevel">缩放级别,默认不缩放</param>
        public void ZoomToPosition(MapLngLat lngLat, int?zoomLevel = null)
        {
            PointLatLng latlng = new global::GMap.NET.PointLatLng(lngLat.Lat, lngLat.Lng);

            if (zoomLevel != null && zoomLevel > 0)
            {
                gmapControl.Zoom = (double)zoomLevel;

                // 启动动画效果
                ThreadPool.QueueUserWorkItem(obj =>
                {
                    using (ZoomToPosition zoomTo = new ZoomToPosition(gmapControl))
                    {
                        zoomTo.ZoomTo(latlng);
                    }
                });
            }

            if (gmapControl.InvokeRequired)
            {
                gmapControl.Invoke(new Action(delegate
                {
                    gmapControl.Position = latlng;
                }));
            }
            else
            {
                gmapControl.Position = latlng;
            }
        }
 internal override void AddEvents(FBAdapter i_FBAdapter, IEnumerable <object> i_Events)
 {
     m_GMapControl.Invoke(new Action(() => m_GMapControl.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance));
     m_GMapControl.Invoke(new Action(() => m_GMapControl.SetPositionByKeywords("dubnov, Tel Aviv, Israel")));
     m_MarkersOverlay = new GMapOverlay("markers");
     foreach (object fbEvent in i_Events)
     {
         if (i_FBAdapter.HasLocationEvent(fbEvent))
         {
             //PointLatLng point = GetPosition(i_FBAdapter.GetLatLong(fbEvent));
             PointD      eventLocation = i_FBAdapter.GetLatLong(fbEvent);
             PointLatLng point         = new PointLatLng(eventLocation.X, eventLocation.Y);
             GMap.NET.WindowsForms.Markers.GMarkerGoogle marker = new GMap.NET.WindowsForms.Markers.GMarkerGoogle(
                 point,
                 GMap.NET.WindowsForms.Markers.GMarkerGoogleType.red_small);
             marker.ToolTipText = i_FBAdapter.GetEventName(fbEvent);
             m_MarkersOverlay.Markers.Add(marker);
         }
     }
 }
Exemple #6
0
 public void SetGMapControlOverlayPropertyThreadSafe(GMapControl control, string propertyName, int index, object propertyValue)
 {
     try
     {
         if (control.InvokeRequired)
         {
             control.Invoke(new SetGMapControlOverlayPropertyThreadSafeDelegate(SetGMapControlOverlayPropertyThreadSafe), new object[] { control, propertyName, index, propertyValue });
         }
         else
         {
             control.Overlays[index].Routes[index].GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control.Overlays[index].Routes[index], new object[] { propertyValue });
         }
     }
     catch (Exception e)
     {
     }
 }
Exemple #7
0
        private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            lock (lockObj)
            {
                isRefreshCall = true;
                refreshTimer.Stop();
            }

            // 单位时间内,只执行一次,且是在单位时间结束时执行
            if (gmapControl.InvokeRequired)
            {
                gmapControl.Invoke(new Action(delegate
                {
                    gmapControl.Refresh();
                }));
            }
            else
            {
                gmapControl.Refresh();
            }
        }
Exemple #8
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;

            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = await GetBestBall(encounter);

                if (pokeball == ItemId.ItemUnknown)
                {
                    Logger.Write(
                        $"No Pokeballs - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}",
                        LogLevel.Caught);
                    return;
                }
                if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) ||
                    PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                    _clientSettings.KeepMinIVPercentage)
                {
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnPointId);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude,
                                                                       pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse =
                    await
                    _client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        _stats.AddExperience(xp);
                    }
                    _stats.IncreasePokemons();
                    var profile = await _client.Player.GetPlayer();

                    _stats.GetStardust(profile.PlayerData.Currencies.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_inventory);

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    Func <ItemId, string> returnRealBallName = a =>
                    {
                        switch (a)
                        {
                        case ItemId.ItemPokeBall:
                            return("Poke");

                        case ItemId.ItemGreatBall:
                            return("Great");

                        case ItemId.ItemUltraBall:
                            return("Ultra");

                        case ItemId.ItemMasterBall:
                            return("Master");

                        default:
                            return("Unknown");
                        }
                    };
                    var catchStatus = attemptCounter > 1
                        ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}"
                        : $"{caughtPokemonResponse.Status}";

                    var color = ConsoleColor.Green;

                    if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee)
                    {
                        color = ConsoleColor.Red;
                    }

                    Logger.Write(
                        $"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter.WildPokemon?.PokemonData)} ({encounter.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter.WildPokemon?.PokemonData)).ToString("0.00")}% perfect) | Chance: {Math.Round(Convert.ToDouble(encounter.CaptureProbability?.CaptureProbability_.First())*100, 2)}% | {Math.Round(distance)}m dist | with a {returnRealBallName(pokeball)}Ball.",
                        LogLevel.Caught, color);

                    if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                    {
                        _caughtInSession.Add(encounter.WildPokemon?.PokemonData);
                        _narrator.Speak($"{pokemon.PokemonId}, {encounter.WildPokemon?.PokemonData?.Cp}");
                        Statistics.KeptPokemon++;

                        _map.Invoke(new MethodInvoker(delegate() {
                            var pokemonOverlay     = _map.Overlays[3];
                            GMapMarker foundMarker = null;

                            for (int i = 0; i < pokemonOverlay.Markers.Count; i++)
                            {
                                var marker = pokemonOverlay.Markers[i];

                                if (Math.Round(marker.Position.Lat, 12) == Math.Round(encounter.WildPokemon.Latitude, 12) &&
                                    Math.Round(marker.Position.Lng, 12) == Math.Round(encounter.WildPokemon.Longitude, 12))
                                {
                                    foundMarker = marker;
                                    break;
                                }
                            }

                            var position = new GMap.NET.PointLatLng(Math.Round(encounter.WildPokemon.Latitude, 12), Math.Round(encounter.WildPokemon.Longitude, 12));
                            _client.Map.CaughtMarkers.Add(new KeyValuePair <int, GMap.NET.PointLatLng>((int)pokemon.PokemonId, position));

                            if (foundMarker != null)
                            {
                                pokemonOverlay.Markers.Remove(foundMarker);
                            }
                        }));
                    }
                }
                attemptCounter++;
                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }