예제 #1
0
        public static WebApiService CreateWebApiService(csWebApi api, string name, Layer layer, Guid id, string folder = "",
            string relativeFolder = "")
        {

            var res = new WebApiService
            {
                IsLocal = true,
                Name = layer.Title,
                Id = id,
                IsFileBased = false,
                StaticService = true,
                AutoStart = false,
                HasSensorData = false,
                Mode = Mode.client,
                RelativeFolder = relativeFolder,
                api = api
            };
            res.csLayer = layer;
            res.Init(Mode.client, AppState.DataServer);
            res.Folder = folder;
            res.InitPoiService();

            res.Settings.OpenTab = false;
            res.Settings.Icon = "layer.png";
            AppState.DataServer.Services.Add(res);
            return res;
        }
예제 #2
0
파일: Api.cs 프로젝트: TNOCS/csTouch
 public void TestApis()
 {
     layers.DeleteLayer("testje");
     var l = new Layer
     {
         Id = "testje",
         Title = "test layer",
         Storage = "file",
         Type = "dynamicgeojson",
         Features = new List<Feature>()
     };
     var f = new Feature() {Type = "Feature", Geometry = new Geometry() {Type = "Point", Coordinates = new List<double?>() {5.3, 54.2}}};
     
     try
     {
         layers.AddLayer(l);
         features.AddFeature("testje", f);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
예제 #3
0
        private global::DataServer.PoI AddFeature(Feature f, Guid id, Layer layer)
        {
            var p = new global::DataServer.PoI { Service = this, Id = id, PoiTypeId = f.Properties.ContainsKey("featureTypeId") ?(string)f.Properties["featureTypeId"]:null };
            UpdateFeature(f, p, layer);


            PoIs.Add(p);
            p.Deleted += (o, s) => { if (IsInitialized) api.features.DeleteFeature(f.Id, layer.Id); };

            var posChanged = Observable.FromEventPattern<PositionEventArgs>(ev => p.PositionChanged += ev,
                ev => p.PositionChanged -= ev);
            posChanged.Throttle(TimeSpan.FromSeconds(1)).Subscribe(k =>
            {
                if (f.Geometry.Coordinates is JArray)
                {
                    var coords = f.Geometry.Coordinates as JArray;
                    if (coords != null &&
                        ((double) coords[0] != p.Position.Longitude || (double) coords[1] != p.Position.Latitude))
                    {
                        ((JArray) f.Geometry.Coordinates)[0] = p.Position.Longitude;
                        ((JArray) f.Geometry.Coordinates)[1] = p.Position.Latitude;
                        //var c = ((JArray) f.Geometry.Coordinates).Select(x => (double) x).ToList();
                        //c[0] = p.Position.Longitude;
                        //c[1] = p.Position.Latitude;
                        //f.Geometry.Coordinates = c;
                        var t = api.features.UpdateFeatureAsync(f, layer.Id, f.Id);
                    }
                }
            });
            return p;
        }
예제 #4
0
        private void UpdateFeature(Feature f, global::DataServer.PoI p, Layer layer)
        {
            p.Data["cs"] = f;


            if (f.Geometry.Type == "Point")
            {
                if (f.Geometry.Coordinates is object[])
                {
                    var co = (object[])f.Geometry.Coordinates;
                    f.Geometry.Coordinates = new JArray(co);
                }
                var c = ((JArray)f.Geometry.Coordinates).Select(x => (double)x).ToList();

                if (p.Position == null || p.Position.Longitude != c[0] || p.Position.Latitude != c[1])
                {
                    p.Position = new Position(c[0], c[1]);
                }
            }
            if (layer.DefaultFeatureType != null)
            {
                p.PoiTypeId = layer.DefaultFeatureType;
            }
            var t = this.PoITypes.FirstOrDefault((pt) => p.PoiTypeId == pt.PoiId);

            //var type = AppState.f
            //p.PoiTypeId = 
            f.Properties.ForEach((v) =>
            {
                p.Labels[v.Key] = v.Value.ToString();
                var mt = t?.MetaInfo.FirstOrDefault((mi) => mi.Id == v.Key);
                if (mt != null)
                {
                    if (mt.Type == MetaTypes.datetime)
                    {
                        p.TimelineString = this.Layer.ID;
                        DateTime dd;
                        if (DateTime.TryParse(v.Value.ToString(), out dd))
                        {
                            p.Date = dd;
                            this.Events.Add(p);
                        }

                    }
                }
            });
            p.ForceUpdate(true, false);
        }
예제 #5
0
 public static void SyncPoi(global::DataServer.PoI p, Layer l, Feature f, csWebApi api)
 {
     if (!p.Data.ContainsKey("cs") || p.Data["cs"] == null)
     {
         p.Data["cs"] = f;
     }
     var posChanged = Observable.FromEventPattern<PositionEventArgs>(ev => p.PositionChanged += ev,
         ev => p.PositionChanged -= ev);
     posChanged.Throttle(TimeSpan.FromSeconds(1)).Subscribe(k =>
     {
         var coords = f.Geometry.Coordinates as JArray;
         if (coords != null && ((double)coords[0] != p.Position.Longitude || (double)coords[1] != p.Position.Latitude))
         {
             ((JArray)f.Geometry.Coordinates)[0] = p.Position.Longitude;
             ((JArray)f.Geometry.Coordinates)[1] = p.Position.Latitude;
             //var c = ((JArray) f.Geometry.Coordinates).Select(x => (double) x).ToList();
             //c[0] = p.Position.Longitude;
             //c[1] = p.Position.Latitude;
             //f.Geometry.Coordinates = c;
             var t = api.features.UpdateFeatureAsync(f, l.Id, f.Id);
         }
     });
 }