"use strict"; var g_map = null; var g_sublayer; var g_polylines = []; var g_first_circle = null; var g_line_width = 1.7; var g_opacity = 0.7; var g_gps_started = false; var g_gps_first_message = false; $(document).ready(function() { $('#idtouredit').click(function(e) { track_edit_show_menu(e); e.preventDefault(); } ); $("#idgps").click(function(event) { event.preventDefault(); //showsidebar(0); start_gps_position(); }); $('input[type="radio"],input[type="checkbox"]').focus( function() { $(this).parent().addClass('active'); }); $('input[type="radio"],input[type="checkbox"]').focusout( function() { $(this).parent().removeClass('active'); }); // init_leaflet(); // do it on page }); var init_leaflet = function(geo_bounds,haspaddingleft,showoverlayimage,showzoomcontrol) { if (typeof showzoomcontrol === 'undefined') { showzoomcontrol = true; } if (typeof geo_bounds !== 'undefined' && 'point' !== geo_bounds) { var corner1 = L.latLng(geo_bounds[0][0], geo_bounds[0][1]); var corner2 = L.latLng(geo_bounds[1][0], geo_bounds[1][1]); var bounds = L.latLngBounds(corner1, corner2); //console.log(geo_bounds); } var ishttps = 1; var http_https = (ishttps)?'https://':'http://'; var mapboxtiles = L.tileLayer(http_https+'api.mapbox.com/styles/v1/xmnr-net/cioj1nv53002xcumbt65lzfsu/tiles/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoieG1uci1uZXQiLCJhIjoiX1YyVm43WSJ9.db6f-l9SLulOORMs12Ez_w', { attribution: 'Map data © Mapbox contributors, CC-BY-SA', tileSize: 512, zoomOffset: -1 }); var cycletiles = L.tileLayer(http_https+'{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}{r}.png?apikey=d21820403d04481c9dbf18d096691a94', { attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA' }); var satellitetiles = L.tileLayer(http_https+'api.mapbox.com/styles/v1/xmnr-net/cj8u36h986ono2sodz8oh1lig/tiles/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoieG1uci1uZXQiLCJhIjoiX1YyVm43WSJ9.db6f-l9SLulOORMs12Ez_w', { attribution: 'Map data © Mapbox contributors, CC-BY-SA', tileSize: 512, zoomOffset: -1 }); var baseLayers = { "Landschaft": mapboxtiles, "Radwege": cycletiles, "Satellit": satellitetiles }; if (typeof bounds === 'undefined') { console.log('Bounds not defined'); g_map = L.map('map', { zoomControl: false, attributionControl: false }) .addLayer(mapboxtiles) .setView([50.9384, 6.9604], 15) ; } else { if (typeof haspaddingleft === 'undefined') { var haspaddingleft = true; } var params = {}; if (haspaddingleft) { //console.log('Has padding left'); var params = {paddingTopLeft:[460,0]}; } //console.log('geo_bounds'); console.log(geo_bounds); if ('point' === geo_bounds[2]) { //console.log(geo_bounds[0]+' , '+geo_bounds[1]); // [lat,lng,'point'] g_map = L.map('map', { zoomControl: false, attributionControl: false }) .addLayer(mapboxtiles) //.setView([geo_bounds[0], geo_bounds[1]], 13,params) .setView([geo_bounds[0], geo_bounds[1]], 14,{ pan: params }) ; console.log('params'); console.log(params); } else { // default bounds with four values g_map = L.map('map', { zoomControl: false, attributionControl: false }) .addLayer(mapboxtiles) .fitBounds(bounds,params) ; } // console.log('Bounds'); // console.log(bounds); } //L.control.scale({imperial: false, position: 'topright'}).addTo(g_map); if (showzoomcontrol) { L.control.layers(baseLayers).addTo(g_map); } if (typeof showoverlayimage === 'undefined') { //console.log('showoverlayimage NOT SET'); showoverlayimage = true; } else { } //if (true) { if (showoverlayimage) { console.log('show overlay image'); // image overlay for area borders var imageUrl = 'https://www.bewegte-kirche.de/assets/images/BL/map/map-borders.svgz'; var imageBounds = [[53.380000000000003,3.780000000000000],[47.509999999999998,12.590000000000000]]; L.imageOverlay(imageUrl, imageBounds).addTo(g_map); //console.log(imageUrl); } else { console.log('NO overlay image'); } //.setView([52.3610, -71.0587], 2); new L.Control.Attribution({position: 'bottomright'}).addTo(g_map); L.control.scale({imperial: false, position: 'bottomright'}).addTo(g_map); if (showzoomcontrol) { new L.Control.Zoom({ position: 'topright' }).addTo(g_map); } // var southWest = L.latLng(40.712, -74.227); // var northEast = L.latLng(40.774, -74.125); // var mapBounds = L.latLngBounds(southWest, northEast); // g_map.setMaxBounds(mapBounds); // g_map.on('dragging', function(e) { g_map.on('zoomend moveend', function(e) { //var bounds = g_map.getBounds(); //console.log('Bounds:'); //console.log(bounds._northEast); //console.log(bounds._southWest); //set_action(1); }); // g_map.on('move', function(e) { // console.log('map mouse'); // }); g_map.on('mousemove click', function(e) { // if (null !== g_first_circle) { // g_first_circle.setLatLng(e.latlng); // } else { // console.log('not found'); // } // set_new_startposition(e.latlng); }); // var marker = L.marker([51.5, -0.09]).addTo(g_map); // // var myLayer = L.geoJson().addTo(g_map); if (typeof leaflet_ready === 'function') { leaflet_ready(); } }; var draw_line = function(lat1,long1,lat2,long2) { var pointA = new L.LatLng(lat1, long1); var pointB = new L.LatLng(lat2, long2); var pointList = [pointA, pointB]; var mypolyline = new L.Polyline(pointList, { color: 'white', weight: g_line_width, opacity: g_opacity, smoothFactor: 1 }); var obj = {}; obj.type = 'polyline'; obj.obj = mypolyline; g_polylines.push(obj); mypolyline.addTo(g_map); }; var draw_circle = function(lat,long,radius) { var circle = L.circleMarker([lat, long], { radius: radius, color: '#FFFFFF', fillColor: '#FFFFFF', fillOpacity: 0.8 }).addTo(g_map); var obj = {}; obj.type = 'circle'; obj.obj = circle; g_polylines.push(obj); return circle; }; var clear_lines = function() { console.log('Hier in clear_all_lines'); g_polylines.forEach(function(obj) { g_map.removeLayer(obj.obj); }); g_polylines = []; // clear array return 'returned'; }; var set_line_width = function(line_width) { g_line_width = line_width; draw_destination_lines(); }; // --------------------------------- var start_gps_position = function() { if (g_gps_started) { $('#idgps').text('GPS'); g_map.stopLocate(); // stop gps g_gps_started = false; g_gps_first_message = false; if (undefined !== hide_gps_marker) hide_gps_marker(); infopopup('GPS-Anzeige beendet','',1000); return; } $('#idgps').text('GPS aktiviert'); if (!g_map) { infopopup('Bitte kurz warten, dann noch einmal probieren'); return; } g_gps_started = true; infopopup('GPS aktiviert, bitte warten','wait',1000); //showsidebar(0); //g_map.locate({setView: true, maxZoom: 22}); g_map.locate({setView: false, watch: true}); //g_map.locate(); // start gps g_map.on('locationfound', onLocationFound); g_map.on('locationerror', onLocationError); }; var onLocationFound = function(e) { // console.log('onLocationFound'); // console.log(e.latlng); // g_map.panTo(new L.latLng(50.9534818,6.8358142)); // return; if (!g_gps_first_message) { g_gps_first_message = true; infopopup('GPS: Aktuelle Position wird angezeigt','ok',1000); } //infopopup('GPS '+e.latlng.lng+','+e.latlng.lat,'ok',1000); if (undefined !== show_gps_marker) show_gps_marker(e.latlng.lng,e.latlng.lat); //g_map.panTo(e.latlng); var L_latlng = L.latLng(e.latlng.lat, e.latlng.lng); panToPosition(L_latlng); //console.log(e.latlng); }; var onLocationError = function(e) { console.log('gps location error'); console.log(e.message); }; // --------------------------------- var panToPosition = function(L_latLng) { if (is_100_width()) { //g_map.panTo([latlng.lat,latlng.lng],{animate:true}); g_map.panTo(L_latLng,{animate:true}); } else { // calculate new center point because of padding left var point = g_map.latLngToContainerPoint(L_latLng); var w = $(document).width(); var s = $('#mapsidebar').width(); var xdiff = s + ((w-s)/2) -(w/2); var x = point.x - xdiff; var y = point.y; var newpoint = g_map.containerPointToLatLng([x, y]); g_map.panTo(newpoint,{animate:true}); } }; // ---------------------------------