Inheritance: BaseContent
Esempio n. 1
0
 public IModelPoiInstance GetPoiInstance(PoI poi)
 {
     var ncp = new LocationPoi { Poi = poi, Model = this };
    
     poi.ModelInstances[Id] = ncp;
     return ncp;
 }
Esempio n. 2
0
 public void RemovePoiInstance(PoI poi)
 {
     // TODO Remove all network connections that were created by this POI.
     if (!poi.ModelInstances.ContainsKey(Id)) return;
     poi.ModelInstances[Id].Stop();
     poi.ModelInstances.Remove(Id);
 }
Esempio n. 3
0
 public AppraisalEffect(PoI poi, string title, string label, double effectValue, double min = 0, double max = 10) {
     selectedPoI      = poi;
     Title            = title;
     Label            = label;
     Min              = min;
     Max              = max;
     this.effectValue = effectValue;
     if (max < min) Max = min + 10;
     TickFrequency = (int) Math.Round((Max - Min)/10);
 }
Esempio n. 4
0
 public IModelPoiInstance GetPoiInstance(PoI poi)
 {
     var vop = new GridPoi {
         Poi = poi,
         Model = this,
         GridLayer = GridLayer
     };
     poi.ModelInstances[Id] = vop;
     return vop;
 }
Esempio n. 5
0
        public GridViewModel(string displayName, PoI poi, GraphicsLayer gridLayer)
        {
            DisplayName = displayName;
            Poi = poi;
            GridLayer = gridLayer;
            ReadLabels();
            RedrawGrid();

            var posChanged = Observable.FromEventPattern<PositionEventArgs>(ev => Poi.PositionChanged += ev, ev => Poi.PositionChanged -= ev);
            posChanged.Throttle(TimeSpan.FromMilliseconds(500)).Subscribe(k => RedrawGrid());
        }
Esempio n. 6
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;
                }
            });
        }
Esempio n. 7
0
 public IModelPoiInstance GetPoiInstance(PoI poi)
 {
     var ncp = new NetworkCreatorPoi { Poi = poi, Model = this };
     var key = Id + ".Networks";
     if (poi.Labels.ContainsKey(key) && !string.IsNullOrEmpty(poi.Labels[key]))
     {
         ncp.Networks = new BindableCollection<Network>();
         var networks = poi.Labels[key].Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (var network in networks)
         {
             ncp.Networks.Add(new Network { Title = network });
         }
     }
     poi.ModelInstances[Id] = ncp;
     return ncp;
 }
Esempio n. 8
0
        public void AddPoi(PoI p)
        {
            UIElement uiElement;


            ImageSource imageSource = p.NEffectiveStyle.Picture;
    
            double opacity = p.NEffectiveStyle.FillOpacity.HasValue ? p.NEffectiveStyle.FillOpacity.Value : 1.0;

            uiElement = new PoiImageOverlay
            {
                Poi = p,
                Source = imageSource,
                Stretch = Stretch.Fill,
                Opacity = opacity,
                Name = "testImage",
                Tag = "testImage"
            };
            

           

            // Set the rotation
            if (p.Orientation != 0.0)
            {
                uiElement.RenderTransformOrigin = new Point(0.5, 0.5);
                uiElement.RenderTransform = new RotateTransform { Angle = p.Orientation }; // KML rotations are specified in a counterclockwise direction
            }

            // Set the envelope
            var elementLayerEnvelopeProperty = ElementLayer.EnvelopeProperty;
            if (p.Points.Count == 2)
            {
                var envelope = new Envelope(new MapPoint(p.Points[0].X, p.Points[0].Y),
                    new MapPoint(p.Points[1].X, p.Points[1].Y));
                var projection = new WebMercator();
                envelope = (Envelope) projection.FromGeographic(envelope) as Envelope;

                uiElement.SetValue(elementLayerEnvelopeProperty, envelope);
                p.Data["Image"] = uiElement;
                p.Data["layer"] = this;
                // Add element to element layer
                this.Children.Add(uiElement);
            }
        }
Esempio n. 9
0
 public IModelPoiInstance GetPoiInstance(PoI poi)
 {
     var ppp = new PathPlannerPoi { Poi = poi, Model = this };
     var key = Id + ".VisitedLocations"; // NOTE the key with the same name in PathPlannerViewModel
     if (poi.Labels.ContainsKey(key) && !string.IsNullOrEmpty(poi.Labels[key]))
     {
         ppp.VisitedLocations = new VisitedLocations();
         var visitedLocations = poi.Labels[key].Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (var split in visitedLocations)
         {
             var visitedLocation = new VisitedLocation();
             visitedLocation.FromString(split);
             ppp.VisitedLocations.Add(visitedLocation);
         }
     }
     poi.ModelInstances[Id] = ppp;
     return ppp;
 }
Esempio n. 10
0
 public void RemovePoi(PoI p)
 {
     Execute.OnUIThread(() =>
     {
         if (!p.Data.ContainsKey("layer")) return;
         var gl = p.Data["layer"] as ElementLayer;
         if (gl == null) return;
         if (p.Data.ContainsKey("layer")) p.Data.Remove("layer");
         if (p.Data.ContainsKey("Image"))
         {
             if (gl.Children.Contains((UIElement) p.Data["Image"]))
             {
                 gl.Children.Remove((UIElement) p.Data["Image"]);
             }
         }
         
         
     }); 
 }
Esempio n. 11
0
 /// <summary>
 /// Called for every PoI, so here is the place to process the parameters and pass them to the PoI.
 /// </summary>
 /// <param name="poi"></param>
 /// <returns></returns>
 public IModelPoiInstance GetPoiInstance(PoI poi)
 {
     var pep = new RouterPoi { Poi = poi, Model = this, };
     poi.ModelInstances[Id] = pep;
     return pep;
 }
