-
Notifications
You must be signed in to change notification settings - Fork 81
Added new kb article map-kb-customize-marker-colors #2700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Tsvetomir-Hr
merged 5 commits into
master
from
new-kb-map-kb-customize-marker-colors-0811f4f4659446da917cbf310881abb5
Jan 22, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f89acd3
Added new kb article map-kb-customize-marker-colors
61e7714
chore: kb polish and file rename
Tsvetomir-Hr 3a31610
chore: polish example and add link in the market layer article
Tsvetomir-Hr 503308a
chore: polish example
Tsvetomir-Hr 6f593f9
chore: apply suggestion
Tsvetomir-Hr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| --- | ||
| title: How to Change Map Markers Colors | ||
| description: Learn how to customize the appearance of map markers by setting and changing their colors in a Blazor application. | ||
| type: how-to | ||
| page_title: How to Change Map Markers Colors | ||
| slug: map-kb-change-marker-colors | ||
| tags: map, markers | ||
| res_type: kb | ||
| ticketid: 1675518 | ||
| --- | ||
|
|
||
| ## Environment | ||
|
|
||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>Map for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| ## Description | ||
|
|
||
| When integrating a [Map for Blazor](slug://components/map/layers), you might want to customize the appearance of your map markers to differentiate them or match your application's theme. This knowledge base article also answers the following questions: | ||
|
|
||
| - How can I set the color of a map marker in Blazor? | ||
| - How to change the color of specific map markers based on their titles? | ||
| - How to apply custom styles to map markers in a Blazor application? | ||
|
|
||
| ## Solution | ||
|
|
||
| To customize the color of map markers in a Blazor application, you can [override the default theme styles](slug://themes-override). | ||
|
|
||
| ### Change the Color to All Map Markers | ||
|
|
||
| To change the color for all markers use the following CSS approach: | ||
|
|
||
| <div class="skip-repl"></div> | ||
| ````RAZOR | ||
| <TelerikMap Class="my-map"> | ||
| <!-- Map configuration --> | ||
| </TelerikMap> | ||
|
|
||
| <style> | ||
| .my-map.k-map .k-marker { | ||
| color: blue; | ||
| } | ||
| </style> | ||
| ```` | ||
|
|
||
| ### Customize Specific Markers | ||
|
|
||
| To change the color of specific markers, target them based on their titles using CSS. Check the runnable example below: | ||
|
|
||
| ````RAZOR | ||
| <TelerikMap Center="@Center" Zoom="3" Class="my-map"> | ||
| <MapLayers> | ||
| <MapLayer Type="@MapLayersType.Marker" | ||
| Data="@MarkerData" | ||
| LocationField="@nameof(MarkerModel.LatLng)" | ||
| TitleField="@nameof(MarkerModel.Title)"> | ||
| </MapLayer> | ||
| <MapLayer Type="@MapLayersType.Tile" | ||
| Attribution="@Attribution" | ||
| Subdomains="@Subdomains" | ||
| UrlTemplate="@UrlTemplate"> | ||
| </MapLayer> | ||
| <MapLayer Type="@MapLayersType.Marker" | ||
| Data="@MarkerData" | ||
| LocationField="@nameof(MarkerModel.LatLng)" | ||
| TitleField="@nameof(MarkerModel.Title)"> | ||
| </MapLayer> | ||
| </MapLayers> | ||
| </TelerikMap> | ||
|
|
||
| @foreach (var mrk in MarkerData) | ||
| { | ||
| <style> | ||
| @* targets the default state *@ | ||
| .my-map .k-marker[title="@mrk.Title"], | ||
| @* targets the hover state *@ | ||
| .my-map .k-marker[data-title="@mrk.Title"] { | ||
| color: @mrk.Color; | ||
| } | ||
| </style> | ||
| } | ||
|
|
||
| @code { | ||
| private string[] Subdomains { get; set; } = new string[] { "a", "b", "c" }; | ||
| private string UrlTemplate { get; set; } = "https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png"; | ||
| private string Attribution { get; set; } = "© <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>"; | ||
| private double[] Center { get; set; } = new double[] { 30.268107, -97.744821 }; | ||
|
|
||
| private List<MarkerModel> MarkerData { get; set; } = new List<MarkerModel>() | ||
| { | ||
| new MarkerModel() | ||
| { | ||
| LatLng = new double[] { 30.268107, -97.744821 }, | ||
| Title = "Austin, TX", | ||
| Color = "#008000" | ||
| }, | ||
| new MarkerModel() | ||
| { | ||
| LatLng = new double[] { 37.7749, -122.4194 }, | ||
| Title = "San Francisco, CA", | ||
| Color = "#0000FF" | ||
| } | ||
| }; | ||
|
|
||
| public class MarkerModel | ||
| { | ||
| public double[]? LatLng { get; set; } | ||
| public string Title { get; set; } = null!; | ||
| public string Color { get; set; } = null!; | ||
| } | ||
| } | ||
| ```` | ||
|
|
||
| ## See Also | ||
|
|
||
| - [Override Theme Styles](slug://themes-override) | ||
| - [Map - Marker Layer](slug://components/map/layers/marker) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.