Document toolboxDocument toolbox

Maps

There are several places in Microbizz where maps are displayed, with different information overlaid on the maps.

We use LeafletJS for the maps.

See also the section about the GIS data format and the Map class.

Data layers

Different data layers may be defined, to get data from tile servers or WMS servers.

This is used by Gentofte Fjernvarme, amongst others.

GPS traces

The Equipment module can display GPS traces on the map for an equipment. The is done by fetching the traces from gps.microbizz.dk.

Traces and other info from gps.microbizz.dk can be read using the various PHP scripts in obj/Gps/php/tracker/. Eg. to read the last location of a tracker, use:

var args = { imei: '123456789012345', maxage: 30 /*minutes*/ }; $.post('/obj/Gps/php/tracker.php', args, function(reply) { if (reply.status == 0) return; console.log(reply.loc.lat+','+reply.loc.lon); }, 'json');

POI

Parts of Microbizz display various POI (Points Of Interest) on the map, f.ex. the on-location map displays markers indicating the location companies, tasks and equipment.

There is currently no standard way for handling this.

Displaying a map

To display a map, make sure to include

'mapload' => 'leaflet'

in the array passed as 4th argument to head(), and include the script /obj/Map/script/routeviewer.js. Setup the map by calling:

var map = new RouteViewer(mapid, 15, [55.4, 12.6], {width:800, height: 600});

Old style

Call the javascript function leaflet_setup(divid, zoom, center, args) where divid is the ID of a <div>zoom is the initial zoom level (typically 15), center is an array with two values (lat and lon), and args is an object with additional settings. Only divid is required.

leaflet_setup('mymapcontainer', 15, [ 55.4, 12.6 ], {});

Drawing layers

Multiple layers with features (rectangle, circles, places etc) are handled by MapLayerUI.

In PHP you call

$ui = new MapLayerUI($id, $modcode, $sysref, $editable); $ui->display();

$id is an ID used as a prefix for all the various <div> and buttons etc used in the UI; typically we use the string maplayers.

$modcode and $sysref specifies which object you are dealing with.

$editable is a bool which indicates if the layers/features should be editable.

In Javascript you call

LayerIU() will call leaflet_setup().

To initialize maped.js at the same time, simply pass the maped.js configuration object as the second argument to LayerUI().

Drawing

Drawing features on a map is handled by maped.js.

If you are not using layerui.js then maped.js is initialised using

id is the ID of the map, and cfg is a object with the configuration.

Style

If you want to be able to edit the style of features, then you need to provide a dialog for editing the style.

In PHP the following will generate the dialog:

In Javascript the following will initialise the dialog:

Also include the following in the maped.js configuration object, so that maped.js will know how to invoke the style editor:

Example of configuration

Most of the configuration object are optional; typically you will only need a list of enabled tools: