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("