Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
LarsBergqvist / map.component.ts
Created January 23, 2021 12:13
Init an OpenLayers Map object with TypeScript
private initilizeMap(): void {
//
// Create placeholders for markers
//
this.markers = [];
for (let i = 0; i < MapComponent.MaxNumMarkers; i++) {
this.markers.push(new Feature({}));
}
this.userMarker = new Feature();
@LarsBergqvist
LarsBergqvist / map.component.html
Last active January 23, 2021 07:32
Template for OpenLayers based Angular map component
<div id="attribution"></div>
<div id="map" class="map"></div>
@LarsBergqvist
LarsBergqvist / bash.sh
Created January 17, 2021 14:53
Add OpenLayers with TypeScript types to an Anguar application
yarn add ol
yarn add @types/ol --dev
@LarsBergqvist
LarsBergqvist / LocationsRepositoryAsync.cs
Last active February 10, 2020 17:49
An async implementation of the locations repository with Sqlite
using LocPoc.Contracts;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LocPoc.Repository.Sqlite
{
public class LocationsRepositoryAsync : ILocationsRepositoryAsync
{
@LarsBergqvist
LarsBergqvist / ILocationsRepositoryAsync.cs
Created February 10, 2020 15:40
An interface for an async version of the locations repository
using System.Collections.Generic;
using System.Threading.Tasks;
namespace LocPoc.Contracts
{
public interface ILocationsRepositoryAsync
{
Task<IEnumerable<Location>> GetAllAsync();
Task<Location> GetAsync(string id);
Task<Location> CreateAsync(Location location);
@LarsBergqvist
LarsBergqvist / LocationsController.cs
Last active February 10, 2020 15:38
LocationsController (simpified for readability)
namespace LocPoc.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LocationsController : ControllerBase
{
ILocationsRepositoryAsync _locationsRepository;
public LocationsController(ILocationsRepositoryAsync locationsRepository)
{
_locationsRepository = locationsRepository ?? throw new ArgumentNullException(nameof(locationsRepository));
@LarsBergqvist
LarsBergqvist / SqliteContext.cs
Created February 3, 2020 18:07
DbContext implementation for Location entities with a Sqlite database
using Microsoft.EntityFrameworkCore;
using LocPoc.Contracts;
namespace LocPoc.Repository.Sqlite
{
public class SqliteContext: DbContext
{
public SqliteContext(DbContextOptions<SqliteContext> options) : base(options)
{
}
@LarsBergqvist
LarsBergqvist / LocationsRepository.cs
Created February 3, 2020 14:39
Repository implementation using Sqlite
using LocPoc.Contracts;
using System;
using System.Collections.Generic;
namespace LocPoc.Repository.Sqlite
{
public class LocationsRepository : ILocationsRepository
{
private readonly SqliteContext _context;
@LarsBergqvist
LarsBergqvist / ILocationsRepository.cs
Last active February 10, 2020 15:33
Repository interface
using System.Collections.Generic;
namespace LocPoc.Contracts
{
public interface ILocationsRepository
{
IEnumerable<Location> GetAll();
Location Get(string id);
Location Create(Location location);
Location Update(Location location);
@LarsBergqvist
LarsBergqvist / app-config.json
Created February 3, 2020 14:03
Angular application configuration: use real data from the API and use Google Maps
{
"apiUrl": "https://localhost",
"apiPort": "5001",
"useFakeData": false,
"useMap": true,
"googleAPIKey": "ABzaDuAQbFxSalDaWfIAB7DEZAh730AFGGGlpg"
}