# Marker Layer

The marker functionality allows you to add points of interest to the Map. These points are defined by the geographical position on the map and can show useful information to the user in a tooltip.

This article describes how to:

* [Create Marker layers](https://www.telerik.com/blazor-ui/documentation/components/map/layers/marker#creating-marker-layers)
* [Customize the Marker appearance](https://www.telerik.com/blazor-ui/documentation/components/map/layers/marker#customizing-marker-appearance)
* [Define Marker shapes](https://www.telerik.com/blazor-ui/documentation/components/map/layers/marker#defining-marker-shapes)
* [Set Marker tooltips](https://www.telerik.com/blazor-ui/documentation/components/map/layers/marker#setting-marker-tooltips)

## Creating Marker Layers

To define a Marker layer in the Map:

1. Add a `<MapLayer>` tag to `<MapLayers>`.
2. Set the `Type` parameter of the `MapLayer` to `MapLayersType.Marker`.
3. Set the `Data` parameter.
4. Set the `LocationField` and `TitleField` parameters to the respective property names of the model class.
5. (optional) Provide the [tooltip settings](https://www.telerik.com/blazor-ui/documentation/components/map/layers/marker#setting-marker-tooltips) or choose the [Marker shape](https://www.telerik.com/blazor-ui/documentation/components/map/layers/marker#defining-marker-shapes).

The Map aligns the bottom-center of each marker element to its coordinates. You can [shift the Map marker position for a different alignment with CSS](https://www.telerik.com/blazor-ui/documentation/knowledge-base/map-markers-misaligned).

The following example demonstrates how to configure the Marker layer of the Map.

> caption The Marker Map layer configuration

```RAZOR
<TelerikMap Center="@MapCenter"
            Height="85vh"
            Zoom="3">
    <MapLayers>
        <MapLayer Type="@MapLayersType.Tile"
                  Attribution="@MapAttribution"
                  Subdomains="@MapSubdomains"
                  UrlTemplate="mapUrlTemplateFunction">
        </MapLayer>

        <MapLayer Type="@MapLayersType.Marker"
                  Data="@MarkerData"
                  LocationField="@nameof(MarkerModel.LatLng)"
                  TitleField="@nameof(MarkerModel.Title)">
        </MapLayer>

    </MapLayers>
</TelerikMap>

<script suppress-error="BL9992">
    function mapUrlTemplateFunction(context) {
        return `https://${context.subdomain}.tile.openstreetmap.org/${context.zoom}/${context.x}/${context.y}.png`;
    }
</script>

@code {
    private double[] MapCenter { get; set; } = new double[] { 30.268107, -97.744821 };

    private readonly string[] MapSubdomains = new string[] { "a", "b", "c" };
    private const string MapAttribution = "&copy; <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>";

    private List<MarkerModel> MarkerData { get; set; } = new List<MarkerModel>() {
        new MarkerModel()
        {
            LatLng = new double[] { 30.268107, -97.744821 },
            Title = "Austin, TX"
        },
        new MarkerModel()
        {
            LatLng = new double[] { 37.7749, -122.4194 },
            Title = "San Francisco, CA"
        }
    };

    public class MarkerModel
    {
        public double[]? LatLng { get; set; }
        public string Title { get; set; } = string.Empty;
    }
}
```

## Customizing Marker Appearance

To customize the marker appearance, set the `Template` parameter in the `<MapLayerMarkerSettings>` child tag of the corresponding `MapLayer`.

The `Template` parameter must point to the name of a JavaScript function, which is defined in the global scope. This function must return plain text or HTML markup as a string. The template function argument is a JavaScript object with properties that match the Marker layer's model class.

The following example uses two Marker layers with different templates. One renders custom HTML markup. The other one shows how to render the built-in Map marker with custom colors.

> caption Using Map marker template



```RAZOR.skip-repl
<TelerikMap Center="@MapCenter"
            Height="85vh"
            Zoom="3">
    <MapLayers>
        <MapLayer Type="@MapLayersType.Tile"
                  Attribution="@MapAttribution"
                  Subdomains="@MapSubdomains"
                  UrlTemplate="mapLayerUrlTemplate">
        </MapLayer>

        <MapLayer Type="@MapLayersType.Marker"
                  Data="@MarkerData1"
                  LocationField="@nameof(MarkerModel.LatLng)"
                  TitleField="@nameof(MarkerModel.Title)">
            <MapLayerMarkerSettings Template="mapLayerMarkerTemplate" />
        </MapLayer>

        <MapLayer Type="@MapLayersType.Marker"
                  Data="@MarkerData2"
                  LocationField="@nameof(MarkerModel.LatLng)"
                  TitleField="@nameof(MarkerModel.Title)">
            <MapLayerMarkerSettings Template="mapLayerSvgMarkerTemplate" />
        </MapLayer>

    </MapLayers>
</TelerikMap>

@* Move the JavaScript code to a separate JS file. *@
<script suppress-error="BL9992">
    function mapLayerMarkerTemplate(context) {
        return `<span class="marker-star">${context.State}</span>`;
    }

    function mapLayerSvgMarkerTemplate(context) {
        return `<span style="color:${context.Color};" class="k-svg-icon k-icon-xxl" aria-hidden="true"><svg viewBox="0 0 512 512" focusable="false"><path d="M256 0C158.8 0 80 78.8 80 176s176 336 176 336 176-238.8 176-336S353.2 0 256 0m0 288c-61.9 0-112-50.1-112-112S194.1 64 256 64s112 50.1 112 112-50.1 112-112 112m48-112c0 26.5-21.5 48-48 48s-48-21.5-48-48 21.5-48 48-48 48 21.5 48 48"></path></svg></span>`;
    }

    function mapLayerUrlTemplate(context) {
        return `https://${context.subdomain}.tile.openstreetmap.org/${context.zoom}/${context.x}/${context.y}.png`;
    }
</script>

<style>
    .marker-star {
        background: palegoldenrod url(https://demos.telerik.com/kendo-ui/content/shared/icons/16/star.png) 0 center no-repeat;
        padding: .2em .2em .2em 20px;
    }
</style>

@code {
    private double[] MapCenter { get; set; } = new double[] { 30.268107, -97.744821 };

    private readonly string[] MapSubdomains = new string[] { "a", "b", "c" };
    private const string MapAttribution = "&copy; <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>";

    private List<MarkerModel> MarkerData1 { get; set; } = new List<MarkerModel>() {
        new MarkerModel()
        {
            LatLng = new double[] { 30.268107, -97.744821 },
            Title = "Austin",
            State = "TX"
        }
    };

    private List<MarkerModel> MarkerData2 { get; set; } = new List<MarkerModel>() {
        new MarkerModel()
        {
            LatLng = new double[] { 37.7749, -122.4194 },
            Title = "San Francisco",
            State = "CA",
            Color = "orange"
        },
        new MarkerModel()
        {
            LatLng = new double[] { 36.188110, -115.176468 },
            Title = "Las Vegas",
            State = "NV"
        },
        new MarkerModel()
        {
            LatLng = new double[] { 40.7166638, -74.0 },
            Title = "New York",
            State = "NY",
            Color = "blue"
        }
    };

    public class MarkerModel
    {
        public double[]? LatLng { get; set; }
        public string Title { get; set; } = string.Empty;
        public string State { get; set; } = string.Empty;
        public string Color { get; set; } = "--kendo-color-primary";
    }
}
```

## Defining Marker Shapes

The Map supports the `Pin` and `PinTarget` Marker types. To define the Marker type, use the `Shape` parameter of the `MapLayer` tag. By default, the visual appearance of the Marker is `PinTarget`.

> caption Different Marker shapes

```RAZOR
<TelerikButtonGroup SelectionMode="@ButtonGroupSelectionMode.Single">
    <ButtonGroupToggleButton Selected="@( MarkerShape == MapMarkersShape.PinTarget )"
                             OnClick="@( () => MarkerShape = MapMarkersShape.PinTarget )">
        Use Pin Target Markers
    </ButtonGroupToggleButton>
    <ButtonGroupToggleButton Selected="@( MarkerShape == MapMarkersShape.Pin )"
                             OnClick="@( () => MarkerShape = MapMarkersShape.Pin )">
        Use Pin Markers
    </ButtonGroupToggleButton>
</TelerikButtonGroup>

<TelerikMap Center="@MapCenter"
            Height="85vh"
            Zoom="3">
    <MapLayers>
        <MapLayer Type="@MapLayersType.Tile"
                  Attribution="@MapAttribution"
                  Subdomains="@MapSubdomains"
                  UrlTemplate="mapUrlTemplateFunction">
        </MapLayer>

        <MapLayer Type="@MapLayersType.Marker"
                  Data="@MarkerData"
                  LocationField="@nameof(MarkerModel.LatLng)"
                  TitleField="@nameof(MarkerModel.Title)"
                  Shape="@MarkerShape">
        </MapLayer>
    </MapLayers>
</TelerikMap>

<script suppress-error="BL9992">
    function mapUrlTemplateFunction(context) {
        return `https://${context.subdomain}.tile.openstreetmap.org/${context.zoom}/${context.x}/${context.y}.png`;
    }
</script>

@code {
    private double[] MapCenter { get; set; } = new double[] { 30.268107, -97.744821 };

    private MapMarkersShape MarkerShape { get; set; } = MapMarkersShape.Pin;

    private readonly string[] MapSubdomains = new string[] { "a", "b", "c" };
    private const string MapAttribution = "&copy; <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>";

    public List<MarkerModel> MarkerData { get; set; } = new List<MarkerModel>() {
        new MarkerModel()
        {
            LatLng = new double[] { 30.268107, -97.744821 },
            Title = "Austin, TX"
        },
        new MarkerModel()
        {
            LatLng = new double[] { 37.7749, -122.4194 },
            Title = "San Francisco, CA"
        }
    };

    public class MarkerModel
    {
        public double[]? LatLng { get; set; }
        public string Title { get; set; } = string.Empty;
    }
}
```

## Setting Marker Tooltips

The `MapLayerMarkerSettingsTooltip` tag allows you to fine-tune the content, appearance, and options of the tooltip, as well as fully customize its HTML content.

> caption Marker tooltip template

```RAZOR
<TelerikMap Center="@MapCenter"
            Height="85vh"
            Zoom="3">
    <MapLayers>
        <MapLayer Type="@MapLayersType.Tile"
                  Attribution="@MapAttribution"
                  Subdomains="@MapSubdomains"
                  UrlTemplate="mapUrlTemplateFunction">
        </MapLayer>

        <MapLayer Type="@MapLayersType.Marker"
                  Data="@MarkerData1"
                  LocationField="@nameof(MarkerModel.LatLng)"
                  TitleField="@nameof(MarkerModel.Title)">
            <MapLayerMarkerSettings>
                <MapLayerMarkerSettingsTooltip>
                    <Template>
                        @{ var dataItem = (MarkerModel)context.DataItem; }
                        <div>Marker Tooltip for: @dataItem.Title</div>
                    </Template>
                </MapLayerMarkerSettingsTooltip>
            </MapLayerMarkerSettings>
        </MapLayer>
    </MapLayers>
</TelerikMap>

<script suppress-error="BL9992">
    function mapUrlTemplateFunction(context) {
        return `https://${context.subdomain}.tile.openstreetmap.org/${context.zoom}/${context.x}/${context.y}.png`;
    }
</script>

@code {
    private double[] MapCenter { get; set; } = new double[] { 30.268107, -97.744821 };

    private readonly string[] MapSubdomains = new string[] { "a", "b", "c" };
    private const string MapAttribution { get; set; } = "&copy; <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>";

    private List<MarkerModel> MarkerData1 { get; set; } = new List<MarkerModel>() {
        new MarkerModel()
        {
            LatLng = new double[] { 30.268107, -97.744821 },
            Title = "Austin, TX"
        },
        new MarkerModel()
        {
            LatLng = new double[] { 37.7749, -122.4194 },
            Title = "San Francisco, CA"
        }
    };

    public class MarkerModel
    {
        public double[]? LatLng { get; set; }
        public string Title { get; set; } = string.Empty;
    }
}
```

## See Also

* [How to Change Map Marker Colors](https://www.telerik.com/blazor-ui/documentation/knowledge-base/map-change-marker-colors)
* [How to Change the Map Marker Alignment and Position](https://www.telerik.com/blazor-ui/documentation/knowledge-base/map-markers-misaligned)
