let $maps2OpenStreetMaps = []; /** * Initialize Open Street Map * * @param $element * @param environment contains settings, current PageId, extConf and current tt_content record * @constructor */ function OpenStreetMaps2($element, environment) { this.categorizedMarkers = {}; this.pointMarkers = []; this.bounds = new L.LatLngBounds(); this.$element = $element.css({ height: environment.settings.mapHeight, width: environment.settings.mapWidth }); this.poiCollections = this.$element.data("pois"); this.editable = this.$element.hasClass("editMarker"); this.createMap(environment); if (typeof this.poiCollections === "undefined" || jQuery.isEmptyObject(this.poiCollections)) { // Plugin: CityMap let lat = this.$element.data("latitude"); let lng = this.$element.data("longitude"); if (lat && lng) { this.createMarkerByLatLng(lat, lng); this.map.fitBounds(this.bounds); } } else { this.createPointByCollectionType(environment); if (this.countObjectProperties(this.categorizedMarkers) > 1) { this.showSwitchableCategories(environment); } if (this.poiCollections.length > 1 && environment.settings.forceZoom === false) { this.map.fitBounds(this.bounds); } else { this.map.panTo([this.poiCollections[0].latitude, this.poiCollections[0].longitude]); } } } /** * Create Map * * @param environment */ OpenStreetMaps2.prototype.createMap = function (environment) { this.map = map = L.map( this.$element.get(0), { center: [environment.extConf.defaultLatitude, environment.extConf.defaultLongitude], zoom: environment.settings.zoom ? environment.settings.zoom : 12, editable: this.editable, scrollWheelZoom: environment.settings.activateScrollWheel !== '0' } ); L.tileLayer(environment.settings.mapTile, { attribution: environment.settings.mapTileAttribution, maxZoom: 20 }).addTo(this.map); }; /** * Group Categories * * @param environment */ OpenStreetMaps2.prototype.groupCategories = function (environment) { let groupedCategories = {}; let categoryUid = "0"; for (let x = 0; x < this.poiCollections.length; x++) { for (let y = 0; y < this.poiCollections[x].categories.length; y++) { categoryUid = String(this.poiCollections[x].categories[y].uid); if (this.inList(environment.settings.categories, categoryUid) > -1 && !groupedCategories.hasOwnProperty(categoryUid)) { groupedCategories[categoryUid] = this.poiCollections[x].categories[y]; } } } return groupedCategories; }; /** * Show switchable categories * * @param environment */ OpenStreetMaps2.prototype.showSwitchableCategories = function (environment) { let categories = this.groupCategories(environment); let $form = jQuery("
") .addClass("txMaps2Form") .attr("id", "txMaps2Form-" + environment.contentRecord.uid); // Add checkbox for category for (let categoryUid in categories) { if (categories.hasOwnProperty(categoryUid)) { $form.append(this.getCheckbox(categories[categoryUid])); $form.find("#checkCategory_" + categoryUid).after(jQuery("") .addClass("map-category") .text(categories[categoryUid].title)); } } // create form let markers = this.categorizedMarkers; $form.find("input").on("click", function () { let isChecked = jQuery(this).is(":checked"); let categoryUid = jQuery(this).val(); if (markers.hasOwnProperty(categoryUid)) { for (let i = 0; i < markers[categoryUid].length; i++) { if (isChecked) { markers[categoryUid][i].setOpacity(1); } else { markers[categoryUid][i].setOpacity(0); } } } }); this.$element.after($form); }; /** * Get Checkbox for Category * * @param category */ OpenStreetMaps2.prototype.getCheckbox = function (category) { return jQuery("
") .addClass("form-group").append( jQuery("
") .addClass("checkbox").append( jQuery("