makeContext = async function(projection, {
width,
height = 500,
extent,
features,
paint_rules = undefined,
label_rules = undefined
} = {}) {
if(!extent && features) {
projection.fitExtent([[50,50],[width-50,height-50]], features)
}
let map = new protomaps.Static({url:'https://api.protomaps.com/tiles/v2/{z}/{x}/{y}.pbf?key=f5d904b825555256',paint_rules:paint_rules,label_rules:label_rules,language1:["name:en"]})
let top_left = projection.invert([0,0])
let bottom_right = projection.invert([width,height])
let context = DOM.context2d(width, height)
await map.drawContextBounds(context,top_left,bottom_right,width,height)
context.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0)
context.font = "200 12px sans-serif"
let text = "Protomaps © OpenStreetMap"
let metrics = context.measureText(text)
let padding = 4
let asc = metrics.actualBoundingBoxAscent
context.globalAlpha = 0.7
context.fillStyle = "white"
context.fillRect(width-metrics.width-padding*2,height-padding*2-asc,metrics.width+padding*2,asc+padding*2)
context.fillStyle = "#666"
context.fillText(text,width-metrics.width-padding,height-padding)
return context
}