Creating Custom OpenStreetMap Tiles for My Own Tile Server (2024)

Once a year, I need to create a printable map with markers.

The map is for Sindorf trödelt, a website which I built for an annual garage sale in my hometown.

Users can register with their addresses, and I use Google Maps to show them on this map on the website.

The map is not active the whole year, so here’s a picture:

Creating Custom OpenStreetMap Tiles for My Own Tile Server (1)

The organizers of the garage sale also need to print flyers and posters with this map, but using the exact same Google Map for this doesn’t make sense, since there’s a limit how many copies you are allowed to print with the free version of Google Maps.

Everybody involved in the garage sale is doing this in their spare time (me included, and I’m sponsoring hosting as well) so there’s simply no budget to pay for a Google Maps license which would allow to print more copies.

First solution

So I needed an alternative way to create a map for printing, and I managed to get something to work with OpenLayers and OpenStreetMap:

I based my code on some example code for a OpenLayers map with markers which I found online (I don’t have the link anymore) - it works well, here’s a simplified JSFiddle (right-click on the map and save as image)

But after the first flyers were printed, one problem came up: the font size for the street names was too small, the names weren’t readable anymore.

That was two years ago. Last year I didn’t have time to find a better solution, so they just printed bigger flyers :-)

This year, I finally had time to investigate this.

Running my own tile server

Sounds impressive, doesn’t it? When you search for things like “how to increase font size in [random web mapping solution]”, you quickly find that:

  • most solutions use pre-made tiles by 3rd party providers, which are provided as images
  • to change the appearance of those tiles, you either need to change the provider or run your own tile server

Running my own tile server sounded scary, so at first I didn’t investigate this, but focused on creating the whole image with different tools.

In the end, I found Maperitive, which has its own scripting language, so it’s possible to write a text file with commands and execute it in Maperitive to create a map image from scratch.

While playing around with this, I found example code which saves the map as tiles (=image files) and uploads them via FTP.

That was my “aha” moment: a tile server is not a complex piece of software, but just a regular web server which serves pre-generated image files over HTTP.

So I just needed some try-and-error, until the tiles looked the way I wanted them to.

Here are the steps to do it with Maperitive (I used v2.4.3.0):

  1. Creating my own ruleset

    A ruleset is a file with Maperitive rendering rules. The look of the map can be changed in Maperitive (colors, details, text appearance), just by providing a different ruleset.

    I needed something “simple” (without many details which clutter the view), so I looked at all the rulesets and picked the Google Maps ruleset. This is just a file in the Rules subfolder in the Maperitive application folder.

    I want bigger fonts for the streets…so I copied that file, searched for font-size and increased some values for the street types that sounded right (some experimentation necessary). Here’s a gist with the changes.

  2. Getting OpenStreetMap data as XML

    Quote from Maperitive’s Ten Minutes Intro ⇒ Loading Map Data:

    Using the browser, go to OSM map, choose a smallish area (let’s say the size of a few city blocks) and then click on the Export tab. Select the OpenStreetMap XML Data radio button value, click on the Export button and you’ll receive a file called map.osm from the server.

  3. Writing a Maperitive script

    This code goes into a text file with .mscript extension:

    // this is the ruleset from step 1use-ruleset location=sindorftiles.mrules// this is the OpenStreetMap XML file from step 2load-source sindorf.osm// move and zoom the map, so that the whole town is visible on the screenmove-pos x=6.674573 y=50.904049 zoom=16// now we could export the map to a file:// export-bitmap file=map.png height=2000 width=1600// ...but we want to generate tiles instead:generate-tiles minzoom=16 maxzoom=16 subpixel=3 bounds=6.6554,50.8898,6.6924,50.9191// upload via FTP:ftp-upload host=tiles.sindorf-troedelt.de user=USERNAME pwd=PASSWORD remote-dir=/

    A few notes about the generate-tiles command:

    • minzoom and maxzoom should match the zoom level from the move-pos command
    • generating tiles for one single zoom level is enough in this case - we just need this view of the map for printing, no more zooming necessary. The more zoom levels, the more tiles are generated!

    For me, the FTP upload isn’t really necessary because generating the tiles is a one-time thing. Uploading the tiles manually would be acceptable as well…but still, it’s nice that Maperitive can do it.

  4. Opening Maperitive and executing the script:

    This is just a two-liner, calling Maperitive and passing the script from step 3:

    rd /s /q TilesC:\Maperitive\Maperitive.exe "%~dp0\sindorftiles.mscript" -exitafter

    I put this into a batch file, and copied all the files mentioned before to the same directory where the batch file is.

That’s it - running this will open Maperitive, which will generate the tiles, save them into the \Tiles subfolder and upload them to the web server.

Here is an example - on the left side an original OpenStreetMap tile, on the right side the same tile generated with Maperitive and my custom ruleset:

Creating Custom OpenStreetMap Tiles for My Own Tile Server (2)

Loading my own tiles with OpenLayers

Back to the JSFiddle from the beginning:

At the bottom of the <script> block, there’s this:

JavaScript

var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ,vectorLayer1 ], view: new ol.View({ center: ol.proj.fromLonLat([6.674573,50.904049]), zoom: 16 })});

To change this in order to use my custom tiles, I just needed to use the XYZ source instead of the OpenStreetMap source which I’m using in the JSFiddle.

So it’s simply changing this line:

JavaScript

source: new ol.source.OSM()

…into this:

JavaScript

source: new ol.source.XYZ({url: 'https://tiles.sindorf-troedelt.de/{z}/{x}/{y}.png'})

/{z}/{x}/{y}.png matches the folder structure and file names generated by Maperitive’s generate-tiles command.

In-house developer (C#/T-SQL/VBA) and DBA at weinor, a mid-sized manufacturing company in Cologne.

Creating Custom OpenStreetMap Tiles for My Own Tile Server (2024)
Top Articles
Mermonkey (BTD6)/Strategies
Book A Bach Taupo
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Espn Transfer Portal Basketball
Pollen Levels Richmond
11 Best Sites Like The Chive For Funny Pictures and Memes
Things to do in Wichita Falls on weekends 12-15 September
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
R/Skinwalker
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Cubilabras
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Juego Friv Poki
Dirt Devil Ud70181 Parts Diagram
Truist Bank Open Saturday
Water Leaks in Your Car When It Rains? Common Causes & Fixes
What’s Closing at Disney World? A Complete Guide
New from Simply So Good - Cherry Apricot Slab Pie
Drys Pharmacy
modelo julia - PLAYBOARD
Poker News Views Gossip
Abby's Caribbean Cafe
Joanna Gaines Reveals Who Bought the 'Fixer Upper' Lake House and Her Favorite Features of the Milestone Project
Tri-State Dog Racing Results
Navy Qrs Supervisor Answers
Trade Chart Dave Richard
Lincoln Financial Field Section 110
Free Stuff Craigslist Roanoke Va
Wi Dept Of Regulation & Licensing
Pick N Pull Near Me [Locator Map + Guide + FAQ]
Crystal Westbrooks Nipple
Ice Hockey Dboard
Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 5733

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.