Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Getting Started

  1. Create a new Blazor Server, Blazor Wasm, or Blazor Hybrid (MAUI) project, using the templates provided in your IDE or the dotnet CLI.
  2. add a PackageReference to the latest version of the dymaptic.GeoBlazor.Core package via your IDE’s Nuget Package Manager or dotnet add package dymaptic.GeoBlazor.Core.
  3. The ArcGIS API requires some form of authentication. The simplest is to use an API Key. Generate a key from the ArcGIS Developer Dashboard. For Blazor Server, place it in your appsettings.json, like this:

    {
        "ArcGISApiKey": "yourKeyValue"
    }
    
    Note: If you are using Blazor WASM, there are several issues with this approach. First, appsettings.json is not added by default to the template. If you want to add it yourself, you need to add it inside the wwwroot folder. Be Aware that the API key will be exposed in the browser (just like it would with Javascript). Even when using Blazor Server, the API key may be present in HTTP requests visible to the user in the browsers dev tools, so you should probably take other steps like setting up referrer rules in ArcGIS.
    You can also set up an OAuth2 workflow, which is more secure as it does not expose a static API key, but this is more complex. You can read about all the authentication options in Authentication.
  4. In the root file that defines your html, add the following lines to the <head> section. This would be _Layout.cshtml for Blazor Server, or index.html for Blazor Wasm and Blazor Hybrid. Note that YourProject is the namespace for the application that you are creating.

     <link href="_content/dymaptic.GeoBlazor.Core"/>
     <link href="_content/dymaptic.GeoBlazor.Core/assets/esri/themes/light/main.css" rel="stylesheet" />
     <link href="YourProject.styles.css" rel="stylesheet" />
    

    or (dark theme)

     <link href="_content/dymaptic.GeoBlazor.Core"/>
     <link href="_content/dymaptic.GeoBlazor.Core/assets/esri/themes/dark/main.css" rel="stylesheet" />
     <link href="YourProject.styles.css" rel="stylesheet" />
    
    Note: You may already have the `YourProject.styles.css` file. If so, you can just add the two lines to the existing file. In some .Net templates, this file is commented out by default and you will need to add it.
  5. In _Imports.razor, add the following lines, or add as needed to resolve code that you consume.

    @using dymaptic.GeoBlazor.Core.Components
    @using dymaptic.GeoBlazor.Core.Components.Geometries
    @using dymaptic.GeoBlazor.Core.Components.Layers
    @using dymaptic.GeoBlazor.Core.Components.Popups
    @using dymaptic.GeoBlazor.Core.Components.Symbols
    @using dymaptic.GeoBlazor.Core.Components.Views
    @using dymaptic.GeoBlazor.Core.Components.Widgets
    @using dymaptic.GeoBlazor.Core.Objects
    
  6. In Program.cs, add the following line to your builder.Services to inject logic components like GeometryEngine.
   builder.Services.AddGeoBlazor();
  1. Create a new Razor Component in the Pages folder, or just use Index.razor. Add a MapView. Give it basic

  2. Create a new Razor Component in the Pages folder, or just use Index.razor. Add a MapView. Give it basic parameters to ensure that it can render.

    @page "/"
    
    <MapView Longitude="_longitude" Latitude="_latitude" Zoom="11" Style="height: 400px; width: 100%;"> 
    </MapView>
    
    @code {
       private readonly double _latitude = 34.027;
       private readonly double _longitude = -118.805;
    } 
    
  3. Within the MapView, define a map using the WebMap component. To load a pre-generated map from ArcGIS Online or Portal, get the Map Id (PortalItem Id) of the map.

    <MapView Longitude="_longitude" Latitude="_latitude" Zoom="11" Style="height: 400px; width: 100%;"> 
        <WebMap>
            <PortalItem Id="4a6cb60ebbe3483a805999d481c2daa5" />
        </WebMap>
    </MapView>
    
  4. Add a Widget to the MapView, after the WebMap.

   <MapView Longitude="_longitude" Latitude="_latitude" Zoom="11" Style="height: 400px; width: 100%;"> 
       <WebMap>
           <PortalItem Id="4a6cb60ebbe3483a805999d481c2daa5" />
       </WebMap>
       <ScaleBarWidget Position="OverlayPosition.BottomLeft" />
   </MapView>
  1. Run your application and make sure you can see your map! Web Map Sample
  2. Now that you have a great starting point, you can now start to customize the features available in your new app using Geoblazor’s capabilites:
    -Take a look at the Documentation pages to learn more.