Esempio n. 12
0
 /// <summary>
 /// Create an object to draw a freehand line
 /// </summary>
 /// <param name="poi"></param>
 public DrawFreehand(PoI poi)
     : base(poi)
 {
 }
Esempio n. 13
0
 private static ContentList ClonePoiTypes(PoiService source, string shapeIdLabel = null)
 {
     var clonedPoiTypes = new ContentList();
     // Add all other PoI types.
     foreach (var baseContent in source.PoITypes)
     {
         var clone = new PoI(); // Important that this is a PoI! Otherwise we have a casting problem elsewhere.
         clone.FromXml(baseContent.ToXml()); // Deep clone.
         // Add a MetaInfo for the counter.
         if (clone.MetaInfo == null)
         {
             clone.MetaInfo = new List<MetaInfo>();
         }
         clone.MetaInfo.Add(new MetaInfo()
         {
             Label       = AggregationCountLabel,
             Description = "The number of features belonging to this aggregation",
             IsEditable  = false,
             Type        = MetaTypes.number
         });
         if (shapeIdLabel != null) clone.MetaInfo.Add(new MetaInfo()
         {
             Label      = "Shape_Name",
             IsEditable = false,
             Type       = MetaTypes.text
         });
         clonedPoiTypes.Add(clone);
     }
     return clonedPoiTypes;
 }
Esempio n. 14
0
        public static PoiService Aggregate(PoiService source, string aggregationLabel, Dictionary<string, AggregationPolicy> aggregationPolicies)
        {
            // Make sure the aggregation label itself is not erased or compromised in any way.
            AggregationPolicy aggregationLabelPolicy;
            if (aggregationPolicies.TryGetValue(aggregationLabel, out aggregationLabelPolicy))
            {
                if (aggregationLabelPolicy.DataIsNumeric)
                {
                    aggregationLabelPolicy.NumericAggregationPolicy = AggregationPolicy.NumericAggregation.KeepFirst;
                }
                else
                {
                    aggregationLabelPolicy.NonNumericAggregationPolicy = AggregationPolicy.NonNumericAggregation.KeepFirst;
                }
            }

            // Master dictionary: aggregation label -> all other labels -> values for those labels
            Dictionary<string, Dictionary<string, List<string>>> aggregations =
                new Dictionary<string, Dictionary<string, List<string>>>();

            // Counter dictionary: aggregation label value -> number of PoIs having that value
            Dictionary<string, int> count = new Dictionary<string, int>();

            // Gather data.
            foreach (BaseContent poi in source.PoIs)
            {
                string aggregationLabelValue;
                if (!poi.Labels.TryGetValue(aggregationLabel, out aggregationLabelValue))
                {
                    continue;
                }
                if (! aggregations.ContainsKey(aggregationLabelValue))
                {
                    aggregations[aggregationLabelValue] = new Dictionary<string, List<string>>();
                }
                foreach (KeyValuePair<string, string> kv in poi.Labels)
                {
                    string poiLabelName = kv.Key;
                    string poiLabelValue = kv.Value;
                    if (!aggregations[aggregationLabelValue].ContainsKey(poiLabelName))
                    {
                        aggregations[aggregationLabelValue][poiLabelName] = new List<string>();
                    }
                    aggregations[aggregationLabelValue][poiLabelName].Add(poiLabelValue);
                }

                if (!count.ContainsKey(aggregationLabelValue))
                {
                    count[aggregationLabelValue] = 1;
                }
                else
                {
                    count[aggregationLabelValue]++;
                }
            }
            
            // Aggregate.
            var aggregate = new PoiService { PoITypes = ClonePoiTypes(source) };
            foreach (var kv in aggregations)
            {
                var labelsWithValues = kv.Value;
                var newPoI = new PoI {PoiType = aggregate.PoITypes.FirstOrDefault()};
                foreach (var kw in labelsWithValues)
                {
                    ApplyAggregation(aggregationPolicies, kw, newPoI);
                }
                aggregate.PoIs.Add(newPoI);
            }

            // Handle keyword aggregation and remove obsolete columns.
            CompressColumns(aggregationPolicies, aggregate);

            // Add count information.
            foreach (BaseContent poi in aggregate.PoIs)
            {
                string aggregationLabelValue;
                if (poi.Labels.TryGetValue(aggregationLabel, out aggregationLabelValue))
                {
                    int aggregationLabelValueFrequency;
                    if (count.TryGetValue(aggregationLabelValue, out aggregationLabelValueFrequency))
                    {
                        poi.Labels[AggregationCountLabel] = "" + aggregationLabelValueFrequency;
                    }                    
                }
            }

            // Return.
            return aggregate;
        }
