Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

header_add_map_providers()

Parameters

This function accepts no parameters.

Location

include/map_functions.php lines 546 to 695

Definition

 
function header_add_map_providers()
    {
    global 
$geo_leaflet_sources$baseurl$geo_tile_caching;
    
?>
    <script>
    // Copied from leaflet-providers.js
    (function (root, factory) {
        if (typeof define === 'function' && define.amd) {
            // AMD. Register as an anonymous module.
            define(['leaflet'], factory);
        } else if (typeof modules === 'object' && module.exports) {
            // define a Common JS module that relies on 'leaflet'
            module.exports = factory(require('leaflet'));
        } else {
            // Assume Leaflet is loaded into global object L already
            factory(L);
        }
    }(this, function (L) {
        'use strict';

        L.TileLayer.Provider = L.TileLayer.extend({
            initialize: function (arg, options) {
                var providers = L.TileLayer.Provider.providers;

                var parts = arg.split('.');

                var providerName = parts[0];
                var variantName = parts[1];

                if (!providers[providerName]) {
                    throw 'No such provider (' + providerName + ')';
                }

                var provider = {
                    url: providers[providerName].url,
                    options: providers[providerName].options
                };

                // overwrite values in provider from variant.
                if (variantName && 'variants' in providers[providerName]) {
                    if (!(variantName in providers[providerName].variants)) {
                        throw 'No such variant of ' + providerName + ' (' + variantName + ')';
                    }
                    var variant = providers[providerName].variants[variantName];
                    var variantOptions;
                    if (typeof variant === 'string') {
                        variantOptions = {
                            variant: variant
                        };
                    } else {
                        variantOptions = variant.options;
                    }
                    provider = {
                        url: variant.url || provider.url,
                        options: L.Util.extend({}, provider.options, variantOptions)
                    };
                }

                // replace attribution placeholders with their values from toplevel provider attribution,
                // recursively
                var attributionReplacer = function (attr) {
                    if (attr.indexOf('{attribution.') === -1) {
                        return attr;
                    }
                    return attr.replace(/\{attribution.(\w*)\}/g,
                        function (match, attributionName) {
                            return attributionReplacer(providers[attributionName].options.attribution);
                        }
                    );
                };
                provider.options.attribution = attributionReplacer(provider.options.attribution);

                // Compute final options combining provider options with any user overrides
                var layerOpts = L.Util.extend({}, provider.options, options);
                L.TileLayer.prototype.initialize.call(this, provider.url, layerOpts);
            }
        });

        /**
        * Definition of providers.
        * see http://leafletjs.com/reference.html#tilelayer for options in the options map.
        */

        L.TileLayer.Provider.providers = {

           
        
foreach($geo_leaflet_sources as $leaflet_source)
            {
            echo 
htmlspecialchars($leaflet_source["code"])  . ": {\n";
            if(
$geo_tile_caching)
                {
                
$urlparams = array(
                    
"provider"  =>  $leaflet_source["code"],
                    );
                
$sourceurl generateurl($baseurl "/pages/ajax/tiles.php",$urlparams) . "&x={x}&y={y}&z={z}";
                }
            else
                {
                
$sourceurl =  $leaflet_source["url"];                        
                }
            echo 
"        url: '" $sourceurl "',\n";
            echo 
"        options: {\n";
            if(isset(
$leaflet_source["maxZoom"]) && is_int_loose($leaflet_source["maxZoom"]))
                {
                echo 
"        maxZoom: " . (int)$leaflet_source["maxZoom"] . ",\n";
                } 
            if(isset(
$leaflet_source["attribution"]))
                {
                echo 
"        attribution: '" $leaflet_source["attribution"] . "',\n";
                }
            echo 
"    },\n"// End of options
            
echo "        variants: {\n";
            foreach(
$leaflet_source["variants"] as $variant=>&$variantdata)
                {
                echo 
$variant  ": {\n        ";
                if(isset(
$variantdata["url"]))
                    {
                    if(
$geo_tile_caching)
                        {
                        
$urlparams["variant"] = $variant;
                        
$variantdata["url"] = generateurl($baseurl "/pages/ajax/tiles.php",$urlparams) . "&x={x}&y={y}&z={z}";
                        }
                    echo 
"    url: '" $variantdata["url"] . "'\n";
                    }
                echo 
"},\n";
                }    
            echo 
"         },\n"// End of variants
            
echo "},\n"// End of leaflet source
            
}
        
?>
        ResourceSpace: {
            url: ' echo $baseurl?>/pages/ajax/tiles.php?x={x}&y={y}&z={z}',
            options: {
                maxZoom: 3,
                attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
                },
            variants: { OSM: {}}
            }

        };

        L.tileLayer.provider = function (provider, options) {
            return new L.TileLayer.Provider(provider, options);
        };

        return L;
    }));
    </script>
    
    
}

This article was last updated 21st April 2021 19:05 Europe/London time based on the source file dated 29th March 2021 15:05 Europe/London time.