Exemplo n.º 1
0
        private void DoRequest()
        {
            Plugin.IsLoading = true;
            //var bagResult = Plugin.CreatePoiTypeResult("BAG", Colors.CornflowerBlue);

            var result = Plugin.CreatePoiTypeResult("MGRS", Colors.CornflowerBlue);
            result.Style.InnerTextColor = Colors.Black;
            Plugin.SearchService.PoITypes.Add(result);


            ThreadPool.QueueUserWorkItem(delegate
            {
                try
                {
                    string mgrsInput = Key;
                    var pois = new ContentList();

                    double[] latLonResult = csCommon.Converters.MgrsConversion.convertMgrsToLatLon(mgrsInput);
                    double lat = latLonResult[0];  
                    double lon = latLonResult[1];   

                    var p = new PoI
                    {
                        Service = Plugin.SearchService,
                        InnerText = "1",
                        Name = mgrsInput,
                        Position = new Position(lon, lat),
                    };

                    p.UpdateEffectiveStyle();
                    pois.Add(p);

                    Application.Current.Dispatcher.Invoke(
                        delegate
                        {
                            lock (Plugin.ServiceLock)
                            {
                                foreach (var q in pois) {
                                    Plugin.SearchService.PoIs.Add(q);
                                }
                            }
                            Plugin.IsLoading = false;
                        });

                }
                catch (Exception e)
                {
                    Logger.Log("MGRS search", "Error finding MGRS location", e.Message, Logger.Level.Error, true);
                    Plugin.IsLoading = false;
                }
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a link between source and sink.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="sink"></param>
        /// <returns></returns>
        private PoI CreateLinkBetweenPoIs(VisitedLocation source, VisitedLocation sink)
        {
            var link = new PoI
            {
                Id        = Guid.NewGuid(),
                Name      = "Path",
                Position  = source.Position, // Although not needed, if I don't supply this, the app freezes
                PoiTypeId = linkPoiType,
                UserId    = PoI.Id.ToString(),
                Layer     = PoI.Layer + "_path",

                Labels = new Dictionary<string, string> {
                    {KeyCreatorId,      PoI.Id.ToString()},
                    {KeySourceId,       source.Id.ToString()},
                    {KeySinkId,         sink.Id.ToString()},
                    {KeyStrokeColor,    sink.StrokeColor},
                    {KeyLabelStartTime, source.TimeOfVisit.ToString("yyyy-MM-dd HH:mm:ss")},
                    {KeyLabelEndTime,   sink  .TimeOfVisit.ToString("yyyy-MM-dd HH:mm:ss")},
                    {KeyLabelDuration,  (sink.TimeOfVisit - source.TimeOfVisit).ToString("dd'.'hh':'mm':'ss")},
                    {KeyAnimateMove,    source.Transition},
                    {"IsActive",        "false"}
                },
                Points = CreatePath(source, sink)
            };
            var convertFromString = ColorConverter.ConvertFromString(sink.StrokeColor);
            link.Style = new PoIStyle { CanMove = false, CanDelete = false, StrokeColor = convertFromString != null ? (Color)convertFromString : Colors.Blue, StrokeWidth = 3 };
            link.Style.DrawingMode = DrawingModes.Polyline;
            link.UpdateEffectiveStyle();
            var s = link.DrawingMode;
            return link;
        }
Exemplo n.º 3
0
        private void DoRequest()
        {
            Plugin.IsLoading = true;
            var bagResult = Plugin.CreatePoiTypeResult("BAG", Colors.CornflowerBlue);
            bagResult.Style.InnerTextColor = Colors.Black;
            bagResult.AddMetaInfo("Adres", "Adres");
            bagResult.AddMetaInfo("Postcode", "Postcode");
            bagResult.AddMetaInfo("Woonplaats", "Woonplaats");
            bagResult.AddMetaInfo("Gemeente", "Gemeente");
            bagResult.AddMetaInfo("Provincie", "Provincie");
            Plugin.SearchService.PoITypes.Add(bagResult);

            ThreadPool.QueueUserWorkItem(delegate
            {
                try
                {
                    string cmdString;
                    if (ZipCodeAndHouseNumberRegex.IsMatch(Key))
                    {
                        // Search for a zip code
                        var ms = ZipCodeAndHouseNumberRegex.Match(Key);

                        var zipNumbers  = ms.Groups["zipNumber"]       .Value.Trim();
                        var zipLetters  = ms.Groups["zipLetter"]       .Value.Trim().ToUpper();
                        var houseNumber = ms.Groups["houseNumberStart"].Value.Trim();

                        if (string.IsNullOrEmpty(houseNumber)) houseNumber = ms.Groups["houseNumberEnd"].Value.Trim();
                        cmdString = string.IsNullOrEmpty(houseNumber)
                            ? string.Format(ZipCodeLookupCommand,          zipNumbers, zipLetters)
                            : string.Format(ZipCodeAndNumberLookupCommand, zipNumbers, zipLetters, houseNumber);
                    }
                    else
                    {
                        // Search for a generic address
                        var input = substitutions.Keys.Aggregate(Key, (current, key) => current.Replace(key, substitutions[key]));
                        var keywords = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        cmdString = string.Format(AddresLookupCommand, string.Join("&", keywords));
                    }

                    var pois = new ContentList();
                    using (var conn = new NpgsqlConnection(ConnectionString))
                    {
                        conn.Open();

                        using (var command = new NpgsqlCommand(cmdString, conn))
                        {
                            using (var dr = command.ExecuteReader())
                            {
                                var count = 0;
                                while (dr.Read())
                                {
                                    count++;

                                    var position = ConvertPointZToPosition(dr.GetString(dr.GetOrdinal("location")));

                                    var p = new PoI
                                    {
                                        Service = Plugin.SearchService,
                                        InnerText = count.ToString(CultureInfo.InvariantCulture),
                                        PoiTypeId = bagResult.ContentId,
                                        PoiType = bagResult,
                                        Position = position
                                    };
                                    AddAddress(p, dr);
                                    p.UpdateEffectiveStyle();
                                    pois.Add(p);
                                }
                            }
                        }
                    }

                    Application.Current.Dispatcher.Invoke(
                        delegate
                        {
                            lock (Plugin.ServiceLock)
                            {
                                pois.ForEach(p => Plugin.SearchService.PoIs.Add(p));
                            }
                            Plugin.IsLoading = false;
                        });
                }
                catch (NpgsqlException e)
                {
                    Logger.Log("BAG Geocoding", "Error finding location", e.Message, Logger.Level.Error, true);
                    Plugin.IsLoading = false;
                }
            });
        }