Esempio n. 15
0
        public static PoiService Aggregate(PoiService source, PoiService shapes, string shapeIdLabel, Dictionary<string, AggregationPolicy> aggregationPolicies, bool addLabelsFromShapeFile)
        {
            // Build a dictionary of shape -> labels -> values.
            Dictionary<BaseGeometry, Dictionary<string, List<string>>> aggregations = new Dictionary<BaseGeometry, Dictionary<string, List<string>>>();

            // Copy the shape PoIs to the aggregate PoI.
            Dictionary<BaseGeometry, PoI> aggregatePois = new Dictionary<BaseGeometry, PoI>(); // Allows to look up PoIs by geometry.
            PoiService aggregate = new PoiService { PoITypes = ClonePoiTypes(source, shapeIdLabel) }; // TODO BUG Note that we omit metadata for the shape layer.
            foreach (BaseContent shapePoi in shapes.PoIs)
            {
                if (shapePoi.Geometry == null)
                {
                    continue;
                }
                var newPoI = new PoI {Geometry = shapePoi.Geometry};
                aggregate.PoIs.Add(newPoI);
                aggregatePois[newPoI.Geometry] = newPoI;
                aggregations[newPoI.Geometry] = new Dictionary<string, List<string>>();
                if (addLabelsFromShapeFile) {
                    foreach (KeyValuePair<string, string> kv in shapePoi.Labels) {
                        newPoI.Labels[kv.Key] = kv.Value;
                        aggregations[newPoI.Geometry][kv.Key] = new List<string>() {kv.Value};
                    }
                }
                else {
                    // Remember at least the ID of the shape layer, if possible.
                    string shapeIdLabelValue;
                    if (!shapePoi.Labels.TryGetValue(shapeIdLabel, out shapeIdLabelValue)) continue;
                    newPoI.Labels[shapeIdLabel] = shapeIdLabelValue;
                    aggregations[newPoI.Geometry][shapeIdLabel] = new List<string> { shapeIdLabelValue };
                }
            }

            // Counter dictionary: aggregation shape -> number of PoIs within that shape
            Dictionary<BaseGeometry, int> count = new Dictionary<BaseGeometry, int>();

            // Fill the dictionary.
            foreach (BaseContent poi in source.PoIs)
            {
                Point pos = poi.Geometry as Point; // NOTE: The following is wrong, because 'Position' is not in sync! -- new Point(poi.Position.Longitude, poi.Position.Latitude);
                if (pos == null)
                {
                    continue;
                }
                foreach (var kv in aggregations)
                {
                    BaseGeometry geometry = kv.Key;
                    Dictionary<string, List<string>> labels = kv.Value;

                    if (! geometry.Contains(pos)) continue;
                    
                    foreach (KeyValuePair<string, string> kw in poi.Labels)
                    {
                        string poiLabel = kw.Key;
                        string poiLabelValue = kw.Value;

                        List<string> labelValues;
                        if (!labels.TryGetValue(poiLabel, out labelValues))
                        {
                            labelValues = new List<string>();
                            labels[poiLabel] = labelValues;
                        }
                        labels[poiLabel].Add(poiLabelValue);
                    }

                    if (!count.ContainsKey(geometry))
                    {
                        count[geometry] = 1;
                    }
                    else
                    {
                        count[geometry]++;
                    }
                }                
            }

            // Aggregate and add count information.
            foreach (KeyValuePair<BaseGeometry, Dictionary<string, List<string>>> kv in aggregations)
            {
                PoI poi;
                if (aggregatePois.TryGetValue(kv.Key, out poi))
                {
                    foreach (KeyValuePair<string, List<string>> kw in kv.Value)
                    {
                        ApplyAggregation(aggregationPolicies, kw, poi);
                    }
                    int numPoisInRegion;
                    if (count.TryGetValue(kv.Key, out numPoisInRegion))
                    {
                        poi.Labels[AggregationCountLabel] = "" + numPoisInRegion;
                    }
                }
            }

            // Handle keyword aggregation and remove obsolete columns.
            CompressColumns(aggregationPolicies, aggregate);

            // Return.
            return aggregate;
        }
Esempio n. 16
0
 private static void ApplyAggregation(Dictionary<string, AggregationPolicy> aggregationPolicies, KeyValuePair<string, List<string>> labelWithValues, PoI destinationPoI)
 {
     AggregationPolicy policy;
     if (!aggregationPolicies.TryGetValue(labelWithValues.Key, out policy)) return;
     if (!policy.IsKeywordAggregation)
     {
         string aggregation = policy.Aggregrate(labelWithValues.Value);
         if (aggregation != null)
         {
             destinationPoI.Labels[labelWithValues.Key] = aggregation;
         }
         else
         {
             destinationPoI.Labels.Remove(labelWithValues.Key);
         }
     }
     else // Throw it all together.
     {
         List<string> values = labelWithValues.Value;
         StringBuilder concat = new StringBuilder();
         foreach (var value in values)
         {
             concat.Append(value).Append(" ");
         }
         destinationPoI.Labels[labelWithValues.Key] = concat.ToString();
     }
 }
Esempio n. 17
0
 public dsStaticSubLayer FindPoiLayer(PoI p)
 {
     var n = string.IsNullOrEmpty(p.Layer) ? ID : p.Layer;
     return FindPoiLayer(n);
 }
Esempio n. 18
0
        private void ServiceOnTapped(object sender, TappedEventArgs e)
        {
            var poi = e.Content as PoI;
            if (poi == null) return;
            var linkPoiTypeParameter = Model.Model.Parameters.FirstOrDefault(p => string.Equals(p.Name, "LinkPoiType", StringComparison.InvariantCultureIgnoreCase));
            if (linkPoiTypeParameter == null) return;
            var linkPoiType = linkPoiTypeParameter.Value;
            var poiType = Model.Service.PoITypes.OfType<PoI>().FirstOrDefault(pt => string.Equals(pt.PoiId, linkPoiType, StringComparison.InvariantCultureIgnoreCase));
            if (poiType == null) return;

            var position = poi.Position ?? CalculateCenter(poi);
            var link = new PoI
            {
                Id = Guid.NewGuid(),
                PoiTypeId = linkPoiType,
                Layer = PoI.Layer + "_link",
                Labels = new Dictionary<string, string> {
                    { "IsActive", "true" },
                    { "QoS", "100"},
                    {Model.Id + ".CreatorId", PoI.Id.ToString() },
                    {Model.Id + ".NetworkName", selectedNetwork.Title },
                    {Model.Id + ".SourceId", lastPoi.Id.ToString() },
                    {Model.Id + ".SinkId", poi.Id.ToString() },
                },
                Points = new ObservableCollection<Point> {
                    new Point {X = lastPoi.Position.Longitude, Y = lastPoi.Position.Latitude},
                    new Point {X = position.Longitude, Y = position.Latitude}
                }
            };
            var strokeColor = (Color)ColorConverter.ConvertFromString(selectedColor);
            link.Style = new PoIStyle { StrokeColor = strokeColor };
            Model.Service.PoIs.Add(link);
            lastPoi = poi;
        }
