map_functions.php
Table of Contents
Functions
- leaflet_osm_basemaps() : string
- Generates OpenStreetMap basemaps for use in a Leaflet map.
- leaflet_esri_basemaps() : string
- Generates ESRI basemaps for use in a Leaflet map.
- leaflet_stamen_basemaps() : mixed
- leaflet_hydda_basemaps() : string
- Generates Hydda basemaps for use in a Leaflet map.
- leaflet_nasa_basemaps() : string
- Generates NASA basemaps for use in a Leaflet map.
- leaflet_usgs_basemaps() : string
- Generates USGS basemaps for use in a Leaflet map.
- leaflet_thunderforest_basemaps() : string
- Generates Thunderforest basemaps for use in a Leaflet map.
- leaflet_mapbox_basemaps() : mixed
- leaflet_map_zoom() : string
- Generates Mapbox basemaps for use in a Leaflet map.
- leaflet_polygon_parsing() : array<string|int, mixed>
- Parses the resource polygon string to extract latitude and longitude bounds and formats the polygon string.
- leaflet_coordinate_check() : bool
- Validates geolocation coordinates to ensure they are numeric and within acceptable bounds.
- leaflet_markers_legend() : void
- Creates a map color markers legend for Leaflet maps.
- header_add_map_providers() : void
- Adds map providers for Leaflet maps.
- get_geolibraries() : void
- Checks the current page and includes necessary geolocation libraries for Leaflet maps.
- set_geo_map_centerview() : void
- Set bounds for default map view (geo_search.php and geo_edit.php)
- get_geo_maps_scripts() : void
- Outputs the script tag for including additional Leaflet plugins.
Functions
leaflet_osm_basemaps()
Generates OpenStreetMap basemaps for use in a Leaflet map.
leaflet_osm_basemaps() : string
This function defines various tile layers from OpenStreetMap and related providers, setting properties such as caching, retina display support, maximum zoom levels, and attribution for each layer.
Return values
string —JavaScript code that initializes the OSM basemaps for Leaflet.
leaflet_esri_basemaps()
Generates ESRI basemaps for use in a Leaflet map.
leaflet_esri_basemaps() : string
This function defines various tile layers from ESRI, setting properties such as caching, retina display support, maximum zoom levels, and attribution for each layer.
Return values
string —JavaScript code that initializes the ESRI basemaps for Leaflet.
leaflet_stamen_basemaps()
leaflet_stamen_basemaps() : mixed
leaflet_hydda_basemaps()
Generates Hydda basemaps for use in a Leaflet map.
leaflet_hydda_basemaps() : string
Return values
string —JavaScript code that initializes the Hydda basemaps for Leaflet.
leaflet_nasa_basemaps()
Generates NASA basemaps for use in a Leaflet map.
leaflet_nasa_basemaps() : string
Return values
string —JavaScript code that initializes the NASA basemaps for Leaflet.
leaflet_usgs_basemaps()
Generates USGS basemaps for use in a Leaflet map.
leaflet_usgs_basemaps() : string
Return values
string —JavaScript code that initializes the USGS basemaps for Leaflet.
leaflet_thunderforest_basemaps()
Generates Thunderforest basemaps for use in a Leaflet map.
leaflet_thunderforest_basemaps() : string
Return values
string —JavaScript code that initializes the Thunderforest basemaps for Leaflet.
leaflet_mapbox_basemaps()
leaflet_mapbox_basemaps() : mixed
leaflet_map_zoom()
Generates Mapbox basemaps for use in a Leaflet map.
leaflet_map_zoom(mixed $map_zoom) : string
This function initializes a Mapbox tile layer, requiring an API ID and access token. It also allows configuration for caching, retina display support, and attribution.
Parameters
- $map_zoom : mixed
Return values
string —JavaScript code that initializes the Mapbox basemap for Leaflet.
leaflet_polygon_parsing()
Parses the resource polygon string to extract latitude and longitude bounds and formats the polygon string.
leaflet_polygon_parsing(array<string|int, mixed> $fields[, bool $minmax = true ]) : array<string|int, mixed>
Parameters
- $fields : array<string|int, mixed>
-
The resource fields array containing polygon data.
- $minmax : bool = true
-
Flag to determine if minimum and maximum latitude and longitude values should be calculated.
Return values
array<string|int, mixed> —An associative array containing the minimum and maximum latitude and longitude values, as well as the formatted polygon string for Leaflet display.
leaflet_coordinate_check()
Validates geolocation coordinates to ensure they are numeric and within acceptable bounds.
leaflet_coordinate_check(mixed $coordinate, string $type) : bool
Parameters
- $coordinate : mixed
-
The coordinate value to check.
- $type : string
-
The type of coordinate ('latitude' or 'longitude').
Return values
bool —True if the coordinate is valid; otherwise, false.
leaflet_markers_legend()
Creates a map color markers legend for Leaflet maps.
leaflet_markers_legend() : void
This function generates HTML for a legend that displays markers with colors corresponding to resource types or custom metadata field values. If a custom metadata field is defined, the legend reflects that; otherwise, it shows the default resource types and their associated colors.
Return values
void —Outputs the HTML for the legend.
header_add_map_providers()
Adds map providers for Leaflet maps.
header_add_map_providers() : void
This function generates a JavaScript snippet that defines various tile layer providers for use in Leaflet maps.
It supports OpenStreetMap and ESRI basemaps, as well as custom providers defined in the global variable $geo_leaflet_sources.
The function also includes options for caching tile layers and handling different zoom levels and attribution.
Return values
void —Outputs the HTML and JavaScript for adding map providers to Leaflet.
get_geolibraries()
Checks the current page and includes necessary geolocation libraries for Leaflet maps.
get_geolibraries() : void
This function loads the Leaflet Control Geocoder plugin and checks if the current page requires geolocation capabilities. It also handles polyfills for browser compatibility, specifically for Internet Explorer and Edge.
Return values
void —Outputs the HTML and JavaScript for including geolocation libraries if applicable.
set_geo_map_centerview()
Set bounds for default map view (geo_search.php and geo_edit.php)
set_geo_map_centerview() : void
get_geo_maps_scripts()
Outputs the script tag for including additional Leaflet plugins.
get_geo_maps_scripts() : void
This function loads the necessary JavaScript for the Leaflet Marker Cluster library, which helps in managing large sets of markers on Leaflet maps by clustering them for better visualization.
Return values
void —Outputs the script tag for the Marker Cluster plugin.