Skip to content

Commit

Permalink
get map attribution from style if none is set
Browse files Browse the repository at this point in the history
  • Loading branch information
goapunk committed May 4, 2023
1 parent 7c01d37 commit ad228e6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
26 changes: 22 additions & 4 deletions bplan/assets/js/app/components/map/mapControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ angular.module('app.map.controllers', [])
style: $scope.baseurl,
maxZoom: 19,
}).addTo(map)
$scope.maplibreMap = maplibreMap

map.attributionControl.setPrefix($scope.attribution);

$scope.districtMarkers = L.layerGroup();

Expand Down Expand Up @@ -191,7 +191,7 @@ angular.module('app.map.controllers', [])
map.on('dragend', function (e){
getMultipolygons();
});
return map;
return {map, maplibreMap};
};

var updatePolygonAfterBplanChange = function(marker, multipolygon){
Expand Down Expand Up @@ -344,15 +344,33 @@ angular.module('app.map.controllers', [])

$scope.$on('data:loaded', function() {
$scope.places.initMap().then(function() {
$scope.map = createMap();
var maps = createMap();
$scope.map = maps.map
$scope.bplansPerDistrict = {}
addGeojson($scope.places.bplan_points.features, 0);
// if no attribution is set, try to get it from style source
if (!$scope.attribution) {
var maplibreMap = maps.maplibreMap.getMaplibreMap();
maplibreMap.on("style.load", function () {
var sources = maplibreMap.getStyle().sources;
var keys = Object.keys(sources);
keys.every((key, index) => {
if ("attribution" in sources[key]) {
$scope.map.attributionControl.
addAttribution(sources[key].attribution);
return false;
}
return true;
});
});
} else {
$scope.map.attributionControl.addAttribution($scope.attribution);
}
if(area){
_.forEach($scope.bplansPerDistrict, function(clustergroup) {
clustergroup.addTo($scope.map);
})
}

});
});

Expand Down
9 changes: 7 additions & 2 deletions bplan/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['afs_behoer'] = self.request.GET.get('afs_behoer', '')
context['map_baseurl'] = settings.MAP_BASEURL
context['map_attribution'] = settings.MAP_ATTRIBUTION
if hasattr(settings, 'MAP_ATTRIBUTION'):
attribution = settings.MAP_ATTRIBUTION
context['map_attribution'] = attribution
return context


Expand All @@ -39,7 +41,10 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['afs_behoer'] = self.request.GET.get('afs_behoer', '')
context['map_baseurl'] = settings.MAP_BASEURL
context['map_attribution'] = settings.MAP_ATTRIBUTION
attribution = ""
if hasattr(settings, 'MAP_ATTRIBUTION'):
attribution = settings.MAP_ATTRIBUTION
context['map_attribution'] = attribution
return context


Expand Down
3 changes: 0 additions & 3 deletions django_zbp/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,3 @@
CORS_ORIGIN_ALLOW_ALL = True
CORS_URLS_REGEX = r'^/api/addresses/.*$'
MAP_BASEURL = "https://basemap.berlin.de/gdz_basemapde_vektor/styles/bm_web_col.json"
MAP_ATTRIBUTION = (
'© 2023 basemap.de / BKG | Datenquellen: © GeoBasis-DE'
)

0 comments on commit ad228e6

Please sign in to comment.