Esempio n. 19
0
 internal void Start(PoI p)
 {
     if (p == null || Service == null) return;
     var folder = Service.Folder + "\\tracks\\";
     if (!FileStore.FolderExists(folder)) FileStore.CreateFolder(folder);
     Poi = p;
     PoiId = p.Id;
     IsRunning = true;            
     //StartTime = DateTime.Now;
     p.PositionChanged += p_PositionChanged;
 }
Esempio n. 20
0
        public void Add()
        {
            //AppState.ViewDef.Layers.ChildLayers.Add(pl);
            IsRunning = true;

            this.ImageUrl = "http://googlediscovery.com/wp-content/uploads/panoramio.png";

            service = new SaveService()
            {
                IsLocal = true,
                Name = "lookr",
                Id = Guid.NewGuid(),
                IsFileBased = false,
                StaticService = true,
                IsVisible = false,
                RelativeFolder = "Social Media"

            };

            service.Init(Mode.client, AppState.DataServer);
            // TODO Check met Arnoud of dit niet de folder moet zijn die in de configoffline staat?
            service.Folder = Path.Combine(Directory.GetCurrentDirectory(),@"\PoiLayers\Social Media");
            service.InitPoiService();

            service.Settings.OpenTab = false;
            service.Settings.Icon = "brugwhite.png";
            service.AutoStart = true;

            webcam = new PoI
            {
                PoiId = "Webcam",
                Style = new PoIStyle
                {
                    DrawingMode = DrawingModes.Image,
                    FillColor = Colors.Red,
                    CallOutFillColor = Colors.White,
                    CallOutForeground = Colors.Black,
                    IconWidth = 30,
                    IconHeight = 30,
                    TapMode = TapMode.OpenMedia,
                    TitleMode = TitleModes.None
                }
            };

            webcam.AddMetaInfo("name", "name");
            //result.AddMetaInfo("height", "height", MetaTypes.number);
            //result.AddMetaInfo("width", "width", MetaTypes.number);
            //result.AddMetaInfo("description", "description");
            //result.AddMetaInfo("image", "image", MetaTypes.image);
            service.PoITypes.Add(webcam);

            AppState.DataServer.Services.Add(service);

            AppState.ViewDef.MapControl.ExtentChanged += MapControl_ExtentChanged;
            DownloadCams();
          
        }
Esempio n. 21
0
        public void CreateService()
        {
            AppState.ViewDef.FolderIcons[@"AcceleratedLayers\Search Result"] = "pack://*****:*****@"\PoiLayers\Search Result";
            SearchService.InitPoiService();
            
            SearchService.Settings.OpenTab = false;
            SearchService.Settings.Icon    = "brugwhite.png";
            SearchService.AutoStart        = true;

            result = new PoI { ContentId = "Brug", Style = new PoIStyle
            {
                DrawingMode       = DrawingModes.Point, 
                FillColor         = Colors.Red, 
                CallOutFillColor  = Colors.White,
                CallOutForeground = Colors.Black,
                IconWidth         = 30, 
                IconHeight        = 30,
                TitleMode         = TitleModes.Bottom
            } };
            
            result.AddMetaInfo("name", "name");
            //result.AddMetaInfo("height", "height", MetaTypes.number);
            //result.AddMetaInfo("width", "width", MetaTypes.number);
            //result.AddMetaInfo("description", "description");
            //result.AddMetaInfo("image", "image", MetaTypes.image);
            SearchService.PoITypes.Add(result);

            DataServer.Services.Add(SearchService);
        }
Esempio n. 22
0
 public PoI CreatePoiTypeResult(string id, Color color, string icon = "")
 {
     var googleResult = new PoI
     {
         Service = SearchService,
         ContentId = id,
         Style = new PoIStyle
         {
             DrawingMode        = DrawingModes.Point,
             FillColor          = color,
             TitleMode          = TitleModes.Bottom,
             CallOutFillColor   = Colors.White,
             CallOutOrientation = CallOutOrientation.Right,
             CallOutForeground  = Colors.Black,
             CallOutMaxWidth    = 400,
             Icon               = icon,
             InnerTextColor     = Colors.White
         }
         
     };
     return googleResult;
 }
Esempio n. 23
0
 /// <summary>
 /// Called for every PoI, so here is the place to process the parameters and pass them to the PoI.
 /// </summary>
 /// <param name="poi"></param>
 /// <returns></returns>
 public IModelPoiInstance GetPoiInstance(PoI poi)
 {
     var pep = new SqlQueryPoi { Poi = poi, Model = this, QueryLayer = QueryLayer};
     poi.ModelInstances[Id] = pep;
     return pep;
 }
Esempio n. 24
0
 public void RemovePoiInstance(PoI poi)
 {
     if (!poi.ModelInstances.ContainsKey(Id)) return;
     poi.ModelInstances[Id].Stop();
     poi.ModelInstances.Remove(Id);
 }
