This is a migrated thread and some comments may be shown as answers.

Shapes from Code Behind

1 Answer 63 Views
Map
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 05 Apr 2019, 03:41 PM

Do you have an example similar to your Server-Side Data Binding example that, instead of creating markers, creates the shapes (similar to the earthquake example) from the Server Side?

I have all my geo locations and condition data stored in SQL and need to dynamically build a layer to show the shapes, sized and colored, based on the condition data queried from SQL.

any direction would be appreciated.

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 10 Apr 2019, 08:31 AM
Hi Mark,

With the current implementation of RadMap, only Markers could be created from the code-behind and Shapes are loaded only from GeoJSON data.

You could create a Web Service for returning the data as a GeoJSON format. An easy for integration approach would be the use of RadClientDataSource control.

Additionally, there is another approach that could be from the code-behind, but it will require to format a string with the shapes data in JSON format, save that string to a HiddenField control and on client-side, use the JSON.parse(string) method for creating a JSON object, which could be set as a data source for a Shape layer.


<script type="text/javascript">
    function OnInitialize(sender, args) {
        var originalOptions = args.get_options();
        var geoJSON = document.getElementById("<%=HiddenGeoJSON.ClientID%>").value;
  
        originalOptions.layers[0].dataSource = { data: JSON.parse(geoJSON) };
  
        args.set_options(originalOptions);
    }
</script>
  
<asp:HiddenField runat="server" ID="HiddenGeoJSON" />
  
<telerik:RadMap runat="server" ID="RadMap1" Zoom="2" Width="500" Height="200">
    <ClientEvents OnInitialize="OnInitialize" />
    <CenterSettings Latitude="30" Longitude="10" />
    <LayerDefaultsSettings>
        <ShapeSettings>
            <StyleSettings>
                <FillSettings Color="green" />
                <StrokeSettings Color="black" Width="2" />
            </StyleSettings>
        </ShapeSettings>
    </LayerDefaultsSettings>
    <LayersCollection>
        <telerik:MapLayer Type="Shape">
        </telerik:MapLayer>
    </LayersCollection>
</telerik:RadMap>

And the code-behind:

protected void Page_Load(object sender, EventArgs e)
{
    HiddenGeoJSON.Value = "[{\"type\": \"Polygon\",\"coordinates\": [[[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]]]}]";
}

You can also review the following forum post - Display LineString (route) from database on the map.

Regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Map
Asked by
Mark
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or