Help enabling Leaflet, with MapBox, Stadia or Similar...

205 views
Skip to first unread message

Parks and Wildlife

unread,
Aug 5, 2021, 3:14:21 AM8/5/21
to ResourceSpace
Hi All,
I tried to setup configuration of Leaflet Maps, but to no avail. Does anyone have an example bit of code that I could try and add to my config, ideally with MapBox or Stadia, or similar?

My code either breaks, or it won't load the tiles...


TIA...
-Ryan

Mark Leo-Russell

unread,
Aug 5, 2021, 11:56:35 AM8/5/21
to ResourceSpace
Ryan--

What problems are you having with LeafMaps and are you on RS version 9.6? LeafMaps are new in 9.6....older versions used a different mapping library. The documentation on RS's site got me through most of the configuration (https://www.resourcespace.com/knowledge-base/systemadmin/leafletmaps). The biggest problem I ran into with the new mapping piece of 9.6 was understanding the geo coordinates used to display the default map when you do a geographic search. Turns out the lat/long coordinates need to be specified in EPSG:3857 format. This site has a handy converter if you're used to decimal degrees or DDMMSS format: https://epsg.io/transform#s_srs=3857&t_srs=3857.

I'm not sure how MapBox or Stadia would come into RS unless you're trying to using custom map tiles.

Hope that helps.

ML-R

Parks and Wildlife

unread,
Aug 8, 2021, 9:25:27 PM8/8/21
to ResourceSpace
Hiya Mark,
Thanks for the info. Basically, The initial standard map tiles fail to load when I zoom out (give a 404 error)

maps.jpg



When i tried to install Leaflet Maps I just got a Grey box and it didn't load.....
I tried again today, using the EXACT details found here:

It did appear... yay!

Ok, I just need to try and enable a better looking tilemap now....
Message has been deleted

Parks and Wildlife

unread,
Aug 9, 2021, 12:22:09 AM8/9/21
to ResourceSpace

For anyone else, here's my working sample, using Esri Maps




#Leaflet Map settings
#Enable leaflet
$leaflet_maps_enable = true;
# Set initial bounds to Australia, with Zoom of 4
$geolocation_default_bounds="14865065.700277,-2963922.210025,4";

#Set my Source to be Esri Maps
$geo_leaflet_sources[] = array(
            "name"          => "Esri",
            "code"          => "Esri",
            "maxZoom"       => 18,
            "detectRetina"  => true,
            "attribution"   => "Tiles © Esri — Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012",
            "default"       => true,
            "extension"     => "jpeg",
            "variants"      => array(
                "World_Street_Map"        => array(
                    "name"          => "World Street Map",
                ),
                "World_Topo_Map"     => array(
                    "name"          => "World Topo Map",
                    ),
                "World_Imagery" => array(
                    "name"          => "World Imagery",
                ),
                )
            );

# State which map should be default
$map_default = "Esri.World_Street_Map";
# Make the Search map height at 650px high
$mapsearch_height = 650;

Leo-Russell, Mark

unread,
Aug 9, 2021, 12:08:13 PM8/9/21
to resour...@googlegroups.com
With LeafMaps in Resource Space, I didn't use a bounding box. Rather, once I figured out the EPGS:3857 coordinates, I set the center of our map area and then experimented with the zoom value until I had the map extent I wanted (zoom value of 6). For us, that's the State of New Mexico. Our offices are close enough to the state centroid that I used our building coordinates to set the center point.

One of the confusing things I ran into in configuring LeafMaps in RS 9.6 is the config files still have lots of stuff from the previous versions that used OpenLayers for the mapping. Changing many of those options had no effect in 9.6. I stayed with using the default USGS base maps but I can see you'd want something else. See my config.php code below (esp. red section).

One other thing I've run into. Resource Space stores coordinates in two places: the 'resource' table and the 'resource_data' table. The latter is where lat/longs go when entered as a resource's metadata. However, the mapping components use the location in the 'resource' table. You can enter both when you edit the metadata but we're working on an automated query that will copy lat/longs from 'resource_data' to 'resource' as part of the nightly maintenance jobs that run on our RS server (save our folks from having to enter the data twice and avoids coordinate mis-matches between the two DB tables). Also, if you want the heat maps to work, you need to have the 'batch/cron-jobs/014_update_heatmap.php' script run on a regular basis. For us that's another scheduled nightly job.

Our PhotoArchive/Resource Space system went live to the public last week so you should be able to get to it via this URL. Try the Geographic Search to see how I configured our state map. The funky-looking colored splotches are the heat-map indicators of our current New Mexico image library.



Hope that helps.

Mark

Mark Leo-Russell
Database Administrator
New Mexico Bureau of Geology and Mineral Resources
New Mexico Institute of Mining and Technology

