public void UnsubscribeLayer(Subscription s) { var id = s.id; if (this.subscriptions.ContainsKey(id)) { var sub = subscriptions[id]; var r = new SubscriptionCallback(); r.action = "unsubscribe"; this.socket.Emit(id, r.JSON()); this.subscriptions.Remove(id); } }
private Subscription Subscribe(string target, string type) { Subscription s; if (!this.subscriptions.ContainsKey(target)) { s = new Subscription() {id = Guid.NewGuid().ToString(), target = target, type = type}; this.socket.Emit("subscribe", s.JSON()); this.subscriptions[s.id] = s; this.socket.On(s.id, (dynamic d) => { switch ((string) d.action) { case "subscribed": Console.WriteLine("subscription : " + s.id); break; case "layer": //var l = new LayerCallback(); var l = JsonConvert.DeserializeObject<LayerCallback>(d.data.ToString()); s.TriggerLayerCallback(l); break; } }); } else { s = this.subscriptions[target]; } return s; }
public override void Subscribe(Mode serviceMode) { base.Subscribe(serviceMode); Reset(); PoIs.StartBatch(); //var isLoaded = LoadOrCreateDataServiceDescription(saveDsd); IsLoading = true; try { var layer = api.layers.GetLayer(this.csLayer.Id); if (layer.TypeUrl.Length > 0) layer.TypeUrl = layer.TypeUrl.TrimStart('/'); this.IsTimelineEnabled = true; if (!string.IsNullOrEmpty(layer.TypeUrl)) { if (layer.TypeUrl.StartsWith("api/resources/") || layer.TypeUrl.StartsWith("data/resourceTypes/")) { var r = layer.TypeUrl.Replace("api/resources/", ""); r = r.Replace("data/resourceTypes/", ""); r = r.Replace(".json", ""); var template = this.dsb.Templates.FirstOrDefault(t => t.Name == r); if (template == null) { resource = api.resources.GetResource(r); // var ps = new PoiService(); // ps.Name = r; // ps.IsTemplate = true; // ps.InitPoiService(); //dsb.Templates.Add(ps); foreach (var ft in resource.FeatureTypes) { var st = ft.Value.Style; var p = new global::DataServer.PoI { ContentId = ft.Key, PoiId = ft.Key, Service = this, Id = Guid.NewGuid(), Style = new PoIStyle { DrawingMode = DrawingModes.Point, Icon = AppState.Config.Get("csWebApiServer", "http://localhost:3002") + "/" + ft.Value.Style.IconUri, //Picture = new BitmapImage(new Uri("http://localhost:3002/" + ft.Value.Style.IconUri))m CallOutFillColor = Colors.LightBlue, CallOutForeground = Colors.Black, CallOutTimeOut = 10, CallOutOrientation = CallOutOrientation.RightSideMenu, FillOpacity= ft.Value.Style.FillOpacity, StrokeColor= (Color)ColorConverter.ConvertFromString(ft.Value.Style.StrokeColor), StrokeOpacity = ft.Value.Style.Opacity, }, MetaInfo = new List<MetaInfo>() }; if (ft.Value.Style.FillColor != null) { p.Style.FillColor = (Color) ColorConverter.ConvertFromString(ft.Value.Style.FillColor); } if (ft.Value.Style.StrokeColor != null) { p.Style.StrokeColor = (Color)ColorConverter.ConvertFromString(ft.Value.Style.StrokeColor); } if (!string.IsNullOrWhiteSpace(p.Style.Icon)) { p.Style.Picture = new BitmapImage(p.Style.IconUri); } if (!string.IsNullOrEmpty(st.NameLabel)) p.Style.NameLabel = st.NameLabel; if (ft.Value.PropertyTypeKeys != null) { var properties = ft.Value.PropertyTypeKeys.Split(';'); if (properties.Length > 0) { foreach (var prop in properties) { if (resource.PropertyTypeData.ContainsKey(prop)) { var rp = resource.PropertyTypeData[prop]; var mi = new MetaInfo() { Label = rp.Label, Description = rp.Description, VisibleInCallOut = true, IsSearchable = true, Section = rp.Section, IsEditable = rp.CanEdit ?? true, Title = rp.Title }; switch (rp.Type.ToLower()) { case "string": mi.Type = MetaTypes.text; break; case "number": mi.Type = MetaTypes.number; break; case "date": mi.Type = MetaTypes.datetime; break; } p.MetaInfo.Add(mi); } } } } if (PoITypes.All(pt => pt.ContentId != p.ContentId)) this.PoITypes.Add(p); //ps.PoITypes.Add(p); } } } if (layer.TypeUrl.StartsWith(api.client.BasePath)) { //api.resources.GetResource() } } this.PoIs.CollectionChanged += (es, tp) => { if (tp.NewItems != null && IsInitialized) { foreach (global::DataServer.PoI p in tp.NewItems) { var newp = (!availablePoIs.Contains(p.Id.ToString())); if (newp) { if (IsInitialized) { var f = GetFeatureFromPoi(p); WebApiService.SyncPoi(p, layer, f, api); api.features.AddFeature(layer.Id, f); } availablePoIs.Add(p.Id.ToString()); } } // foreach (va) } }; sub = api.GetLayerSubscription(layer.Id); sub.LayerCallback += (e, s) => { Execute.OnUIThread(()=> { switch (s.action) { case LayerUpdateAction.deleteFeature: var dp = PoIs.FirstOrDefault( k => k.Data.ContainsKey("cs") && ((Feature)k.Data["cs"]).Id == s.featureId); if (dp != null) { RemovePoi(dp); } break; case LayerUpdateAction.updateFeature: var f = GetFeature((JObject)s.item); // find feature var p = PoIs.FirstOrDefault(k => k.Data.ContainsKey("cs") && ((Feature)k.Data["cs"]).Id == f.Id); if (p != null) { // update poi UpdateFeature(f, (global::DataServer.PoI)p, layer); //TriggerContentChanged(p); } else { // add poi var g = Guid.NewGuid(); availablePoIs.Add(g.ToString()); var np = AddFeature(f, g, layer); } break; } }); }; foreach (var f in layer.Features) { var p = AddFeature(f, Guid.NewGuid(), layer); availablePoIs.Add(p.Id.ToString()); } IsLoading = false; ContentLoaded = true; Execute.OnUIThread(() => Layer.IsLoading = false); PoIs.FinishBatch(); } catch (Exception e) { AppState.TriggerNotification(e.Message); } }