Tower of Prince Henry, Reversed

Ok, for you to enjoy this blog post I’m pretty confident that you have to be a bit of a JavaScript, Python and map geek. At least you will have to watch this presentation from FOSS4G 2014 by Eric Theise.

Ok, you watched it? You got his point? My takeaway was that as you generate map tiles further down in the zoom stack you’ll have to generate a ton of tiles, but in many cases you only want to show a map that puts your town/buisiness/whatever on the map. But, you would like some context, and then you have to set the bbox in TileMill WIDE. And then the tileset gets large, and you don’t bother.

So, I thought that there should be a way to limit a web map library to only request tiles that are within a given bounding box. Turns out that Leaflet has this option, set the “bounds” parameter on an L.TileLayer and you are good to go?

L.TileLayer('http://{s}{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors',
bounds: bounds

Well, the user can still pan away from the area, so set “maxBounds” on the map as well:

var map ='map', {maxBounds: bounds}).setView([63.4, 10.3], 0);

This works, the amount of requests sent to the tile server is reduced, but it doesn’t look good, does it:

The main problem is that L.TileLayer only loads tiles that intersects with the bounding box you’ve set (the small, blue square on my map). So, we’ll have to do something about that, and after a bit of digging I found that the “_tileShouldBeLoaded” method of L.TileLayer performs this check (at least in version 0.7.3). Thankfully, Leaflet classes are easy to subclass, and so “L.BoundedTileLayer” was born.

To get more context around I wanted to show some neighboring tiles as well as those that intersects the bounds. So, after we check for intersection we perform one additional check, which I think is best described in code:

