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;