Skip to content

Commit

Permalink
allow fill colors for features too
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Oct 1, 2021
1 parent d902d8c commit b1ddef7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/my-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class MyMap extends LitElement {
@property({ type: String })
featureColor = "#0000ff";

@property({ type: Boolean })
featureFill = false;

@property({ type: Number })
featureBuffer = 40;

Expand Down Expand Up @@ -297,7 +300,10 @@ export class MyMap extends LitElement {
});
}

const outlineLayer = makeFeatureLayer(this.featureColor);
const outlineLayer = makeFeatureLayer(
this.featureColor,
this.featureFill
);
map.addLayer(outlineLayer);

// ensure getFeaturesAtPoint has fetched successfully
Expand Down
9 changes: 7 additions & 2 deletions src/os-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ import { GeoJSON } from "ol/format";
import { Vector as VectorLayer } from "ol/layer";
import { toLonLat } from "ol/proj";
import { Vector as VectorSource } from "ol/source";
import { Stroke, Style } from "ol/style";
import { Fill, Stroke, Style } from "ol/style";

import { hexToRgba } from "./utils";

const featureServiceUrl = "https://api.os.uk/features/v1/wfs";

const featureSource = new VectorSource();

export const outlineSource = new VectorSource();

export function makeFeatureLayer(color: string) {
export function makeFeatureLayer(color: string, featureFill: boolean) {
return new VectorLayer({
source: outlineSource,
style: new Style({
stroke: new Stroke({
width: 3,
color: color,
}),
fill: new Fill({
color: featureFill ? hexToRgba(color, 0.2) : hexToRgba(color, 0),
}),
}),
});
}
Expand Down

0 comments on commit b1ddef7

Please sign in to comment.