//the distance from the tilecenter lng to closest bounds edge
var lngDist = Math.min(
Math.abs(tileCenter.lng - options.bounds.getEast()),
Math.abs(tileCenter.lng - options.bounds.getWest())

//the distance from the tilecenter lat to closest bounds edge
var latDist = Math.min(
Math.abs( - options.bounds.getSouth()),
Math.abs( - options.bounds.getNorth())

//these are probably equal
var tileWidth = Math.abs(nw.lng - se.lng);
var tileHeight = Math.abs( -;

//check if tile should be loaded
return lngDist < tileWidth && latDist < tileHeight;

In essence, I check if the distance from the distance from the center of a given tile is smaller than the width or height of a tile. This can probably be optimized a bit, and I can almost guarantee that there are corner cases that I've missed, but it seems to work as expected:


Now we get more context, and we still limit the amount of tiles requested. Happy?

No: we still have to generate all those tiles, because we can't know what tiles the client will request. So, ditching JavaScript and Leaflet for a bit I switched to Python and tried to find a way to generate a list of all tiles the client would request using L.BoundedTileLayer for a given bounding box.

Luckily some smart people have already tackled the maths involved in computing tile indexes from bounding boxes, and the open source script I found at was a good starting point. After that it was just a matter of porting the logic from L.BoundedTileLayer to Python, free myself from the Leaflet context and write some 30 lines of code (3-4 hours of trial and error, I don't know how many times I've mixed up axis ordering!).

In the end I could throw a bounding box and a minimum and maximum zoom level at my script and get back a list in the form of:

{"z": 0, "y": 0, "x": 0},
{"z": 1, "y": 0, "x": 0},
{"z": 1, "y": 1, "x": 0},

But this doesn't help me much, I want to generate these specific tiles using TileMill! So, then I started researching how to do that. Nothing came up, except this page describing how to export tiles from TileMill via the command line. I studied the (lack of?) documentation, before I started digging into the source of TileMill and TileLive (which TileMill uses to use Mapnik to render tiles), but after 3 hours I was going nowhere, and it did not work. The next day I asked on stackexchange, and a couple of hours later it dawned on me (to quote my own answer): "that the option --list=[file] could be what I was after."

After digging a bit through the tilemill and tilelive source code i found that this options is (not suprisingly) used by the filescheme renderer (it says that in the comments), and some further digging in the source code to figure out the format of the file, I was able to tell TileMill to render a specific set of tiles.


Well, a bit on streamlining was called for, so I cleaned up stuff a bit, created a config file for input and looked into calling the TileMill export function from my Python code. This all worked fine, and pretty soon I could type "python -c config.json" and 3 minutes after have an .mbtiles file of about 14 MB that covers the Trondheim municipality, zoomable from zoom level 0 through 18. Neat!

Then, the moment of truth. Would the tileset I generated line up with what my Leaflet layer requested? I installed TileStache, and 30 seconds later I had a tileserver running at localhost, serving my generated .mbtiles file to my Leaflet map! And it worked!

So, why should you care? Well, I for one, think this is cool by itself, but I also see some useful applications for this. The components I've built now are not far away from the point where I can invoke the generation of a new tileset from a web map. If I do this i can load up a PostGIS database with up-to-data, detailed map data (and refill it through a cron-job or somethin), define the cartography in CartoCSS, and generate a small tilecache for small projects on-the-fly, when needed.

The only drawback is that I have to learn CartoCSS properly to do this, but I guess that's the topic of another blog post.

Do you have any ideas how this can be used, improved or built upon? Feel free to let me know, either in the comments here or via a pull request to the GitHub repo!

Debunking Map Myth #4: The earth is round

Ok, ok, unless you are a member of the “Flat Earth Society” (or a geographer), you might think I’ve gone insane right now?

Well, the earth isn’t round if you by round mean a “sphere“, which Wikipedia defines as:

[...] a perfectly round geometrical and circular object in three-dimensional space that resembles the shape of a completely round ball

So, what is the earth then? Actually, the Earth is a misshapen blob of matter that if matched to a mathematically defined shape would be an “ellipsoid“, i.e. the three-dimensional variant of an ellipse, or a lightly squeezed sphere if you like.

So, dependent of how mathematical you need to be the earth is either an ellipsoid, and these ellipsoids can be defined in several ways, as we discussed when debunking myth #1. These ellipsoids are defined by the parameters semi-major axis, a and semi-minor axis, b, from which you can deduce the flattening, f. The flattening occurs due to the fact that the earth spins.

This ellipsoid is what the GPS-systems use to determine your position, and forms the basis of latitude/longitudes.

But, the more interesting case is perhaps the “misshapen blob of matter”, called the Geoid, that is:

[...]the shape that the surface of the oceans would take under the influence of Earth’s gravitation and rotation alone, in the absence of other influences such as winds and tides.

To determine the actual shape of the geoid, geodesists rely on gravitational measurements from satellites, and by knowing the actual geoid height at a known location you can get a rather accurate idea of your “height above sea level” from a GPS (which really only measures the “ellipsoid height”. These calculations are rather complex, but given decent data they are simple enough that I’ve managed to write a Fortran program which does compute it.

So, there you have it, the earth isn’t round: it’s either ellipsoidal or misshapen, dependent on what you intend to use it for (and for the purpose of myth #5, it’s certainly not ellipsoidal!)

(And by the way, people in the middle ages did not think the earth was flat either!)

Ølbyen Trondheim

På lørdag ettermiddag satt jeg på Sot på Solsiden med en øl, og i en plutselig entusiasme over hvor bra Trondheim er som ølby twitret jeg følgende:

I etterkant har jeg tenkt mer over det, og det er faktisk enda bedre. Så, for de som ikke bor i byen, eller ikke frekventerer “trønderske ølfanatikere”, eller bare vil ha en oversikt over hva som skjer på øl-fronten i Trondheim kommer en oversikt fra mitt ståsted. Det er sikkert også mer som skjer, så si gjerne fra.

Ja, E.C. Dahls er på vei ut og vekk, men de siste åra har vi sett en del nye bryggerier i byen og omegn.

Mest kjent er kanskje Austmann Bryggeri på Byneset (eller Høvringen for å være korrekt). Massevis av spennende (og noen kanskje ikke fullt så spennende øl), trivelige folk og “storleverandør” til polet, ikke værst på halvannet år. Northumberland har blitt et av favorittøelene mine, og det er faktisk et øl du får tak i på flere og flere steder i byen.

En annen nykommer er norges eneste (?) “gravitasjonsbryggeri”, To Tårn. Disse holder til i sand- og vanntårnet til jernbaneverket på Marienborg, og selv om jeg synes endel av ølet deres lider under “butikkgrensa” klarer de å levere endel gode øl. Sist ut var Solbærporter. Distribusjon ganske lokalt, utsalg og “pubkvelder” i bryggeriet av og til, men ikke full-distribuert på samme måte som Austmann.

Beveger vi oss utover bygrensene, men holder oss i Trøndelag har vi Klostergården bryggeri, som kanskje har gjort seg mest bemerket med sin tolkning av stjørdalsølet: Alstadberger, men de produserer også endel annet godt. Noe av ølet lider også under “butikkgrensa”, men andre er bare nydelige. Desverre er kun Alstadberger å finne på polet, så her er du avhengig av å være på rett sted til rett tid.

Bortsett fra disse finnes det en hel rekke “mikrobryggerier” i Trøndelag. I tillegg er det ikke lange veien til Stjørdal og Oppdal, to av lommene hvor norsk tradisjonsbrygging fortsatt lever.

Som om ikke dette er nok er hjemmebryggemiljøet i byen stort, det brygges øl på Moholt, det arrangeres hjemmebryggefestival, vinnerene av NM i hjemmebrygg 2013 var fra Trondheim, og tror du ikke hjemmebryggerene bak Polaris Porter også holder til i byen?

Byen huser også Bakke Brygg, en levrandør av råvarer, utstyr og kunnskap for hjemmebrygging. Disse har allerede flyttet en gang for å dekke etterspørselen, så det er ikke tvil om at hjemmebryggemiljøet lever i beste velgående her!

Trondheim Mikrobryggeri er kanskje i den siste tiden mest kjent for øltavla si, men har servert øl brygget på stedet i 1998, og var sånn sett veldig tidlig ute. Man kan mene mye om ølet de lager, de serverer kun eget øl og kvaliteten kan variere.

Det skulle ta lang tid før Trondheim fikk flere bryggeripuber, men så kom det plutselig to på rappen. Daglighallen på Samfundet gjorde overgangen fra “fotballpub” til “kvalitetsølsted” en gang etter at jeg var ferdig med studiene, og det neste naturlige skrittet da var å brygge eget øl. Som sagt, så gjort, og nå serverer de både eget øl og andres, i trivelige omgivelser (gitt at det ikke er fotballkamp). Enkelte ølbloggere har sågar plassert Daglighallen på “topp 10″ av norske ølbarer.

Det aller siste skuddet på stammen befinner seg i Fjordgdata, og Brygghus 9 spiller på ressursser fra flere steder. Eierene er de samme som driver Bakke Brygg, og de har også fått med seg bryggere derfra. For å bemanne baren har de fått med seg en flere burde kjenne igjen fra Den Gode Nabo, og for å tilby noe annet enn eget øl spiller de på varelageret til Beer Enthusiast. Brygghus 9 har en resturant i overetasjen, der de satser på skikkelig mat, samt en bar i kjelleren, med nevnte trivelige herremann.

Strengt tatt er vel både Daglighallen og Brygghus 9 å regne som ølbarer like mye som bryggeripuber, men all den tid de faktisk har et bryggeri hanvner de i den kategorien. Det betur ikke at de ikke hører med på en allerede rikfoldig liste over gode ølpuber i byen.

Den Gode Nabo kan jeg ikke finnes upartisk i min beskrivelse av, stamgjest på tiende året som jeg er. Dog, en artig brygge på Bakklandet, med lekter på Nidelva om sommeren, generelt flinke folk bak baren og et godt utvalg er dette et sikkerstikk. Kan til tider være mye studenter som bråker eller turister som skaper kø, men når øl-utvalget er godt er naboen et nydelig sted.

Skulle du gå lei av naboen kan du labbe 100 meter borti gata og sette deg på Antikvariatet, men sørg for å kom deg innerst i bokbaren. Stedet har holdt på siden 2011, og har ikke verdens største utvalg, men det de har er som regel bra. 3-4 10 tappekraner og en 30-40 ca 70 øl på flaske. Flinke folk bak baren, men ofte mye kulturelle arrangementer, som noen ganger kan være en god ting, andre ganger ikke.

Diskoteket er et artig paradoks i Trondheims øl-scene. Navnet hinter ikke akkurat til et fantastisk ølsted, men med 10 tappekraner, og byens beste surøl-kjeller kan navnet bedra. Dog, stedet heter ikke Diskoteket for ingenting, så etter 21-22 er det ikke stedet for å nyte ølet ditt i ro og mak. Dog, ta en tidlig tur innom, og du vil ikke bli skuffet.

Sot er egentlig en hamburgersjappe på Solsiden (og den observante leser vil huske at det var der jeg satt da jeg fikk inspirasjonen til å skrive dette), men de har også et overraskende godt ølutvalg, og det er ikke noe i veien for å sette seg ned for en øl eller to. Fokus er på amerikansk øl, og de har endel godbiter andre steder i byen ikke har.

Bari har også matservering, og mye fokus på vin, men sist jeg var der hadde de også et decent ølskap, så det kan absolutt være verdt å ta seg en tur hit.

I tillegg har jeg hørt mye bra om steder som Bar Moskus, Ramp og Ila Braiinstasjon, uten at jeg har vært der selv.

Edit: Observante lesere har påpekt at Cafe Løkka også har et “over snittet utvalg øl”, og dermed er det bare rett og rimlig at den nevnes her. Jeg har ikke selv vært der på en stund, og det viser vel bare at utvalget av steder med godt utvalg i byen begynner å bli bra ;)

Flere av stedene nevnt over har også matservering, men det er ikke typen sted med hvit duk og servitører ved bordene (med unntak av resturanten til Brygghus 9), men det finnes også resturanter i Trondheim som kan tilby noe annet enn fransk og italiensk druesaft til maten ;)

To Rom og Kjøkken er vel stjerneeksempelet her. En virkelig gourmetresturant (som jeg ikke ofte frekventerer), som på strak arm setter opp en ølmeny til maten din om du foretrekker det over vin. Utvalget er godt, men lite (etter hva jeg husker), men fokus er øl til mat.

En annen resturant er Ågot på torget, en fiskeresturant med bånd til Austmann via styremeldemmer. På Ågot finner du skikkelig god sjømat, kombinert med et godt utvalg av lokalt og norsk kvalitetsøl. Vel verdt et besøk!

Ølimportøren Beer Enthusiast har, etter at Austmann så dagens lys, etablert seg med en representant i Trondheim. Det betyr at steder som “BrukBlæst” (eller hva de nå heter) og andre, ganske standard utesteder, kan slumpe til å ha noen annet enn Brooklyn Lager å tilby den som har lyst på noe annet enn Dahls.

Å ha en øldistributør i byen betyr også at det titt og ofte blir annonsert diverse øl-happenings, mer om det under.

Trondheim fikk “halvspesialpol”Valentinlyst på nyåret, noe som betyr at vi endelig har fått et sted å få tak i det litt særere ølet på polet uten å dra til Oslo eller Bergen. På tide! Jeg vet ikke helt hvordan det står til med “de facto” ølpolet i Trondheim på City Syd, men de var jo før kjent for fantastisk ølutvalg og service. Polet på Bankkvartalet er heller ikke å forakte.

Skal du ha butikkstyrke-øl er det vel verdt å ta en tur ut til Lade og Meny-butikken der. Her tar de inn mye godt øl, inkludert lokalt øl fra To Tårn, Klostergården og Inderøya.

Som sagt gir det å ha en øldistributør i byen muligheter for øl-happenings (eller snik-reklame), men det finnes en rekke andre arenaer også. En stabil traver er Det Gode Øls Klubb, som til stadighet arrangerer diverse øl-arrangementer, enten i lukkede settinger eller på en bar. På toppen av dette arrangerer en del av stedene egne øl-events, samt at både og Ølakademiet er i ferd med å etablere seg i byen etter hva jeg erfarer.

Rosinen i pølsa er vel uansett Bryggerifestivalen i Trondheim. Denne er blitt arrangert to år på rad i forbindelse med Trøndersk Matfestival, og blir bare bedre og bedre. Her stiller det som kan krype og gå av trønderske ølentusiaster opp som frivillige, og når man klarer å samle en solid gjeng lokale og norske bryggerier midt på Trondheim Torg på sommeren er det til å bli glad av!

Som om ikke det var nok arrangeres det som sagt et årlig hjemmebryggemesterskap i regi av Det Gode Øls Klubb, samt en juleøl-konkurranse på Tautra i sammarbeid med Klostergården.

Så, som sagt er det mye å glede seg over som øl-interessert i Trondheim for tiden. Det artigste er dog at de forskjellige tilbudene er relativt ulike, de fleste barene har ikke identisk utvalg og det er generelt mye flinke folk bak gjæringskar, barer og disker rundt omkring i byen.

På toppen av det hele er Trondheim såpass liten at man fort blir kjent med en rekke hyggelige folk via diverse arrangementer, så man klarer nesten aldri å stikke ut for en øl eller tre uten å møte på kjentfolk. Det er jo absolutt en hyggelig ting!


Foss4g 2014: The good, the bad and the beers

After the closing-party last night I am in a post-foss4g-mood. That is, I’m hung over and over-stimulated at the same time. So this should be a perfect time to reflect on the conference. TLDR: It was great, going to foss4g feels like coming home!

So, we (that is, Alexander and me) arrived in Portland by plane from Norway last saturday, and found our “condo” rented through AirBnB. Note to self: rent a place, skip the hotels, much better! The first days we spent drinking beers, shopping and enjoying the city. Tuesday was JsGeo-day: that is a whole day filled with two things I really enjoy: Geographic data and Javascript. Several good talks, interesting remarks and a real sense of belonging.

What is actually quite cool about an event such as JsGeo is that in my day-to-day life I share the interest with about 5-6 people, but all of a sudden I am in a room with about 100 people that are really into the same stuff. Also, seeing and hearing authors of frameworks I use daily is quite something. So: JsGeo was absolutely worth it, including the after-conference JsGeoBeers at Rogue Halls. Another interesting observation is that projections are regarded as so hard, guess that shows that more and more of the developers working with geo has no formal background in the field, and that the widespread use of web mercator have made people “lazy”?

Wednesday was the start of the actual Foss4g-conference, and a bit tired we found our way to the gigantic Oregon Convention Centre, and missed the introductory talks. What we did not miss was the opening keynote by Mike Bostock, known for the d3-libary. While I personally never have managed to wrap my head around d3 I really think Bostock hit a note in the audience. I’m not sure if it was the really great projections-work or his thoughts on tool-making or the combination that caught on, but his keynote was referenced frequently by other speakers throughout the conference.

One of my main takeaways from the overall conference vibe is that foss4g is turning more into a geo-tech conference than a strictly open source geo conference, but that might be because all the interesting stuff happens in opensource? Another observation is that while we still have the stable, cross-company developed products such as PostGIS, OpenLayers, Mapserver and GeoServer there are some new players on the field that are more in the services for pay, code for free-area. Wether this is a good thing or not can of course be debated, but as long as this results in great, open source code for all to use one can’t really complain.

For technology I really think JavaScript got lots of attention this year, as well as vector tiles and web stuff in general. Also nice to see so many talks on cartography and the related topic of design. These observations may also be explained by the fact that they are things that interest me, so I naturally gravitated towards these talks. While on the topic of talks, I’ve given up counting how many times I had to think long and hard about what track to choose, with 8 tracks in paralell and so many promising talks things do get hard. I really look forward to the videos beeing uploaded, there are lots of things to catch up on.

I’m not really going to go through all the talks I saw, but I have to mention some that really impressed me. I’ve started to realize that delivering a great talk is really hard, 25 minutes is not a lot of time, so limiting scope is important. Knowing your audience is also importand, although this is really hard. Nevertheless, the majority of the talks I attended where good, focused and thought me something. While it may seem unfair to mention only some of the talks I really think some deserves a special mention:

Fiona and Rasterio: Data Access for Python Programmers and Future Python Programmers by Sean Gillies was the first talk I saw after the opening keynote and this really struck a chord with me. Seans intent of doing GIS the pythonic way really reflects how I think code should be written.

TileMill and the Tower of Prince Henry, Reversed by Eric Theise was a talk I chose because it sounded a bit strange, and by God it was. The strangest talk I’ve seen, but in a good way. I can’t really describe this talk, neither the concept, but suffice to say he started out referencingart films from the seventies and ended up proposing a rather cool idea of “hearding” the user through a web map, limiting choice and the need for large tile sets. Really hope that this idea gets somewhere, I’m tempted to try to implement some of his ideas in OpenLayers 3!

“Sliding” datasets together for more automated map tracing by Paul Mach from Strava was excellent in that it had a limited focus on a really great idea implemented in a really impressive way. OSMers should really look at this guys work, there is seroius potential for saving time here. The main idea is fitting (or sliding) existing geometries in order to “merge” or correct them.

Cartography from code…? by Barend Köbben started off the last day of the conference for me, and what impressed me was the “code as a tool”-mindset of a die-hard cartographer. I really think this is needed, cartography hasn’t really taken the front-seat in web mapping, but I think cartography will be even more important in the future.

projections in web browsers are terrible and you should be ashamed of yourself Calvin Metcalf was by far the funniest talk of the conference, continuing the underlying theme of “projections are hard” that started at JsGeo, Calvins bold, fun and “no-filter” way of presenting made me laugh hard several times, while also conveying an important message that seems to me to be even more important in the states, where every state has it’s own “projection”. Use WGS84 geographic coordinates for data exchange and web mercator unless there are valid reasons not to was my main takeaway.

While these talks are the ones that really impressed me there was, as I said, really an abundance of great talks. One thing I did notice was that several talks was a bit america-centered, assuming everyone has the same background as americans when it comes to data formats, ways of doing things and the like, but since we are in USA this is maybe rather natural?

So, the “best” have been covered in great detail, what about the bad? Well, I do not really have that much to say when it comes to “bad”, I feel that last year maybe was better at getting a social context, with a smaller venue, more joint sessions and people mostly living on campus. Also, the amount of entertainment was considerably less this year, I really missed something like the festival of the spoken nerd from last year. Apart from that I don’t think there was anything bad to write home about.

And the beer: 10 excellent breweries and bars visited, 50 different beers tasted (in smaller or larger quantities): Portland really is beer geek heaven! With Foss4g in town is really was like beeing in paradise for me for a week!

Debunking map myth #8: Scale numbers works on a screen

So, I’m obviously not going to debunk my map myths in the order they are stated, but in the order I’ve defined as “what Atle feels like writing about at a given moment”.

That brings us to myth 8, which I guess is more a myth among people buying web map solutions (and usually with a GIS-background). But then again, there are apparent solution to this problem, and there are web maps that seems to have solved it, so I guess there are programmers that believe that this is possible as well. Hence: a myth about maps (and web maps to be specific) worth writing a couple of words about.

But first, let us properly define what this myth is about: Scale (or scale numbers). To quote Wikipedia on “Scale”:

The scale of a map is the ratio of a distance on the map to the corresponding distance on the ground.

Or, as I first heard the concept of scale described when I got into the (weird) sport of Orienteering. A map scale of 1: 50.000 means that 1 cm on your printed map equals 50.000 cm (or 500 meters) in the “real world”. What implications does this have? The first, and most important one is that there is a defined relationship between the real world and the map. In other words: you can bring out your ruler, measure a distance on the map (say 10 cm), check the map scale (say 1:50.000) and then figure out that you still have 5000 meters (or 5 km) left to walk before you can rest for the day.

This relationship between the map and the real world is ingrained with people that work with maps, and naturally they expect that this relationship holds for maps on a computer screen as well. My statement is that this is in fact a myth and a falsehood. And, it seems like the rest of the world agrees, when did you last see a scale printed on a web map? I had to dig a bit and found the previous version of the map client from the Norwegian Mapping Authority as an example.


Look at the screenshot above. (“Målestokk” is scale in Norwegian). If we apply the concept of scale we know from printed maps the following principle could be used:

  • Take out your ruler
  • Measure a distance on the screen (say the distance Oslo-Trondheim, on my screen this is 5cm)
  • Note the scale (1:3.838.112)
  • Compute the distance using the method above
  • This gives a distance Trondheim – Oslo of approx 192 km
  • The measure-tool on the pages says the distance is approx 380 km

So, if we trust the measure-tool there is clearly something wrong with the scale on my screen. Go ahead and try the same on your screen, and I will almost guarantee that you won’t get the same result as me. Why? Because pixels does not map to actual, physical, length. Several factors come into play, most significant is screen resolution. Mapping libraries such as OpenLayers assumes a DPI of 72, because this was determined to be a standard in some day. Later recommendations is to use 96, but you still won’t match every users screen resolution. Think of mobile screens and retina screens for example.

Thus: the notion that map scale works on a screen in the same way as on a printed map is flawed. So, what to do? One thing that will work is to display a scale-bar (which you can see on the screenshot above). This works, because the relationship is the same, so if I measure how may centimeters the 100 km bar on the screenshot is on my screen (about 1.3 cm) I can get the scale: 1: 7692307.7. This translates to a distance Oslo – Trondheim of about 384.615 km, which is (given all the error sources) in the ballpark of a correct answer.

So, skip fixed scale numbers, and use a scale bar. Even simpler, do not talk about scale at all, but operate with zoom levels such as “country”, “city”, and “street”. In this way you give no impression that your web map has a scale in the same way as a paper map.

So, with these calculations I think I’ve debunked this myth. I’m aware that I’m a bit hazy on the cm – pixel – dpi – relationship, but that’s intended. I’m no expert on these things, but I do hope that some knowledgeable reader can fill in some gaps for me?