Esempio n. 25
0
        private void WcDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            // AppStateSettings.Instance.FinishDownload((Guid) e.UserState);
            if (e.Error != null) return;
            var n = new List<string>();
            var r = new JsonTextReader(new StringReader(e.Result));
            JObject j = JObject.Parse(e.Result);
            var av = new List<string>();
            var cams = j["content"];
            foreach (var c in cams)
            {
                var Id = c["webcamid"].Value<string>();
                var lng = double.Parse(c["lng"].Value<string>(), CultureInfo.InvariantCulture);
                var lat = double.Parse(c["lat"].Value<string>(), CultureInfo.InvariantCulture);
                var ImageUrl = c["thumbnail"].Value<string>();
                var current = c["preview"]["current"].Value<string>();
                if (service.PoIs.All(k => k.ContentId != Id))
                {
                    var bc = new PoI
                    {
                        PoiTypeId = webcam.PoiId,
                        Service = service,
                        PoiType = webcam,
                        ContentId = Id,
                        Style = new PoIStyle {Icon = ImageUrl},
                        Position = new Position(lng, lat),

                    };

                    var m = new Media();
                    m.PublicUrl = current;
                    m.LocalPath = current;
                    bc.AllMedia.Add(m);
                    service.PoIs.Add(bc);
                    av.Add(Id);
                }
            }


            //string sReferences = e.Result;
            //int iStart = sReferences.IndexOf("[{");
            //int iLength = sReferences.IndexOf("}]") - iStart;
            //if (iStart <= 1) return;
            //string sPhotos = sReferences.Substring(iStart + 1, iLength - 1);
            //////string[] sPhotoArray = sPhotos.Split(new char[] { (char)10 });
            //var sSeparator = new string[1];
            //sSeparator[0] = "},";

            //string[] sPhotoArray = sPhotos.Split(sSeparator, StringSplitOptions.RemoveEmptyEntries);

            ////PrepLayer();

            //

            //foreach (string sPhoto in sPhotoArray)
            //{
            //    try
            //    {

            //        var Id = GetValueFromTag(sPhoto, "photo_id");
            //        var Name = GetValueFromTag(sPhoto, "photo_title");
            //        var ImageUrl = GetValueFromTag(sPhoto, "photo_file_url");
            //        var Height = Convert.ToInt16(GetValueFromTag(sPhoto, "height"));
            //        var Width = Convert.ToInt16(GetValueFromTag(sPhoto, "width"));
                    
                    

            //        var bc = new PoI
            //        {
            //            PoiTypeId = webcam.PoiId,
            //            Service = service,
            //            PoiType = webcam,
            //            ContentId = Id,
            //            Style = new PoIStyle { Icon = ImageUrl },
            //            Position = new Position(Convert.ToDouble(GetValueFromTag(sPhoto, "longitude"),
            //                CultureInfo.InvariantCulture),
            //                Convert.ToDouble(GetValueFromTag(sPhoto, "latitude"),
            //                    CultureInfo.InvariantCulture)),

            //        };
            //        var m = new Media();
            //        m.PublicUrl = ImageUrl;
            //        m.LocalPath = ImageUrl;
            //        bc.AllMedia.Add(m);
            //        service.PoIs.Add(bc);
            //        av.Add(Id);
                    

            //        //CurrentFeatures.Add(pf);
            //        //}
            //        //else
            //        //{
            //        //    f.First().Attributes["visible"] = true;
            //        //    //((PhotoFeature)f.First()).Enabled = true;
            //        //}
            //    }
            //    catch
            //    {

            //    }

                //), "photo",
                //GetValueFromTag(sPhoto, "photo_title"), "", Double.Parse(GetValueFromTag(sPhoto, "latitude"), ciEnglish), Double.Parse(GetValueFromTag(sPhoto, "longitude"), ciEnglish),
                //16, Int32.Parse(GetValueFromTag(sPhoto, "owner_id")), GetValueFromTag(sPhoto, "owner_name"), DateTime.MinValue,
                //DateTime.MinValue, "http://www.panoramio.com");
            //}

            var tbr = service.PoIs.Where(k => !av.Contains(k.ContentId)).ToList();
            foreach (var c in tbr) if (service.PoIs.Contains(c)) service.PoIs.Remove(c);

            //CleanLayer();

            //CurrentFeatures.RemoveAll(k => !((PhotoFeature) k).Enabled);
        }
Esempio n. 26
0
 private void ConvertGeometryToPolygon(PoI p, PoiGraphic g)
 {
     var polygon = new Polygon();
     if (p.Geometry is csCommon.Types.Geometries.Polygon)
     {
         var geom = p.Geometry as csCommon.Types.Geometries.Polygon;
         foreach (var ls in geom.LineStrings)
         {
             var pc = new PointCollection();
             foreach (var ps in ls.Line)
             {
                 pc.Add(mercator.FromGeographic(new MapPoint(ps.X, ps.Y)) as MapPoint);
             }
             if (pc.First().X != pc.Last().X || pc.First().Y != pc.Last().Y)
                 pc.Add(pc.First());
             polygon.Rings.Add(pc);
         }
         g.SetGeometry(polygon);
     }
     else return;
 }
