Skip to content

Draw programmatically MultiPolygon #123

@ProxBiz

Description

@ProxBiz

Hello,
I am tryng to create a MultiPolygon with the code bellow

Image

I get the error:
Error: System.Text.Json.JsonException: The JSON value could not be converted to OpenLayers.Blazor.Coordinates. Path: $.coordinates | LineNumber: 0 | BytePositionInLine: 93.
---> System.InvalidOperationException: Cannot get the value of a token type 'EndArray' as a number.

Message=
Source=
StackTrace:
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.TryGetDouble(Double& value)
at OpenLayers.Blazor.CoordinateConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at OpenLayers.Blazor.CoordinatesConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Coordinates, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Coordinates& value, Boolean& isPopulatedValue) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1[[OpenLayers.Blazor.Coordinates, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Shape& value) at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Shape& value, Boolean& isPopulatedValue)
at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, Shape& value, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex) at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, Shape& value, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].Deserialize(Utf8JsonReader& reader, ReadStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.ParseArguments(JSRuntime jsRuntime, String methodIdentifier, String arguments, Type[] parameterTypes)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)
at w.endInvokeDotNetFromJS (https://localhost:10441/_framework/blazor.web.js:1:3158)
at Object.zr [as endInvokeDotNetFromJS] (https://localhost:10441/_framework/blazor.web.js:1:165451)
at https://localhost:10441/_framework/dotnet.runtime.18clfjpo0j.js:3:33880
at Fc (https://localhost:10441/_framework/dotnet.runtime.18clfjpo0j.js:3:172344)
at wasm://wasm/00b5d276:wasm-function[288]:0x1f35a
at wasm://wasm/00b5d276:wasm-function[219]:0x1c95a
at wasm://wasm/00b5d276:wasm-function[210]:0xeaaf
at wasm://wasm/00b5d276:wasm-function[247]:0x1d5bb
at wasm://wasm/00b5d276:wasm-function[3224]:0xf168d
at wasm://wasm/00b5d276:wasm-function[2547]:0xc719d

Image

I have also tried to draw a MultiPolygon using the demo and selecting ShapeType ShapeType= ShapeType.MultiPolygon; same error with the Json sparse;

Image

Error: System.Text.Json.JsonException: The JSON value could not be converted to OpenLayers.Blazor.Coordinates. Path: $.coordinates | LineNumber: 0 | BytePositionInLine: 96.
---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a number.

Message=
Source=
StackTrace:
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.TryGetDouble(Double& value)
at OpenLayers.Blazor.CoordinateConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at OpenLayers.Blazor.CoordinatesConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Coordinates, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Coordinates& value, Boolean& isPopulatedValue) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1[[OpenLayers.Blazor.Coordinates, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Shape& value) at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, Shape& value, Boolean& isPopulatedValue)
at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, Shape& value, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex) at System.Text.Json.Serialization.JsonConverter1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, Shape& value, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].Deserialize(Utf8JsonReader& reader, ReadStack& state) at System.Text.Json.Serialization.Metadata.JsonTypeInfo1[[OpenLayers.Blazor.Internal.Shape, OpenLayers.Blazor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]].DeserializeAsObject(Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadAsObject(Utf8JsonReader& reader, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.ParseArguments(JSRuntime jsRuntime, String methodIdentifier, String arguments, Type[] parameterTypes)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet(JSRuntime jsRuntime, DotNetInvocationInfo invocationInfo, String argsJson)
at w.endInvokeDotNetFromJS (https://localhost:10441/_framework/blazor.web.js:1:3158)
at Object.zr [as endInvokeDotNetFromJS] (https://localhost:10441/_framework/blazor.web.js:1:165451)
at https://localhost:10441/_framework/dotnet.runtime.18clfjpo0j.js:3:33880
at Fc (https://localhost:10441/_framework/dotnet.runtime.18clfjpo0j.js:3:172344)
at wasm://wasm/00b5d276:wasm-function[288]:0x1f35a
at wasm://wasm/00b5d276:wasm-function[219]:0x1c95a
at wasm://wasm/00b5d276:wasm-function[210]:0xeaaf
at wasm://wasm/00b5d276:wasm-function[247]:0x1d5bb
at wasm://wasm/00b5d276:wasm-function[3224]:0xf168d
at wasm://wasm/00b5d276:wasm-function[2547]:0xc719d

Using the same logic for MultiLineString works with no problems

Image Image

The code:
shape = new Shape(ShapeType.MultiPolygon);
shape.Coordinates.Values.Clear();
shape.Coordinates.Type = CoordinatesType.MultiList;
shape.Coordinates.Values.Add(new List()
{
new Coordinate(25.96191042963997,47.706858355214706),
new Coordinate(25.966889774948257,47.708316026434574),
new Coordinate(25.967701624726786,47.70499976528495),
new Coordinate(25.96191042963997,47.706858355214706)
});
shape.Coordinates.Values.Add(new List() {
new Coordinate(25.96180218300283,47.71141344241963),
new Coordinate(25.974034052999286,47.70656681607872),
new Coordinate(25.96851347450531,47.70219353335824),
new Coordinate(25.95714757760595,47.70645748848236),
new Coordinate(25.96180218300283,47.71141344241963)
});

 shape.Fill = "#563d7c";
 shape.Stroke = "#dd1111";
 shape.StrokeThickness = 2;
 shape.Id = Guid.NewGuid().ToString();
 refLayer.ShapesList.Add(shape);

Can you help me with the problem or poin me in the right direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions