New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Shapes Layer

Earthquakes in April-May 2014

Earthquake magnitude: Earthquake magnitude

This example demonstrates how to data bind, display and customize shapes with RadMap. To do this, you need the data in GeoJSON format and to set the Type property of the MapLayer to Shape.

Two RadClientDataSource controls retrieve the countries and earthquakes data and provide it to the layers through their ClientDataSourceID property.

Each earthquake is represented in the GeoJSON as Feature object, where the details for the earthquake are within the Properties member. The Geometry member holds a Point object with the coordinates.

By default, each Point object in the Shape layer is automatically converted to a Marker, but it is possible to prevent the default behavior and create a circle object with coordinates and radius. To do this, we:

  • Handle the client-side OnClientMarkerCreated event and cancel it.
  • Handle the client-side OnClientShapeCreated event, obtain the dataItem associated with the Shape and calculate the radius and the color for each circle. The magnitude from the data item is used as a parameter for these calculations.

Finally, for displaying detailed information for each earthquake, we are using the client-side OnClientShapeClick event, where the event coordinates are used for calculating where the RadToolTip should be positioned. Again, the dataItem of the clicked shape is used to provide the message.

  • DefaultVB.aspx
  • DefaultVB.aspx.vb
  • scripts.js
  • Styles.css
<%@ Page Language="vb" AutoEventWireup="false"  %>

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <script type="text/javascript" src="Scripts.js"></script>
    <link href="Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadClientDataSource runat="server" ID="RadClientDataSource1">
        <DataSource>
            <WebServiceDataSourceSettings ServiceType="GeoJSON">
                <Select Url="Content/countries.json" DataType="JSON" />
            </WebServiceDataSourceSettings>
        </DataSource>
    </telerik:RadClientDataSource>
    <telerik:RadClientDataSource runat="server" ID="RadClientDataSource2">
        <DataSource>
            <WebServiceDataSourceSettings ServiceType="GeoJSON">
                <Select Url="Content/earthquakes.json" DataType="JSON" />
            </WebServiceDataSourceSettings>
        </DataSource>
    </telerik:RadClientDataSource>

    <div class="demo-container size-auto">
        <h2 class="mapTitle">Earthquakes in April-May 2014</h2>
        <telerik:RadMap RenderMode="Lightweight" runat="server" ID="RadMap1" Zoom="2" MinZoom="2" Skin="Silk">
            <ClientEvents OnShapeCreated="shapeCreated" OnShapeMouseEnter="shapeMouseEnter"
                OnShapeClick="shapeClick" OnPan="clientPan" OnZoomStart="zoomStart"
                OnShapeMouseLeave="shapeMouseLeave" OnClick="clientClick" OnMarkerCreated="markerCreated" />
            <LayersCollection>
                <telerik:MapLayer ClientDataSourceID="RadClientDataSource1" Type="Shape" Opacity="1"></telerik:MapLayer>
                <telerik:MapLayer ClientDataSourceID="RadClientDataSource2" Type="Shape" Opacity="0.9"></telerik:MapLayer>
            </LayersCollection>
            <CenterSettings Longitude="32" Latitude="7" />
        </telerik:RadMap>
        <div class="mapFooter">
            <span class="aligner"></span>
            <span>Earthquake magnitude: </span>
            <img src="Legend.png" alt="Earthquake magnitude" />
        </div>
    </div>
    <telerik:RadToolTip RenderMode="Lightweight" runat="server" ID="Radtooltip1" Width="250px" Height="90px" TargetControlID="RadMap1" RenderInPageRoot="true"
        RelativeTo="Mouse" ShowEvent="FromCode" HideEvent="ManualClose" Position="BottomRight" Skin="Silk" EnableShadow="false">
        <div class="toolTipContentWrapper" id="toolTipContentWrapper">
        </div>
    </telerik:RadToolTip>

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function findToolTip() {
                return $find("<%=Radtooltip1.ClientID%>");
            }
        </script>
    </telerik:RadCodeBlock>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance