Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WorldMap component for Blazor WebAssembly and Blazor Server

NotificationsYou must be signed in to change notification settings

erossini/BlazorWorldMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

This component shows a map for using it withBlazor WebAssembly andBlazor Server. The components is build with .NET6.The map is build withjqvmap.jquery is required.

Now, usually in connection with the map, we want to display flags or icons. For that, you can use other my component that allows you to useSVG image for icons and flags.

You can see the component is action on thiswebsite. The full source code is onGitHub. For any comment or question, please use myforum in theWorldMap section.

Installation

Fist, you have to add the component from NuGet. Then, open yourindex.html or_Host and add at the end of the page the following scripts:

<script src="/_content/PSC.Blazor.Components.WorldMap/js/worldmap.js"></script>

The first script is the jqvmap library version 1.5.0 because I'm using this version to create the components. You can use other sources for it but maybe you can face issues in other versions.

Then, open your_Imports.razor and add the following:

@using PSC.Blazor.Components.WorldMap@using PSC.Blazor.Components.WorldMap.Enums

I recommend to add also the libraryPSC.Extensions to convert anenum in a string. See the example below.

@using PSC.Extensions

Add a new map

In your page you can create a new chart adding this code

<WorldMap Values="@values" TextTooltip=": {0} visitors" RegionSelect="@OnRegionSelect"     SelectedRegions="@SelectedRegions" SelectChanged="@SelectedChanged"    PinMode="PinMode.Id" Pins="@pins" />@code {    string SelectedRegions = "it, ru";    List<string> Selection = new List<string>();    Dictionary<string, string> pins = new Dictionary<string, string>()    {        { "it", "svgIcon" }    };    Dictionary<string, string> values = new Dictionary<string, string>()        {            { World.UnitedKingdom.GetDescription(), "15" },            { World.Italy.GetDescription(), "7.5" },            { World.Australia.GetDescription(), "9" },        };    Task OnRegionSelect(ChangeData data)    {        Console.WriteLine($"Selected {data.Code} / {data.Region}");        return Task.CompletedTask;    }    Task SelectedChanged(List<string> slc)    {        Selection = slc;        return Task.CompletedTask;    }}

So, with this code you create the map in the followinf screenshot

World Map Screenshot

Add the map to your project

Countries

CountryFile name
Worldjquery.vmap.world.js
Algeriajquery.vmap.algeria.js
Argentinajquery.vmap.argentina.js
Braziljquery.vmap.brazil.js
Canadajquery.vmap.canada.js
Croatiajquery.vmap.croatia.js
Francejquery.vmap.france.js
Germanyjquery.vmap.germany.js
Greecejquery.vmap.greece.js
Indonesiajquery.vmap.indonesia.js
Iranjquery.vmap.iran.js
Iraqjquery.vmap.iraq.js
Polandjquery.vmap.poland.js
Russiajquery.vmap.russia.js
Serbiajquery.vmap.serbia.js
Tunisiajquery.vmap.tunisia.js
Turkeyjquery.vmap.turkey.js
Ukrainejquery.vmap.ukraine.js
Usajquery.vmap.usa.js
Venezuelajquery.vmap.venezuela.js

Regions

RegionFile name
Europejquery.vmap.europe.js
Francejquery.vmap.new_regions_france.js
USA countriesjquery.vmap.usa.counties.js
USA Districtsjquery.vmap.usa.districts.js

Continents

ContinentFile name
Africajquery.vmap.africa.js
Asiajquery.vmap.asia.js
Australiajquery.vmap.australia.js
Europejquery.vmap.europe.js
North Americajquery.vmap.north-america.js
South Americajquery.vmap.south-america.js

Configuration settings

PropertyDescriptionDefault
MapMap you want to load. Must include the javascript file with the name of the map you want. Available maps with this library areworld_en,usa_en,europe_en andgermany_enworld_en
BackgroundColorBackground color of map container in any CSS compatible format.#a5bfdd
BorderColorBorder Color to use to outline map objects#818181
BorderOpacityBorder Opacity to use to outline map objects (use anything from 0-1, e.g. 0.5)0.25
BorderWidthBorder Width to use to outline map objects1
ColorColor of map regions.#f4f3f0
ColorsColors of individual map regions. Keys of the colors objects are country codes according to ISO 3166-1 alpha-2 standard. Keys of colors must be in lower case.
EnableZoomWhether to Enable Map Zoom (true or false)true
HeightHeight of the map container300px
HoverColorColor of the region when mouse pointer is over it.#c9dfaf
HoverColorsColors of individual map regions when mouse pointer is over it. Keys of the colors objects are country codes according to ISO 3166-1 alpha-2 standard. Keys of colors must be in lower case.
HoverOpacityOpacity of the region when mouse pointer is over it.
NormalizeFunctionThis function can be used to improve results of visualizations for data with non-linear nature. Function gets raw value as the first parameter and should return value which will be used in calculations of color, with which particular region will be painted.linear
ScaleColorsThis option defines colors, with which regions will be painted when you set option values. Array scaleColors can have more then two elements. Elements should be strings representing colors in RGB hex format.['#b6d6ff', '#005ace']
SelectedColorColor for a region when you select it#333333
SelectedRegionsThis is the Region that you are looking to have preselected (two letter ISO code, defaults to null). See Region sectionnull
MultiSelectRegionWhether to enable more than one region to be selected at a time.
ShowLabelsWhether to show ISO Code Labels (true or false)true
ShowTooltipWhether to show Tooltips on Mouseover (true or false)true
WidthWidth of the map container100%
ValuesDictionary of the value to use for each countrynull

Events

EventDescription
onLoadCallback function which will be called when map is loading, returning the map event and map details.
onLabelShowCallback function which will be called before label is shown. Label DOM object and country code will be passed to the callback as arguments.
onRegionOverCallback function which will be called when the mouse cursor enters the region path. Country code will be passed to the callback as argument.
onRegionOutCallback function which will be called when the mouse cursor leaves the region path. Country code will be passed to the callback as argument.
onRegionClickCallback function which will be called when the user clicks the region path. Country code will be passed to the callback as argument. This callback may be called while the user is moving the map. If you need to distinguish between a "real" click and a click resulting from moving the map
onRegionSelectCallback function which will be called when the selects a region. Country code will be passed to the callback as argument.
onRegionDeselectCallback function which will be called when the deselects a region. Country code will be passed to the callback as argument.
onResizeCallback function which will be called when the map is resized. Return event, width & height.

Regions and enums

World

Country codeRegion name
AEUnited Arab Emirates
AFAfghanistan
AGAntigua and Barbuda
ALAlbania
AMArmenia
AOAngola
ARArgentina
ATAustria
AUAustralia
AZAzerbaijan
BABosnia and Herzegovina
BBBarbados
BDBangladesh
BEBelgium
BFBurkina Faso
BGBulgaria
BIBurundi
BJBenin
BNBrunei Darussalam
BOBolivia
BRBrazil
BSBahamas
BTBhutan
BWBotswana
BYBelarus
BZBelize
CACanada
CDCongo
CFCentral African Republic
CGCongo
CHSwitzerland
CICote d'Ivoire
CLChile
CMCameroon
CNChina
COColombia
CRCosta Rica
CUCuba
CVCape Verde
CYCyprus
CZCzech Republic
DEGermany
DJDjibouti
DKDenmark
DMDominica
DODominican Republic
DZAlgeria
ECEcuador
EEEstonia
EGEgypt
EREritrea
ESSpain
ETEthiopia
FIFinland
FJFiji
FKFalkland Islands
FRFrance
GAGabon
GBUnited Kingdom
GDGrenada
GEGeorgia
GFFrench Guiana
GHGhana
GLGreenland
GMGambia
GNGuinea
GQEquatorial Guinea
GRGreece
GTGuatemala
GWGuinea-Bissau
GYGuyana
HNHonduras
HRCroatia
HTHaiti
HUHungary
IDIndonesia
IEIreland
ILIsrael
INIndia
IQIraq
IRIran
ISIceland
ITItaly
JMJamaica
JOJordan
JPJapan
KEKenya
KGKyrgyz Republic
KHCambodia
KMComoros
KNSaint Kitts and Nevis
KPNorth Korea
KRSouth Korea
KWKuwait
KZKazakhstan
LALao People's Democratic Republic
LBLebanon
LCSaint Lucia
LKSri Lanka
LRLiberia
LSLesotho
LTLithuania
LVLatvia
LYLibya
MAMorocco
MDMoldova
MGMadagascar
MKMacedonia
MLMali
MMMyanmar
MNMongolia
MRMauritania
MTMalta
MUMauritius
MVMaldives
MWMalawi
MXMexico
MYMalaysia
MZMozambique
NANamibia
NCNew Caledonia
NENiger
NGNigeria
NINicaragua
NLNetherlands
NONorway
NPNepal
NZNew Zealand
OMOman
PAPanama
PEPeru
PFFrench Polynesia
PGPapua New Guinea
PHPhilippines
PKPakistan
PLPoland
PTPortugal
PYParaguay
QAQatar
REReunion
RORomania
RSSerbia
RURussian Federationß
RWRwanda
SASaudi Arabia
SBSolomon Islands
SCSeychelles
SDSudan
SESweden
SISlovenia
SKSlovakia
SLSierra Leone
SNSenegal
SOSomalia
SRSuriname
STSao Tome and Principe
SVEl Salvador
SYSyrian Arab Republic
SZSwaziland
TDChad
TGTogo
THThailand
TJTajikistan
TLTimor-Leste
TMTurkmenistan
TNTunisia
TRTurkey
TTTrinidad and Tobago
TWTaiwan
TZTanzania
UAUkraine
UGUganda
USUnited States of America
UYUruguay
UZUzbekistan
VEVenezuela
VNVietnam
VUVanuatu
YEYemen
ZASouth Africa
ZMZambia
ZWZimbabwe

USA

District codeRegion name
AKAlaska
ALAlabama
ARArkansas
AZArizona
CACalifornia
COColorado
CTConnecticut
DCDistrict of Columbia
DEDelaware
FLFlorida
GAGeorgia
HIHawaii
IAIowa
IDIdaho
ILIllinois
INIndiana
KSKansas
KYKentucky
LALouisiana
MAMassachusetts
MDMaryland
MEMaine
MIMichigan
MNMinnesota
MOMissouri
MSMississippi
MTMontana
NCNorth Carolina
NDNorth Dakota
NENebraska
NHNew Hampshire
NJNew Jersey
NMNew Mexico
NVNevada
NYNew York
OHOhio
OKOklahoma
OROregon
PAPennsylvania
RIRhode Island
SCSouth Carolina
SDSouth Dakota
TNTennessee
TXTexas
UTUtah
VAVirginia
VTVermont
WAWashington
WIWisconsin
WVWest Virginia
WYWyoming

Europe

Country codeRegion name
ADAndorra
ALAlbania
AMArmenia
ATAustria
AZAzerbaijan
BABosnia and Herzegovina
BEBelgium
BGBulgaria
BYBelarus
CHSwitzerland
CYCyprus
CZCzech Republic
DEGermany
DKDenmark
DZAlgeria
EEEstonia
ESSpain
FIFinland
FRFrance
GBUnited Kingdom
GEGeorgia
GLGreenland
GRGreece
HRCroatia
HUHungary
IEIreland
ILIsrael
IQIraq
IRIran
ISIceland
ITItaly
JOJordan
KZKazakhstan
LBLebanon
LILiechtenstein
LTLithuania
LULuxembourg
LVLatvia
MAMorocco
MCMonaco
MDMoldova
MEMontenegro
MKMacedonia
MTMalta
NLNetherlands
NONorway
PLPoland
PTPortugal
RORomania
RURussian Federation
SASaudi Arabia
SESweden
SISlovenia
SKSlovakia
SMSan Marino
SRSuriname
SYSyrian Arab Republic
TMTurkmenistan
TNTunisia
TRTurkey
UAUkraine

Germany

Region codeRegion name
BBBrandenburg
BEBerlin
BWBaden-WÃrttemberg
BYBayern
HBBremen
HEHessen
HHHamburg
MVMecklenburg-Vorpommern
NINiedersachsen
NWNordrhein-Westfalen
RPRheinland-Pfalz
SHSchleswig-Holstein
SLSaarland
SNSachsen
STSachsen-Anhalt
THThÃri

Russia

