コード例 #1
0
        public override GeoJSONObject ReadJson(JsonReader reader, Type objectType, GeoJSONObject existingValue, bool hasExistingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null) //GeoJSONObject can be abstract
            {
                return(null);
            }

            JObject token = JObject.Load(reader);

            if (!token.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out JToken TypeToken))
            {
                throw new JsonReaderException("Invalid geojson object, does not have 'type' field.");
            }

            // Match GeoJSONType to actual type
            GeoJSONType tokenType  = TypeToken.ToObject <GeoJSONType>(serializer);
            Type        actualType = tokenType switch
            {
                GeoJSONType.Point => typeof(Point),
                GeoJSONType.LineString => typeof(LineString),
                GeoJSONType.Polygon => typeof(Polygon),
                GeoJSONType.Feature => typeof(Feature),
                GeoJSONType.FeatureCollection => typeof(FeatureCollection),
                _ => null, //TODO: proper check here
            };

            if (existingValue == null || existingValue.GetType() != actualType)
            {
                return((GeoJSONObject)token.ToObject(actualType, serializer));
            }
            else
            {
                using (JsonReader derivedTypeReader = token.CreateReader())
                {
                    serializer.Populate(derivedTypeReader, existingValue);
                }

                return(existingValue);
            }
        }
コード例 #2
0
        public async Task NavigateToNewEditPage(GeoJSONType type)
        {
            Page currentPage = GetCurrentPage();

            await currentPage.Navigation.PushModalAsync(new EditFeatureView(new EditFeatureViewModel(type)));
        }
コード例 #3
0
 protected GeoJSONObject(GeoJSONType type) => Type = type;
コード例 #4
0
 /// <summary>
 /// 创建GeometryGeoJson对象,并对Type进行赋值
 /// </summary>
 /// <param name="type"></param>
 public GeometryGeoJson(GeoJSONType type)
 {
     this.Type = type;
 }