Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
LarsBergqvist / map-functions.ts
Created Jan 23, 2021
Helper functions for working with Features/Markers in OpenLayers
View map-functions.ts
import { click } from 'ol/events/condition';
import Feature from 'ol/Feature';
import Select, { SelectEvent } from 'ol/interaction/Select';
import VectorLayer from 'ol/layer/Vector';
import Map from 'ol/Map';
import { Fill, Icon, Style, Text } from 'ol/style';
export function styleMarkersAsDeselected(features: Feature[]) {
if (!features) return;
features.forEach((f) => {
@LarsBergqvist
LarsBergqvist / map.component.ts
Created Jan 23, 2021
Update an OpenLayers map with markers
View map.component.ts
private setupMap(input: MapInput) {
this.positions = input.markerPosisitons;
this.userPos = input.userPos;
if (!this.map) {
this.initilizeMap();
}
const view = this.map.getView();
if (this.positions.length > 0) {
@LarsBergqvist
LarsBergqvist / map.component.ts
Created Jan 23, 2021
Init an OpenLayers Map object with TypeScript
View map.component.ts
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 Jan 23, 2021
Template for OpenLayers based Angular map component
View map.component.html
<div id="attribution"></div>
<div id="map" class="map"></div>
@LarsBergqvist
LarsBergqvist / bash.sh
Created Jan 17, 2021
Add OpenLayers with TypeScript types to an Anguar application
View bash.sh
yarn add ol
yarn add @types/ol --dev
@LarsBergqvist
LarsBergqvist / LocationsRepositoryAsync.cs
Last active Feb 10, 2020
An async implementation of the locations repository with Sqlite
View LocationsRepositoryAsync.cs
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 Feb 10, 2020
An interface for an async version of the locations repository
View ILocationsRepositoryAsync.cs
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 Feb 10, 2020
LocationsController (simpified for readability)
View LocationsController.cs
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 Feb 3, 2020
DbContext implementation for Location entities with a Sqlite database
View SqliteContext.cs
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 Feb 3, 2020
Repository implementation using Sqlite
View LocationsRepository.cs
using LocPoc.Contracts;
using System;
using System.Collections.Generic;
namespace LocPoc.Repository.Sqlite
{
public class LocationsRepository : ILocationsRepository
{
private readonly SqliteContext _context;