PageSourceSearch

https://agrar-bdg.de/wp-content/plugins/osmapper/assets/js/min/osmapper_renderer.js?ver=2.1.5

js agrar-bdg.de collected 2026-09-24 11:38:38 UTC 18,724 bytes, 567 lines download raw bytes

1/**
2 * Author : Mateusz Grzybowski
3 * [email protected]
4 */
5
6
7(function ($) {
8
9
10    var ajaxAdmin = ba_map_ajax.url,
11        loadingGif = ba_map_ajax.gif,
12        defaultConfig = ba_map_ajax.defaultConfig,
13        mapHolder = $('.ba_map_holder');
14
15    if (mapHolder.length > 0) {
16
17        // console.log('mapHolder present')
18
19        $.each(mapHolder, function (key, value) {
20
21            var mapID = $(this).data('map-id'),
22                holderID = $(this).attr('id');
23            // console.log(holderID);
24
25
26            /**
27             * Whenever we have custom hard-coded html map
28             */
29            if ($(this).hasClass('markers')) {
30
31                var mapConfig = findMarkers($(this)),
32                    holderID = generateID();
33
34                //Attach generated ID to this div
35                $(this).attr('id', holderID);
36                renderCustomMap(holderID, mapConfig);
37            } else {
38				
39                sendRequest('getConfig', {
40                    'mapID': mapID,
41                    'holderID': holderID,
42                });
43            }
44        })
45    }
46
47
48    $(document).ajaxSuccess(function (event, xhr, param) {
49        /**
50         * Prevent catching WordPress ajax actions like heartbeat
51         */
52//		console.log(param.data);
53		if( param.hasOwnProperty( 'data' ) ) {
54//			console.log( param.data );
55		    if( param.data.indexOf( 'ba_map_ajax_handler' ) > 0 ) {
56			    if (param && typeof param.data !== "undefined") {
57				   let sentParams = parseString(param.data);
58				   // console.log(sentParams);
59				   /**
60					* Make sure that we get data from ba_map_ajax_handler handler
61					*/
62				    if (sentParams.action === "ba_map_ajax_handler") {
63					   /**
64						* Check sent request type to verify sent object
65						*/
66						   // console.log(typeof xhr.responseJSON);
67					    var markers,
68						   config;
69
70
71					    if (typeof xhr.responseJSON !== 'undefined' && sentParams.requestType === 'getConfig') {
72
73						   markers = xhr.responseJSON.markers;
74						   config = xhr.responseJSON.config;
75
76						   // console.log(xhr.responseJSON);
77						   // console.log(config);
78
79						   renderMap(markers, config, xhr.responseJSON)
80					    } else if (typeof xhr.responseText !== 'undefined' && sentParams.requestType === 'getConfig') {
81
82						   var responseJson = JSON.parse(xhr.responseText);
83
84						   markers = responseJson.markers;
85						   config = responseJson.config;
86
87						   renderMap(markers, config, responseJson);
88						   // console.log(responseJson);
89					    } else {
90//						   console.log("Couldn't recieve response")
91					    }
92				   }
93			    }
94		    }
95	   }
96    });
97
98    /**
99     * Scans div for markers to add
100     *
101     * @param obj
102     */
103    function findMarkers(obj) {
104
105        if (!obj.hasClass('markers')) {
106            return false;
107        }
108
109        var markers = {
110            markers: {},
111            config: {},
112        };
113        /**
114         * Find all markes inside given div
115         */
116        $.each(obj.find('.marker'), function (key, value) {
117
118            let lat = $(this).data('lat'),
119                lng = $(this).data('lng'),
120                pin = $(this).data('pin'),
121                infoWindow = $(this)[0].innerHTML,
122                obj = {};
123
124
125            if (typeof lat !== "undefined" && typeof lng !== "undefined") {
126
127                obj['lat'] = lat;
128                obj['lng'] = lng;
129                if (infoWindow !== "") {
130                    obj['infoWindow'] = infoWindow.replace('<p></p>', '');
131                }
132                /**
133                 * Set custom or default map pin
134                 */
135                if (typeof pin !== "undefined") {
136                    obj['icon'] = pin;
137                } else {
138                    obj['icon'] = defaultConfig.pin;
139                }
140
141                //Add found items to master obj
142                markers['markers'][key] = obj;
143            }
144
145
146        });
147
148        /**
149         * Add all attached data-params
150         */
151        $.each(obj[0].dataset, function (key, value) {
152
153            // console.log(key);
154
155            if (value !== "" && key !== "") {
156                markers['config'][key] = value;
157            }
158
159        });
160
161
162        return markers;
163    }
164
165    function isMobile() {
166        var check = false;
167        (function (a) {
168            if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true;
169        })(navigator.userAgent || navigator.vendor || window.opera);
170        return check;
171    };
172
173    function generateID() {
174
175        return '_' + Math.random().toString(36).substr(2, 9);
176    }
177
178    /**
179     * Generate Custom map from given settings in HTML
180     * @param mapID
181     * @param settings
182     * @returns {*}
183     */
184    function renderCustomMap(mapID, settings) {
185
186        var mapMarkers = [],
187            allLatLngs = [];
188
189
190        /**
191         * Color scheme of map
192         * colors :
193         * normal: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png'
194         * gray:' http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png'
195         * @type {mn}
196         */
197        var tileLayer = new L.TileLayer(settings.config.scheme + '/{z}/{x}/{y}.png', {
198            attribution: '<a href="https://b4after.pl">Interactive agency Before After </a>&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
199        });
200
201
202        /**
203         * Main instance of map
204         * @type {be}
205         */
206        var map = new L.Map(mapID, {
207            center: [52.3735144, 16.9020508],
208            // minZoom: 20,
209            // maxZoom: 30,
210            zoom: 15,
211            scrollWheelZoom: settings.config.scroll === "false" ? false : true, //Enable or disable scroll on map
212            tap: false,
213            dragging: !isMobile(),
214            layers: [tileLayer],
215//			fullscreenControl: {
216//				pseudoFullscreen: false
217//			},
218//			fullscreenControl: true,
219        });
220
221//		map.addControl(new L.Control.Fullscreen());
222        /**
223         * Render each marker in the map
224         */
225        $.each(settings.markers, function (key, value) {
226
227            var marker = $(this);
228
229            /**
230             * Generate array of all coordinates to center it in further step
231             * @type {*[]}
232             */
233            allLatLngs[key] = [value.lat, value.lng];
234
235            /**
236             * New pin instance
237             */
238            var customIcon = L.icon({
239                iconUrl: value.icon,
240                iconSize: [38, 38],
241                popupAnchor: [-3, -20]
242            });
243
244            /**
245             * New marker instance
246             */
247            var mapMarker = L.marker([value.lat, value.lng], {
248                icon: customIcon,
249
250            });
251            /**
252             * Generate infobox
253             */
254            if (typeof value.infoWindow !== 'undefined' && value.infoWindow !== "") {
255                /**
256                 * # 1.3.4
257                 * Fixed error with no enters in javascript
258                 */
259                mapMarker.bindPopup('<p class="markerInfoBox">' + value.infoWindow.replace(/(\r\n|\n|\r)/gm, "<br />") + '</p>', {
260                    className: 'osmapper_class'
261                })
262            }
263            mapMarkers[key] = mapMarker;
264            //Add marker to map
265            mapMarker.addTo(map)
266
267
268        });
269        /**
270         * Get center of all lat lngs
271         * @type {T}
272         */
273            // console.log(allLatLngs);
274        var bounds = new L.LatLngBounds(allLatLngs);
275        /**
276         * Center on all markers
277         */
278        map.fitBounds(bounds);
279
280        if (allLatLngs.length < 2) {
281            map.setZoom(14);
282        }
283
284        return settings;
285    }
286
287    /**
288     *
289     * @param markers
290     * @param config
291     * @param xhrOptions
292     */
293    function renderMap(markers, config, xhrOptions) {
294        let mapID = xhrOptions.params.holderID,
295            mapMarkers = [],
296            allLatLngs = [],
297            mapScheme;
298
299        if (config.pin) {
300            var legacyIcon = L.icon({
301                iconUrl: config.pin, //TODO: dodać stadardowy url dla kompatybilności
302                iconSize: [38, 38],
303                popupAnchor: [-3, -20]
304            });
305        }
306        if (typeof config.layer === "undefined") {
307            mapScheme = '//basemaps.cartocdn.com/light_all/';
308        } else {
309            mapScheme = config.layer
310        }
311
312        if (config.map_height) {
313            $('#' + mapID).css({
314                'height': config.map_height + 'px'
315            });
316        }
317
318
319        /**
320         * Color scheme of map
321         * colors :
322         * normal: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png'
323         * gray:' http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png'
324         * @type {mn}
325         */
326        let tileLayer = new L.TileLayer(mapScheme + '{z}/{x}/{y}.png', {
327            attribution: '<a href="https://b4after.pl/?utm_source=' + window.location.href + '&utm_medium=map_contributors&utm_campaign=OSMapper">Agencja SEO Poznań</a> &copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
328        });
329
330
331        let map = new L.Map(mapID, {
332            center: [52.3735144, 16.9020508],
333            // minZoom: 20,
334            // maxZoom: 30,
335            scrollWheelZoom: config.zoom_on_scroll === "No" ? false : true, //Enable or disable scroll on map
336            tap: false,
337            dragging: !isMobile(),
338            layers: [tileLayer],
339			fullscreenControl: config.full_screen === "No" ? false : true, //Enable or disable scroll on map,
340        });
341
342
343        /**
344         * Debuggggg
345         */
346        // console.log({
347        //     config, xhrOptions
348        // });
349
350        $.each(markers, function (key, value) {
351            let rowID = value.row_id;
352            /**
353             * Set default rowID if map isnt saved after update
354             *
355             */
356            if (typeof rowID === "undefined") {
357                rowID = $('input[data-name="row_id"]').attr('id');
358            }
359
360            let locationsLat = $('#' + rowID).siblings('input[data-name="latitude"]').attr('id'),
361                locationsLng = $('#' + rowID).siblings('input[data-name="longitude"]').attr('id'),
362                marker = $(this);
363
364
365            if (value.pin) {
366                var markerIcon = L.icon({
367                    iconUrl: value.pin,
368                    iconSize: [38, 38],
369                    popupAnchor: [-3, -20]
370                });
371            }
372
373
374            /**
375             * Fixing undefined values of oldeer versions of plugin
376             */
377            if (typeof locationsLat === "undefined" || typeof locationsLng === "undefined") {
378                locationsLat = $('input[value="' + value.latitude + '"]');
379                locationsLng = $('input[value="' + value.longitude + '"]');
380            }
381            /**
382             * Generate array of all coordinates to center it in further step
383             * @type {*[]}
384             */
385            allLatLngs[key] = [value.latitude, value.longitude];
386            /**
387             * New marker instance
388             */
389            let mapMarker = L.marker([value.latitude, value.longitude], {
390                icon: typeof markerIcon !== 'undefined' ? markerIcon : legacyIcon,
391                draggable: xhrOptions.is_admin ? true : false,
392            });
393            /**
394             * Generate infobox
395             */
396            if (typeof value.infobox !== 'undefined' && value.infobox !== "") {
397
398                /**
399                 * # 1.3.4
400                 * Fixed error with no enters in javascript
401                 */
402                mapMarker.bindPopup('<div class="markerInfoBox">' + value.infobox.replace(/(\r\n|\n|\r)/gm, "<br />") + '</div>', {
403                    className: value.popup_style ? value.popup_style : 'standard'
404                })
405            }
406
407            mapMarker.on('dragend', function (event) {
408                // console.log({
409                //     locationsLat,
410                //     locationsLng
411                // });
412                let newPosition = event.target.getLatLng();
413
414
415                event.target.setLatLng(newPosition, {
416                    draggable: 'true'
417                }).update();
418                /**
419                 * Overwrite values in inputs
420                 */
421                // let lat = $('#' + locationsLat),
422                //     lng = $('#' + locationsLng);
423
424
425                locationsLat.val(newPosition.lat);
426                locationsLng.val(newPosition.lng);
427
428                locationsLat.addClass('manuallyDragged');
429                locationsLng.addClass('manuallyDragged');
430
431
432                // console.log(event);
433                xhrOptions.is_admin ? iziToast.show({}) : '';
434            });
435
436
437            mapMarkers[key] = mapMarker;
438            //Add marker to map
439            mapMarker.addTo(map)
440        });
441        /**
442         * Get center of all lat lngs
443         * @type {T}
444         */
445        let bounds = new L.LatLngBounds(allLatLngs);
446        /**
447         * Center on all markers
448         */
449
450        // console.log(bounds);
451        // console.log(bounds.getNorth());
452        // console.log(bounds.getEast());
453        // console.log(bounds.getCenter());
454        // map.fitBounds(bounds);
455
456        if (allLatLngs.length < 2) {
457
458            map.setView({
459                lat: bounds.getNorth(),
460                lng: bounds.getEast(),
461            }, config.map_zoom ? config.map_zoom : 14);
462            /**
463             * Move map to X/Y position
464             * @type {number}
465             */
466            if (config.marker_position !== "center") {
467                var offset = map.getSize(),
468                    params = [];
469
470                if (config.marker_position === "left") {
471                    params = [
472                        offset.x * .35, 0
473                    ]
474                } else if (config.marker_position === "right") {
475                    params = [
476                        offset.x * -.35, 0
477                    ]
478                } else if (config.marker_position === "bottom") {
479                    params = [
480                        0, offset.y * -.35,
481                    ]
482                } else if (config.marker_position === "top") {
483                    params = [
484                        0, offset.y * .35,
485                    ]
486                }
487                // console.log(params);
488                map.panBy(new L.Point(params[0], params[1]), {animate: true});
489            }
490        } else {
491            map.fitBounds(bounds);
492            // map.setView(bounds.getCenter(), 14)
493            // console.log(map);
494            /**
495             * Set new zoom only when new is greated than old one after fitBounds
496             */
497            let newZoom = map.getZoom() > parseInt(config.map_zoom) ? config.map_zoom : map.getZoom();
498            // console.log(newZoom);
499            map.setZoom(newZoom);
500        }
501
502    }
503
504    /**
505     *
506     * @param type
507     * @param param
508     */
509    function sendRequest(type, param) {
510
511        $.ajax({
512            url: ajaxAdmin,
513            type: 'post',
514            dataType: 'json',
515            data: {
516                action: 'ba_map_ajax_handler',
517                requestParams: param,
518                requestType: type,
519            },
520            beforeSend: function () {
521                mapHolder.addClass('loading');
522            },
523            success: function (result) {
524                // console.log(result);
525                mapHolder.removeClass('loading');
526
527                // console.log(result);
528
529
530            }
531        });
532    }
533
534    /**
535     * Javascript version of PHP
536     * @param string
537     * @returns {Array}
538     */
539    function parseString(string) {
540
541        /**
542         * Convert string to array
543         */
544        var data = string.split('&');
545
546        var results = [];
547        for (var i = 0; i < data.length; i++) {
548            /**
549             *
550             */
551            results.push(data[i].split('='));
552        }
553
554        var finalResults = [];
555        $.each(results, function (k, v) {
556
557            /**
558             * Make an associative array
559             */
560            finalResults[v[0]] = v[1]
561
562
563        });
564
565        return finalResults;
566    }
567})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.