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); } }
/// <summary> /// Add resource Adds a single resource /// </summary> /// <param name="body">Resource object that needs to be added to the datastorage</param> /// <returns></returns> public async System.Threading.Tasks.Task AddResourceAsync (Resource body) { // verify the required parameter 'body' is set if (body == null) throw new ApiException(400, "Missing required parameter 'body' when calling AddResource"); var path = "/resources"; var pathParams = new Dictionary<String, String>(); var queryParams = new Dictionary<String, String>(); var headerParams = new Dictionary<String, String>(); var formParams = new Dictionary<String, String>(); var fileParams = new Dictionary<String, FileParameter>(); String postBody = null; pathParams.Add("format", "json"); postBody = ApiClient.Serialize(body); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse) await ApiClient.CallApiAsync(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings); if (((int)response.StatusCode) >= 400) throw new ApiException ((int)response.StatusCode, "Error calling AddResource: " + response.Content, response.Content); return; }