Esempio n. 27
0
        public static void Merge(PoiService mainDataService, string mainKey, PoiService secondaryDataService,
            string secKey,
            bool includeSecondaryPois,
            bool excludeNonExistentSecondaryPois,
            bool includeSecondaryColumns,
            bool overwriteDuplicateLabels, bool stopOnFirstHit, bool includeMetaData, FileLocation destination = null,
            TextBox txtMergeDebugOutput = null) {
            if (txtMergeDebugOutput != null)
                txtMergeDebugOutput.Text = "Merging files on [" + mainKey + " = " + secKey + "]";

            // Determine whether to use well-known text.
            var mainPoiType = mainDataService.PoITypes.FirstOrDefault();
            if (mainPoiType == null) {
                mainPoiType                = new PoI {
                    Name                   = "Default",
                    ContentId              = "Default",
                    Service                = mainDataService,
                    Style                  = new PoIStyle {
                        Name               = "default",
                        FillColor          = Colors.Transparent,
                        StrokeColor        = Color.FromArgb(255, 128, 128, 128),
                        CallOutOrientation = CallOutOrientation.Right,
                        FillOpacity        = 0.3,
                        TitleMode          = TitleModes.Bottom,
                        NameLabel          = "Name",
                        DrawingMode        = DrawingModes.Image,
                        StrokeWidth        = 2,
                        IconWidth          = 24,
                        IconHeight         = 24,
                        Icon               = "images/missing.png",
                        CallOutFillColor   = Colors.White,
                        CallOutForeground  = Colors.Black,
                        TapMode            = TapMode.CallOut
                    },
                    Id                     = Guid.NewGuid(),
                    DrawingMode            = DrawingModes.Image,
                    MetaInfo               = new List<MetaInfo>()
                };
                mainDataService.PoITypes.Add(mainPoiType);
            }

            if (mainPoiType != null && string.IsNullOrEmpty(mainPoiType.ContentId)) mainPoiType.ContentId = "Default";
            BaseContent secondaryPoiType = null;
            if (secondaryDataService.PoITypes != null && secondaryDataService.PoITypes.Any()) {
                secondaryPoiType = secondaryDataService.PoITypes.FirstOrDefault();
            }
            ;
            bool useWKT = mainPoiType != null && mainPoiType.Style != null && mainPoiType.Style.Name == "WKT";
            useWKT = (useWKT || secondaryPoiType != null && secondaryPoiType.Style != null) &&
                     secondaryPoiType.Style.Name == "WKT" && includeSecondaryColumns;
            if (useWKT) {
                if (mainPoiType != null) {
                    mainPoiType.ContentId = "WKT"; // We directly set the main PoI's "PoiId" to WKT.                    
                }
                mainDataService.StaticService = true; // Make sure we save the file as static.
                if (txtMergeDebugOutput != null)
                    txtMergeDebugOutput.AppendText(
                        "\nOne of the files uses well-known text; the output will be a static layer.");
            }

            // Merge the meta info. 
            if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nMerging meta info.");
            if (secondaryPoiType != null && secondaryPoiType.MetaInfo.Count == 0) {
                //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nSecondary file has no meta info; nothing to merge.");
            }
            if (secondaryPoiType != null && includeSecondaryColumns)
                foreach (MetaInfo secMetaInfo in secondaryPoiType.MetaInfo) {
                    string secMetaInfoLabel = secMetaInfo.Label;
                    bool doAdd = true;
                    if (secMetaInfoLabel == secKey) {
                        //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nLabel " + secMetaInfo.Label + " is the one we merge on, so we skip it.");
                        doAdd = false;
                    }
                    if (doAdd) {
                        if (mainPoiType != null) {
                            if (mainPoiType.MetaInfo.Any(mainMetaInfo => mainMetaInfo.Label == secMetaInfoLabel)) {
                                doAdd = false; // label already there.
                            }
                        }
                    }
                    if (!doAdd) continue;
                    if (mainPoiType != null)
                        mainPoiType.MetaInfo.Add(secMetaInfo);
                    //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nInserted meta-info from secondary file into main file: " + secMetaInfo.Label + ".");
                }

            // Merge the Style info. If the right file has WKT, set the drawing mode to MultiPolygon.
            // TODO For now we completely ignore some important aspects of poitypes:
            // 1. Multiple PoITypes.
            // 2. Different PoiId attributes.
            if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nMerging styles.");
            if ((secondaryPoiType != null && secondaryPoiType.Style != null && (mainPoiType.Style == null))) {
                // We need to overwrite, or the main does not have something yet.                
                mainPoiType.Style = secondaryPoiType.Style;
                //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nInserted style from secondary file into main file.");
            }
            else {
                //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nMain file already has a style definition.");
            }
            if (useWKT) {
                mainPoiType.Style.DrawingMode = DrawingModes.MultiPolygon;
//                if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText(
//                    "\nEnsuring main file uses drawing mode 'multi polygon' given the fact that well-known text is used.");
            }

            // Remember which PoIs were found in the main as well as secondary file.
            HashSet<BaseContent> unvisitedMainPois = new HashSet<BaseContent>();
            foreach (var poI in mainDataService.PoIs) {
                unvisitedMainPois.Add(poI);
            }

            // Merge data.
            if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\n\nMerging data.");
            foreach (var secPoi in secondaryDataService.PoIs) {
                if (!secPoi.Labels.ContainsKey(secKey)) {
//                    if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\n" + secPoi.Id + " does not have label " + secKey +
//                                                   " and will be skipped.");
                    continue;
                }
                var mainPoiFound = false;
                //var mainPoi = mainDataService.PoIs.FirstOrDefault(p => p.Labels.ContainsKey(mainKey) 
                //    && string.Equals(p.Labels[mainKey], secPoi.Labels[secKey], StringComparison.InvariantCultureIgnoreCase));
                foreach (var mainPoi in mainDataService.PoIs.Where(mainPoi =>
                    mainPoi.Labels.ContainsKey(mainKey)
                    &&
                    string.Equals(mainPoi.Labels[mainKey], secPoi.Labels[secKey],
                        StringComparison.InvariantCultureIgnoreCase)))
                    if (mainPoi != null) {
                        mainPoiFound = true;
                        if (mainPoi.PoiType == null) {
                            mainPoi.PoiType = mainPoiType;
                            mainPoi.ContentId = mainPoiType.ContentId;
                        }
                        unvisitedMainPois.Remove(mainPoi); // We visited this PoI! :)

                        if (!includeSecondaryColumns)
                            continue; // Do not copy information from the secondary to the first.
                        //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nAdding new data to " + mainPoi.Labels[mainKey] + ".");
                        //GetShortFriendlyName(mainPoi.Name) + "." + mainKey + " = " + GetShortFriendlyName(secPoi.Name) + "." + secKey + "] = " + );

                        // Merge the labels part.
                        if (overwriteDuplicateLabels) {
                            //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nCopying label/values with overwrite: ");
                            foreach (var label in secPoi.Labels) {
                                if (label.Key != secKey) {
                                    //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\n->" + label.Key + "=" + label.Value + ", ");
                                    mainPoi.Labels[label.Key] = label.Value;
                                }
                            }
                        }
                        else {
                            //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nCopying label/values without overwrite: ");
                            foreach (var label in secPoi.Labels.Where(l => l.Key != secKey)) {
                                string value;
                                if (mainPoi.Labels.TryGetValue(label.Key, out value)) {
                                    //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\n->" + label.Key + " skipped (value already set to " + value + "), ");
                                    continue;
                                }
                                //if (label.Key == secKey)
                                //{
                                //    //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\n->" + label.Key + " is the label on which we merge; skipped (value " + mainPoi.Labels[mainKey] + "), ");
                                //    continue;
                                //}
                                //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\n->Setting " + label.Key + " to " + label.Value);
                                mainPoi.Labels[label.Key] = label.Value;
                            }
                        }

                        // Also merge WKT information there may be.
                        if (useWKT) {
                            mainPoi.PoiTypeId = "WKT";
                        }
                        if (!string.IsNullOrWhiteSpace(secPoi.WktText)) {
                            if (overwriteDuplicateLabels || string.IsNullOrWhiteSpace(mainPoi.WktText)) {
                                //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nAlso merged well-known text elements.");
                                mainPoi.WktText = secPoi.WktText;
                            }
                        }

                        // Stop if needed.
                        if (!stopOnFirstHit) continue;
                        if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nStopping on first hit!");
                        break;

                        // And that's it.
                        //if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\n");
                    }

                if (mainPoiFound) continue;
                if (includeSecondaryPois) {
                    var copyPoI = new PoI();
                    copyPoI.FromXml(secPoi.ToXml());
                    if (useWKT) {
                        copyPoI.PoiTypeId = "WKT";
                    }
                    else {
                        copyPoI.PoiType = mainPoiType;
                        copyPoI.PoiTypeId = mainPoiType.PoiId;
                    }
                    copyPoI.Labels[mainKey] = copyPoI.Labels[secKey]; // Rename the merge label.
                    copyPoI.Labels.Remove(secKey);
                    mainDataService.PoIs.Add(copyPoI);
                    if (txtMergeDebugOutput != null)
                        txtMergeDebugOutput.AppendText("\nMain file does not have PoI with label " + mainKey +
                                                       " set to " + secPoi.Labels[secKey] +
                                                       ", including PoI from secondary file.");
                }
                else {
                    if (txtMergeDebugOutput != null)
                        txtMergeDebugOutput.AppendText("\nMain file does not have PoI with label " + mainKey +
                                                       " set to " + secPoi.Labels[secKey] +
                                                       " and will be skipped.");
                }
            }

            // Report on unvisited PoIs in main file.
            // Remove any PoIs in the main file that are not in the secondary file (if the user selected this option).
            if (txtMergeDebugOutput != null) {
                if (unvisitedMainPois.Any()) {
                    if (txtMergeDebugOutput != null)
                        txtMergeDebugOutput.AppendText(
                            "\nSome PoIs in the main file were not matched with a PoI in the secondary file.");
                    if (excludeNonExistentSecondaryPois && txtMergeDebugOutput != null)
                        txtMergeDebugOutput.AppendText(" These PoIs will be removed from the main file.");
                }
                foreach (BaseContent unvisitedMainPoi in unvisitedMainPois) {
                    if (txtMergeDebugOutput != null) {
                        string unvisitedMainPoiValue;
                        bool found = unvisitedMainPoi.Labels.TryGetValue(mainKey, out unvisitedMainPoiValue);
                        if (!found) {
                            unvisitedMainPoiValue = "UNDEFINED";
                        }
                        txtMergeDebugOutput.AppendText("\n" + unvisitedMainPoi + ", " + mainKey + " = " +
                                                       unvisitedMainPoiValue + ".");
                    }
                }
                if (excludeNonExistentSecondaryPois) {
                    // Annoyingly, calling "remove" on a ContentList throws an exception.
                    // Therefore, we construct a new list of PoIs that should be kept, instead of removing the PoIs we should remove.
                    ContentList newMainPoIs = new ContentList();
                    foreach (BaseContent poI in mainDataService.PoIs.Where(poI => !unvisitedMainPois.Contains(poI))) {
                        newMainPoIs.Add(poI);
                    }
                    mainDataService.PoIs = newMainPoIs;
                }
            }

            // We are done.
            if (txtMergeDebugOutput != null) txtMergeDebugOutput.AppendText("\nMerge completed!");

            if (destination == null) {
                mainDataService.SaveXml();
            }
            else {
                PoiServiceExporters.Instance.Export(mainDataService, destination, includeMetaData);
            }
        }