Region codeRegion name
CHChukotka Autonomous Okrug
KAKamchatka Krai
MAMagadan Oblast
SASakha Republic
AMAmur Oblast
PRPrimorsky Krai
EUJewish Autonomous Oblast
HAKhabarovsk Krai
SHSakhalin Oblast
OMOmsk Oblast
NVNovosibirsk Oblast
ALAltai Krai
LTAltai Republic
TVTuva Republic
HKRepublic of Khakassia
KMKemerovo Oblast
TMTomsk Oblast
ZBZabaykalsky Krai
BRBuryat Republic
IRIrkutsk Oblast
KRKrasnoyarsk Krai
YAYamalo-Nenets Autonomous Okrug
HTKhanty-Mansi Autonomous Okrug
TUTyumen Oblast
KUKurgan Oblast
CLChelyabinsk Oblast
SVSverdlovsk Oblast
ARArkhangelsk Oblast
NENenets Autonomous Okrug
KOKomi Republic
MUMurmansk Oblast
VOVologda Oblast
NONovgorod Oblast
PSPskov Oblast
LELeningrad Oblast
KLRepublic of Karelia
KNKaliningrad Oblast
DARepublic of Dagestan
STStavropol Krai
SORepublic of North Ossetia-Alania
KBKabardino-Balkar Republic
KHKarachay-Cherkess Republic
CCChechen Republic
INRepublic of Ingushetia
ADRepublic of Adygea
KSKrasnodar Krai
RORostov Oblast
KKRepublic of Kalmykia
ASAstrakhan Oblast
VLVolgograd Oblast
TRTver Oblast
SMSmolensk Oblast
BNBryansk Oblast
KYKursk Oblast
BLBelgorod Oblast
OROryol Oblast
KJKaluga Oblast
TLTula Oblast
LPLipetsk Oblast
MCMoscow Oblast
RZRyazan Oblast
TBTambov Oblast
VMVladimir Oblast
IVIvanovo Oblast
YRYaroslavl Oblast
KTKostroma Oblast
NNNizhny Novgorod Oblast
MRRepublic of Mordovia
PZPenza Oblast
SRSaratov Oblast
SSSamara Oblast
OBOrenburg Oblast
BSRepublic of Bashkortostan
ULUlyanovsk Oblast
CUChuvash Republic
TARepublic of Tatarstan
MLMari El Republic
UDUdmurt Republic
KIKirov Oblast
PEPerm Krai
VNVoronezh Oblast

Licence and contribution

A lot of people sent me the same question. My components (MarkdownEditor,DataTable,SVG Icon and others that you find on myGitHub) are freeware.

I ask you to contribute to the project in one of the following ways:

  • sending your feedback
  • highlight bugs
  • ask for improvement
  • submit code and fixes
  • share the project
  • share my websitePureSourceCode.com

If you don't know how to do it or you:

  • want to support this project
  • find very useful this project and it saves you a lot of time and work
  • like to sustain my work
  • want to pay my a beer
  • are using this component for commercial purpose and you want to set your conscience at rest and/or put a hand on one's heart 😂

then, you can buy one of the support licence I created. There are different prices. The amount is your decision. You find have a full list onPureSourceCode Shop

The contribution gives you:

  • dedicate email support
  • priority access to the support
  • fast bug fix
  • receive preview and beta of the components
  • help to fix your code withVisual Studio Live Share

Other Blazor components

Component nameForumDescription
Chart.js for BlazorForumComponent for Blazor WebAssembly and Blazor Server for creating graphs using Chart.js
DataTable for BlazorForumDataTable component for Blazor WebAssembly and Blazor Server
Markdown editor for BlazorForumThis is a Markdown Editor for use in Blazor. It contains a live preview as well as an embeded help guide for users.
Modal dialog for BlazorForumSimple Modal Dialog for Blazor WebAssembly
PSC.ExtensionsForumA lot of functions for .NET5 in a NuGet package that you can download for free. We collected in this package functions for everyday work to help you with claim, strings, enums, date and time, expressions...
Quill for BlazorForumQuill Component is a custom reusable control that allows us to easily consume Quill and place multiple instances of it on a single page in our Blazor application
Segment for BlazorForumThis is a Segment component for Blazor Web Assembly and Blazor Server
Tabs for BlazorForumThis is a Tabs component for Blazor Web Assembly and Blazor Server

More examples and documentation

About

WorldMap component for Blazor WebAssembly and Blazor Server

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp