Skip to content

5 Scale the objects

Oliver Heilig edited this page Apr 21, 2024 · 4 revisions

The WgsToTile method gives us coordinates with pixel reference. The DPI number for the tiling scheme is 96, so you can calculate the actual size on the display. Sometimes it is useful to increase the size of object depending on the map zoom. To achieve this, you can take the current map scale (given by the level) into account. One simple method is to explicitly set a size for a range of Levels, for expample we can set the width of our Latitude line depending on the Level.

int strokeSize = (z > 15)? 4 : (z > 10)? 3 : (z > 5)? 2 : 1;   

This sets the size of the stroke in Pixels to 3 for zoom Levels between 11 and 15.

a more flexible way is the "power law scaling": For a base size and a adaptive factor, the objects can be scaled in a non-linear way. If the adaptive factor is 0.0, the size is constant (=pixel). If the adaptive factor is 1.0 the size is linear (=meters at equator). If it is something in between, the size grows non-linearly.

// calculate map scale
var mapSize = 256 * Math.Pow(2, z); // size of the map in pixel
double earthCircumfence = 2.0 * Math.PI * 6378137.0; // circumfence of earth
var scale = mapSize / earthCircumfence; // pixel per mercator unit

// Calculate the symbol sizes with 3 different scaling modes
// 1 - constant scaling - radius is always 16 pixels
int sz1 = (int)(16 * Math.Pow(scale, 0.0));

// 2 - linear scaling - the symbol has a size of 10000 merctor units (=meter at equator, equals sz = 10000 * scale)
int sz2 = (int)(10000 * Math.Pow(scale, 1.0));

// 3 - logarithmic scaling - the size is adapted with a base size (64) and a scaling factor (0.25)
int sz3 = (int)(64 * Math.Pow(scale, 0.25));

The result: https://spatialtutorial.azurewebsites.net/05-SymbolScaling.html

Clone this wiki locally