Esempio n. 28
0
        private void UpdateCircularMenu(PoI p, DataBinding db, dsLayer pl, Point pos)
        {
            if (!p.NEffectiveStyle.CanEdit.ValueOrFalse()) return;
            pos = new Point(pos.X + 50, pos.Y - 50);
            if (!p.IsSelected)
            {
                if (menu != null) AppState.RemoveCircularMenu("PoiMenu" + p.Id);
                return;
            }
            var lineWidth = new CircularMenuItem
            {
                Title = "Line\nWidth",
                Position = 5,
                Items = new List<CircularMenuItem> {
                    new CircularMenuItem {
                        Title = "1",
                        Position = 1
                    },
                    new CircularMenuItem {
                        Title = "2",
                        Position = 2
                    },
                    new CircularMenuItem {
                        Title = "3",
                        Position = 3
                    },
                    new CircularMenuItem {
                        Title = "5",
                        Position = 4
                    },
                    new CircularMenuItem {
                        Title = "10",
                        Position = 5
                    }
                }
            };

            lineWidth.ItemSelected += (e, f) =>
            {
                p.StrokeWidth = Convert.ToDouble(f.SelectedItem.Title);
                lineWidth.Menu.Back();
                //pl.RedrawPoi(p, db.Attributes["Graphic"] as Graphic);
            };

            //Color c = Colors.Blue;
            var fill = ColorCircularMenuItem.CreateColorMenu("Fill", 6);
            fill.ColorChanged += (e, f) =>
            {
                //SolidColorBrush scb = fill.Fill as SolidColorBrush;
                p.FillColor = fill.Color;
                //pl.RedrawPoi(p, db.Attributes["Graphic"] as Graphic);
            };

            var line = ColorCircularMenuItem.CreateColorMenu("Line\nColor", 7);
            line.ColorChanged += (e, f) =>
            {
                p.StrokeColor = line.Color;
                //pl.RedrawPoi(p, db.Attributes["Graphic"] as Graphic);
            };

            var delete = new CircularMenuItem
            {
                Position = 2,
                Title = "Delete",
                Element = "M33.977998,27.684L33.977998,58.102997 41.373998,58.102997 41.373998,27.684z M14.841999,27.684L14.841999,58.102997 22.237998,58.102997 22.237998,27.684z M4.0319996,22.433001L52.183,22.433001 52.183,63.999001 4.0319996,63.999001z M15.974,0L40.195001,0 40.195001,7.7260003 56.167001,7.7260003 56.167001,16.000999 0,16.000999 0,7.7260003 15.974,7.7260003z"
            };
            delete.Selected += (e, f) => AppState.RemoveCircularMenu("PoiMenu" + p.Id);

            var stylemenu = new CircularMenuItem
            {
                Id = "style",
                Title = "Style",
                Position = 1,
                Icon = "pack://application:,,,/csCommon;component/Resources/Icons/paint.png",
                Items = new List<CircularMenuItem> {
                    lineWidth,
                    fill,
                    line
                }
            };

            menu = new CircularMenuItem
            {
                Id = "PoiMenu" + p.Id,
                Title = "test",
                StartPosition = pos,
                Icon = "pack://application:,,,/csCommon;component/Resources/Icons/paint.png",
                Items = new List<CircularMenuItem>
                {
                    stylemenu,
                    delete
                },
                AutoCloseTimeout = 10
            };
            AppState.AddCircularMenu(menu);

            //AppState.SetCircularMenu(menu);
        }
