Add MN Ambulance Service Areas layer
Requested-By: Isaac Swift
This commit is contained in:
parent
e233c8dda6
commit
66205965ce
4 changed files with 115 additions and 0 deletions
54
layers/mn-ambulance-service-areas/layer.js
Normal file
54
layers/mn-ambulance-service-areas/layer.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import GeoJSON from 'ol/format/GeoJSON.js';
|
||||
import VectorLayer from 'ol/layer/Vector.js';
|
||||
import VectorSource from 'ol/source/Vector.js';
|
||||
|
||||
import serviceAreas from './mn-ambulance-service-areas.geojson?url';
|
||||
|
||||
import { Fill, Stroke, Style, Text } from 'ol/style.js';
|
||||
|
||||
window.chosenColors = {};
|
||||
window.chosenColors2 = {};
|
||||
|
||||
function style(feature){
|
||||
const name = feature.get('AmbServNam');
|
||||
// // djb2 -- results in very non-uniform distribution
|
||||
// // https://web.archive.org/web/20251011200517/https://www.cse.yorku.ca/~oz/hash.html
|
||||
// let hash = 5381;
|
||||
// for (let i = 0; i < name.length; i++) {
|
||||
// hash = hash * 33 + name.charCodeAt(i);
|
||||
// }
|
||||
// const colorDeg = hash % 360;
|
||||
|
||||
// erichash -- thanks @villnoweric
|
||||
let hash = 0;
|
||||
for (let i = 0; i < name.length; i++) {
|
||||
hash += name.charCodeAt(i);
|
||||
}
|
||||
let colorDeg = hash % 360;
|
||||
|
||||
return new Style({
|
||||
text: new Text({
|
||||
text: name,
|
||||
}),
|
||||
fill: new Fill({
|
||||
color: `lch(50% 50 ${colorDeg} / 40%)`,
|
||||
}),
|
||||
stroke: new Stroke({
|
||||
color: `lch(50% 50 ${colorDeg})`,
|
||||
width: 1.25,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
const layer = {
|
||||
name: "MN Ambulance Service Areas",
|
||||
layer: new VectorLayer({
|
||||
source: new VectorSource({
|
||||
url: serviceAreas,
|
||||
format: new GeoJSON(),
|
||||
}),
|
||||
style: style,
|
||||
}),
|
||||
};
|
||||
|
||||
export default layer;
|
||||
Loading…
Add table
Add a link
Reference in a new issue