=====BEGIN: code segment from config.php=====
    // New settings for leaflet maps
    $leaflet_maps_enable = true;

    // $geo_leaflet_maps_sources: Use the standard tile sources provided by leaflet maps?
    // If this is enabled please refer to /include/map_basemaps to see the available config options that enable specific defined map providers
    $geo_leaflet_maps_sources = true;
    $map_usgstopo = true;
    $map_usgsimagery = true;
    $map_usgsimagerytopo = true;

    // $geo_leaflet_sources = define available tile servers.
    // Configured sources need to follow the default template as below
    $geo_leaflet_sources = array();
    $geo_leaflet_sources[] = array(
        "name"          => "The National Map",
        "code"          => "USGSTNM",
        "url"           => "https://basemap.nationalmap.gov/arcgis/rest/services/USGSTopo/MapServer/tile/{z}/{y}/{x}",
        "maxZoom"       => 8,
        "detectRetina"  => true,
        "attribution"   => "<a href=\"https://www.doi.gov\">U.S. Department of the Interior</a> | <a href=\"https://www.usgs.gov\">U.S. Geological Survey</a>",

        "default"       => true,
        "extension"     => "jpeg",
        "variants"      => array(
            "USTopo"        => array(
                "name"          => "US Topographic",
            ),
            "USImagery"     => array(
                "name"          => "US Imagery",
                "url"           => 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}',
                ),
            "USImageryTopo" => array(
                "name"          => "US Imagery & Topographic",
                "url"           => 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryTopo/MapServer/tile/{z}/{y}/{x}',
            ),
            )
        );

    // Limit number of search results that can be displayed in map view. Set to 0 for no limit
    $search_map_max_results = 5000;
   
    // Use zoom slidebar instead of standard +/- buttons?
    $map_zoomslider = true;

    // Leaflet: Show zoom history navigation bar?
    $map_zoomnavbar = true;

    // Leaflet: Cache map layer tiles in the browser (recommended to reduce tile server load)?
    $map_default_cache = true; # Default basemap?
    $map_layer_cache = true; # All basemaps?

    // Enable retina display tiles (four tiles of half size and a larger zoom level in place of one to utilize higher resolution)?
    $map_retina = false;

    // Leaflet: default basemap to show
    // Set to be '{CODE}.{variant} - matching the definitions from the $geo_leaflet_source code array
    // e.g. "OSM.Mapnik"
    $map_default = 'USGSTNM.USTopo';

    // Open resource when clicking on a search result marker, instead of resource tooltip?
    $marker_resource_preview = true;

    // Leaflet: Custom map marker coloring based on a selected numeric value metadata field, instead of coloring by resource type, enable by setting a metadata field ID and descriptive text value.
    # $marker_metadata_field = 85; # Example is fieldID 85.
    $lang['custom_metadata_markers'] = ''; # Custom metadata field map legend header text.

    // Array of minimum and maximum numeric values for the markers on the map, up to eight marker pairs (min >=, max <=) when using custom marker coloring.  Example below shows a range of years.
    $marker_metadata_array = [
        0 => ['min' => 1935, 'max' => 1939], # Blue marker
        1 => ['min' => 1940, 'max' => 1949], # Red marker
        2 => ['min' => 1950, 'max' => 1959], # Green marker
        3 => ['min' => 1960, 'max' => 1969], # Orange marker
        4 => ['min' => 1970, 'max' => 1979], # Yellow marker
        5 => ['min' => 1980, 'max' => 1989], # Black marker
        6 => ['min' => 1990, 'max' => 1999], # Grey marker
        7 => ['min' => 2000, 'max' => 2010], # Violet marker
        8 => ['min' => 2010, 'max' => 2020]  # Gold marker
    ];

    // Leaflet: Show a KML overlay on the map?
    $map_kml = false;
    $map_kml_file = ''; # Place KML file in ../filestore/system/, example: overlay.kml

    // Resource metadata field integer ID containing polygon footprint location string, blank '' if not used.  String in (latitude, longitude) coordinate pairs separated by a comma: (40.75,-111.51), (40.75,-111.49), (40.73,-111.49), (40.73,-111.51) or using braces [].  String can also contain a fifth pair that closes the polygon and equal to the first pair.
    # $map_polygon_field = 84;

// Option to add a 'heatmap' when performing a geographic search to aid searching
// Heatmap data relies on presence of a file that is generated by a ResourceSpace cron job (scheduled task)
// Please note the following:-
//  - This should be disabled in multi-client environments
//  - Cached location co-ordinates are rounded to one decimal place to improve handling of large numbers of resources
//  - Only resources that are currently in the default search states will be included in the heatmap
//  - This can be enabled per usergroup as a configuration option
$geo_search_heatmap = true;


# 2021-07-13 Added from https://www.resourcespace.com/knowledge-base/systemadmin/leafletmaps
#            Default center and zoom for map ('-10494743.596017,4508852.6025659,4' = USA)
# Center on USA 48
#$geolocation_default_bounds="-10494743.596017,4508852.6025659,4";
###
### NOTE: Resource Space uses EPSG:3857 coordinates [ref: https://epsg.io/transform#s_srs=3857&t_srs=3857]
###
# Center on NMBGMR [Lon/Lat]: -106.90424, 34.06826 => [EPSG:3857] -11900444.30, 4037901.48
$geolocation_default_bounds="-11900444.30,4037901.48,6";


=====END: code segment from config.php=====




On Sun, Aug 8, 2021 at 8:18 PM Parks and Wildlife <digital...@dbca.wa.gov.au> wrote:
... also, just wondering mark, do you have any ideas about the default bounds conversion?
$geolocation_default_bounds="-10494743.596017,4508852.6025659,4";

I need to define just Australia... In Mapbox, i usually add:

var bounds = [
[61.3281695751607,-66.78498350502078], // Southwest coordinates
[218.86447290782468,21.873396117354957]  // Northeast coordinates
];

.. thought I'd chuck it out there in case you may know, cheers mate...

On Thursday, August 5, 2021 at 11:56:35 PM UTC+8 mark...@nmt.edu wrote:

--
ResourceSpace: Open Source Digital Asset Management
http://www.resourcespace.com
---
You received this message because you are subscribed to a topic in the Google Groups "ResourceSpace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/resourcespace/3r_I-axBYms/unsubscribe.
To unsubscribe from this group and all its topics, send an email to resourcespac...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/resourcespace/055580fd-63d3-4ad5-ab49-d1b92bbcda4bn%40googlegroups.com.

Parks and Wildlife

unread,
Aug 11, 2021, 7:30:59 PM8/11/21
to ResourceSpace
Hey Mark, that's above and beyond help, thanks so much, i'll give that config a go!
Reply all
Reply to author
Forward
0 new messages