Esempio n. 29
0
 public void Open(PoI p, PoiService service) // REVIEW TODO fix: async removed
 {
     var f = p.Id + ".t";
     string folder = service.Folder + "\\tracks\\";
     if (!service.store.HasFile(folder, f)) return;
     var his = service.store.GetString(folder + "\\" + f); // REVIEW TODO fix: await removed
     foreach (var ln in his.Split('\n'))
     {      
         try
         {
             if (!ln.StartsWith("#")) {
                 var pos = new Position(ln);
                 History.Add(pos);
             }
         }
         catch (Exception e)
         {
             // FIXME TODO Deal with exception!
             //Logger.Log("DataService","Error opening track file",e.Message,Logger.Level.Error);
         }
     }
 }
Esempio n. 30
0
        public void AddNetwork()
        {
            if (Networks == null) Networks = new BindableCollection<Network>();
            var title = string.IsNullOrEmpty(networkName) ? Model.Id : networkName;
            var network = Networks.FirstOrDefault(n => string.Equals(n.Title, title, StringComparison.InvariantCultureIgnoreCase))
                          ?? new Network {Title = title};
            // Only add the network in case its unique
            if (!Networks.Contains(network)) Networks.Add(network);
            UpdateNetworkNamesLabel();
            SelectedNetwork = network;
            lastPoi = PoI;

            if (Model == null || Model.DataServer == null) return;
            foreach (var service in Model.DataServer.Services.OfType<PoiService>().Where(s => s.IsSubscribed))
            {
                service.Tapped += ServiceOnTapped;
            }
            var notificationEventArgs = new NotificationEventArgs
            {
                Id = Guid.NewGuid(),
                Background = Brushes.White,
                Foreground = Brushes.Black,
                Header = "Add a network",
                Text = "Press OK when done.",
                Duration = TimeSpan.FromDays(1),
                Options = new List<string> { "OK", "Cancel" }
            };

            notificationEventArgs.OptionClicked += (sender, args) =>
            {
                foreach (var service in Model.DataServer.Services.OfType<PoiService>())
                {
                    service.Tapped -= ServiceOnTapped;
                }
                switch (args.Option)
                {
                    case "OK":
                        break;
                    case "Cancel":
                        RemoveNetwork(selectedNetwork);
                        break;
                }
            };
            AppState.TriggerNotification(notificationEventArgs);
        }