86 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			86 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 
								 | 
							
								/*
							 | 
						||
| 
								 | 
							
								 * This Source Code Form is subject to the terms of the Mozilla Public
							 | 
						||
| 
								 | 
							
								 * License, v. 2.0. If a copy of the MPL was not distributed with this
							 | 
						||
| 
								 | 
							
								 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								function maplibreMap() {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    var theme = "liberty";
							 | 
						||
| 
								 | 
							
								    if ($("#app").hasClass("theme-dark")) {
							 | 
						||
| 
								 | 
							
								        theme = "libertydark";
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    $("#mapbox").css("background-color", SETTINGS.maptileurls[theme].bgcolor);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    var map = new mapboxgl.Map({
							 | 
						||
| 
								 | 
							
								        container: 'mapbox',
							 | 
						||
| 
								 | 
							
								        style: SETTINGS.maptileurls[theme].json,
							 | 
						||
| 
								 | 
							
								        //attributionControl: false,
							 | 
						||
| 
								 | 
							
								        interactive: false,
							 | 
						||
| 
								 | 
							
								        pitch: 0,
							 | 
						||
| 
								 | 
							
								        zoom: 1,
							 | 
						||
| 
								 | 
							
								        maxZoom: 14,
							 | 
						||
| 
								 | 
							
								        center: [-97, 38]
							 | 
						||
| 
								 | 
							
								    });
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    map.mapEasing = function (t) {
							 | 
						||
| 
								 | 
							
								        return t * (2 - t);
							 | 
						||
| 
								 | 
							
								    };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    map.setMapHeading = function (heading) {
							 | 
						||
| 
								 | 
							
								        if (typeof heading == 'number') {
							 | 
						||
| 
								 | 
							
								            map.easeTo({
							 | 
						||
| 
								 | 
							
								                bearing: heading,
							 | 
						||
| 
								 | 
							
								                easing: map.mapEasing
							 | 
						||
| 
								 | 
							
								            });
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    map.setMapLocation = function (latitude, longitude) {
							 | 
						||
| 
								 | 
							
								        map.easeTo({
							 | 
						||
| 
								 | 
							
								            center: [
							 | 
						||
| 
								 | 
							
								                longitude,
							 | 
						||
| 
								 | 
							
								                latitude
							 | 
						||
| 
								 | 
							
								            ]
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								    };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    map.animateMapIn = function (latitude, longitude, zoom, heading) {
							 | 
						||
| 
								 | 
							
								        if (typeof zoom == 'undefined') {
							 | 
						||
| 
								 | 
							
								            zoom = 10;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        if (typeof heading == 'undefined') {
							 | 
						||
| 
								 | 
							
								            heading = 0;
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        map.flyTo({
							 | 
						||
| 
								 | 
							
								            center: [
							 | 
						||
| 
								 | 
							
								                longitude,
							 | 
						||
| 
								 | 
							
								                latitude
							 | 
						||
| 
								 | 
							
								            ],
							 | 
						||
| 
								 | 
							
								            speed: 1,
							 | 
						||
| 
								 | 
							
								            zoom: zoom,
							 | 
						||
| 
								 | 
							
								            heading: heading,
							 | 
						||
| 
								 | 
							
								            pitch: 0
							 | 
						||
| 
								 | 
							
								        });
							 | 
						||
| 
								 | 
							
								    };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    map.addMarker = function (latitude, longitude) {
							 | 
						||
| 
								 | 
							
								        var el = document.createElement("div");
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        el.className = "package-marker";
							 | 
						||
| 
								 | 
							
								        new mapboxgl.Marker(el).setLngLat([longitude, latitude]).addTo(map);
							 | 
						||
| 
								 | 
							
								    };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    map.removeMarkers = function () {
							 | 
						||
| 
								 | 
							
								        var oldmarkers = document.getElementsByClassName("map-marker");
							 | 
						||
| 
								 | 
							
								        if (oldmarkers.length > 0) {
							 | 
						||
| 
								 | 
							
								            markerparent = oldmarkers[0].parentNode;
							 | 
						||
| 
								 | 
							
								            while (oldmarkers.length > 0) {
							 | 
						||
| 
								 | 
							
								                markerparent.removeChild(oldmarkers[0]);
							 | 
						||
| 
								 | 
							
								            }
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return map;
							 | 
						||
| 
								 | 
							
								}
							 |