示例#1
0
        protected override IEnumerable <TRenderObject> DoRenderFeature(IFeatureDataRecord feature,
                                                                       GeoJsonGeometryStyle style,
                                                                       RenderState state,
                                                                       ILayer layer)
        {
            if (feature == null)
            {
                throw new ArgumentNullException("feature");
            }
            if (style == null)
            {
                throw new ArgumentNullException("style");
            }

            if (feature.Geometry == null)
            {
                throw new InvalidOperationException("Feature must have a geometry to be rendered.");
            }


            StringBuilder sb = new StringBuilder();

            GeoJsonFeatureWriter.WriteFeature(sb, style, feature);
            yield return((TRenderObject)(object)(new GeoJsonRenderObject(sb.ToString())));
            /* oh dear - i feel very dirty now */
        }
示例#2
0
        protected override IEnumerable <GeoJsonRenderObject> DoRenderFeature(IFeatureDataRecord feature,
                                                                             GeoJsonLabelStyle style,
                                                                             RenderState state, ILayer layer)
        {
            FeatureDataRow fdr = (FeatureDataRow)feature;

            string text = fdr.Evaluate(style.LabelExpression);


            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            sb.Append(JsonUtility.FormatJsonAttribute("type", "Label"));
            sb.Append(",");
            sb.Append(JsonUtility.FormatJsonAttribute("id", feature.GetOid()));
            sb.Append(",");
            sb.Append(JsonUtility.FormatJsonAttribute("text", text));
            sb.Append(",");


            IGeometry geom;

            if (style.IncludeGeometryData)
            {
                geom = style.PreProcessGeometries
                           ? style.GeometryPreProcessor(feature.Geometry)
                           : feature.Geometry;
            }
            else
            {
                geom = feature.Geometry.Centroid;
            }

            sb.Append("\"shape\":");
            GeoJsonFeatureWriter.WriteGeometry(sb, geom, style.CoordinateNumberFormatString);
            sb.Append("}");


            yield return(new GeoJsonRenderObject(sb.ToString()));
        }