Skip to content

Commit

Permalink
In geo map annotations, use default mapBox settings
Browse files Browse the repository at this point in the history
added 'user' and 'styleId' to mapBox settings

refs #19966
  • Loading branch information
Beechwell committed Dec 17, 2020
1 parent 7dadb33 commit 2b164f4
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4706,6 +4706,14 @@ public String getAnchorLabelInTitleBarSuffix(String template) {
public String getMapBoxToken() {
return getLocalString("maps.mapbox.token", "");
}

public String getMapBoxUser() {
return getLocalString("maps.mapbox.user", "");
}

public String getMapBoxStyleId() {
return getLocalString("maps.mapbox.styleId", "");
}

/**
* @param marker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,14 @@ public boolean isAggregateSearchHits() {
public String getMapBoxToken() {
return DataManager.getInstance().getConfiguration().getMapBoxToken();
}

public String getMapBoxUser() {
return DataManager.getInstance().getConfiguration().getMapBoxUser();
}

public String getMapBoxStyleId() {
return DataManager.getInstance().getConfiguration().getMapBoxStyleId();
}

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
riot.mount("annotationBody", {
currentlang: "#{navigationHelper.localeString}",
resturl: "#{configurationBean.restApiUrl}",
mapboxtoken: "#{configurationBean.mapBoxToken}"
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@
</div>
</div>
<script>
$(document).ready(() => {
riot.mount( "annotationBody", {
currentlang: "#{navigationHelper.localeString}",
resturl: "#{configurationBean.restApiUrl}",
mapboxtoken: "#{configurationBean.mapBoxToken}"
} );
})
</script>

</h:form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var viewerJS = ( function( viewer ) {
},
allowMovingFeatures: false,
mapBoxToken : undefined,
mapBoxWorldId: "mapbox.world-bright",
language: "de",
popover: undefined,
emptyMarkerMessage: undefined,
Expand Down Expand Up @@ -78,9 +77,24 @@ var viewerJS = ( function( viewer ) {
this.map.remove();
}

if(!this.config.mapBoxToken) {
this.config.mapBoxToken = viewerJS.getMapBoxToken();
//init mapBox config. If no config object is set in viewerJS, only get token from viewerJS
//if that doesn't exists, don't create mapBox config
if(!this.config.mapBox && viewerJS.getMapBoxToken()) {
if(viewerJS.mapBoxConfig) {
this.config.mapBox = viewerJS.mapBoxConfig;
} else {
this.config.mapBox = {
token : viewerJS.getMapBoxToken()
}
}
}
if(this.config.mapBox && !this.config.mapBox.user) {
this.config.mapBox.user = "mapbox";
}
if(this.config.mapBox && !this.config.mapBox.styleId) {
this.config.mapBox.styleId = "streets-v11";
}

if(_debug) {
console.log("init GeoMap with config ", this.config);
}
Expand All @@ -93,9 +107,12 @@ var viewerJS = ( function( viewer ) {
keyboard: !this.config.fixed
});

if(this.config.mapBoxToken) {
var mapbox = new L.TileLayer(
'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=' + this.config.mapBoxToken, {
if(this.config.mapBox) {
let url = 'https://api.mapbox.com/styles/v1/{1}/{2}/tiles/{z}/{x}/{y}?access_token={3}'
.replace("{1}", this.config.mapBox.user)
.replace("{2}", this.config.mapBox.styleId)
.replace("{3}", this.config.mapBox.token);
var mapbox = new L.TileLayer(url, {
tileSize: 512,
zoomOffset: -1,
attribution: '© <a href="https://apps.mapbox.com/feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,14 +461,15 @@ var viewerJS = ( function( viewer ) {
}

viewer.getMapBoxToken = function() {
if(typeof mapBoxToken != "undefined") {
if(typeof this.mapBoxConfig != "undefined" && typeof this.mapBoxConfig.token != "undefined") {
return this.mapBoxConfig.token;
} else if(typeof mapBoxToken != "undefined") {
return mapBoxToken;
} else {
return undefined;
}
}

}

viewer.getMetadataValue = function(object, language) {
if(typeof object === "string") {
return object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ var viewerJS = ( function( viewer ) {
if(closable === true) {
$dismissButtons.show();
$( 'body' ).one( 'click.close-modal', "[data-overlay-action='dismiss']", event => {
console.log("close modal", event, $node);
($node).detach();
$overlay.removeClass("active");
$overlay.removeClass("fullscreen");
Expand All @@ -155,7 +154,6 @@ var viewerJS = ( function( viewer ) {
});
//close on click outside content
$( 'body' ).one( 'click.close-modal', ".overlay", event => {
console.log("close modal", event, $node);
if($(event.target).hasClass("overlay")) {
//click directly on modal
($node).detach();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ this.on("mount", () => {
mapId: "geomap_" + this.opts.annotationid,
fixed: true,
clusterMarkers: false,
mapBoxToken: this.opts.mapboxtoken
};
this.geoMap = new viewerJS.GeoMap(this.config);
let view = this.feature.view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ this.on("mount", () => {
mapId: "geomap_" + this.opts.annotationid,
fixed: true,
clusterMarkers: false,
mapBoxToken: this.opts.mapboxtoken
};
this.geoMap = new viewerJS.GeoMap(this.config);
let view = this.feature.view;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -849,14 +849,15 @@ var viewerJS = ( function( viewer ) {
}

viewer.getMapBoxToken = function() {
if(typeof mapBoxToken != "undefined") {
if(typeof this.mapBoxConfig != "undefined" && typeof this.mapBoxConfig.token != "undefined") {
return this.mapBoxConfig.token;
} else if(typeof mapBoxToken != "undefined") {
return mapBoxToken;
} else {
return undefined;
}
}

}

viewer.getMetadataValue = function(object, language) {
if(typeof object === "string") {
return object;
Expand Down Expand Up @@ -3567,7 +3568,6 @@ var viewerJS = ( function( viewer ) {
},
allowMovingFeatures: false,
mapBoxToken : undefined,
mapBoxWorldId: "mapbox.world-bright",
language: "de",
popover: undefined,
emptyMarkerMessage: undefined,
Expand Down Expand Up @@ -3605,9 +3605,24 @@ var viewerJS = ( function( viewer ) {
this.map.remove();
}

if(!this.config.mapBoxToken) {
this.config.mapBoxToken = viewerJS.getMapBoxToken();
//init mapBox config. If no config object is set in viewerJS, only get token from viewerJS
//if that doesn't exists, don't create mapBox config
if(!this.config.mapBox && viewerJS.getMapBoxToken()) {
if(viewerJS.mapBoxConfig) {
this.config.mapBox = viewerJS.mapBoxConfig;
} else {
this.config.mapBox = {
token : viewerJS.getMapBoxToken()
}
}
}
if(this.config.mapBox && !this.config.mapBox.user) {
this.config.mapBox.user = "mapbox";
}
if(this.config.mapBox && !this.config.mapBox.styleId) {
this.config.mapBox.styleId = "streets-v11";
}

if(_debug) {
console.log("init GeoMap with config ", this.config);
}
Expand All @@ -3620,9 +3635,12 @@ var viewerJS = ( function( viewer ) {
keyboard: !this.config.fixed
});

if(this.config.mapBoxToken) {
var mapbox = new L.TileLayer(
'https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/{z}/{x}/{y}?access_token=' + this.config.mapBoxToken, {
if(this.config.mapBox) {
let url = 'https://api.mapbox.com/styles/v1/{1}/{2}/tiles/{z}/{x}/{y}?access_token={3}'
.replace("{1}", this.config.mapBox.user)
.replace("{2}", this.config.mapBox.styleId)
.replace("{3}", this.config.mapBox.token);
var mapbox = new L.TileLayer(url, {
tileSize: 512,
zoomOffset: -1,
attribution: '© <a href="https://apps.mapbox.com/feedback/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
Expand Down Expand Up @@ -6888,7 +6906,6 @@ var viewerJS = ( function( viewer ) {
if(closable === true) {
$dismissButtons.show();
$( 'body' ).one( 'click.close-modal', "[data-overlay-action='dismiss']", event => {
console.log("close modal", event, $node);
($node).detach();
$overlay.removeClass("active");
$overlay.removeClass("fullscreen");
Expand All @@ -6898,7 +6915,6 @@ var viewerJS = ( function( viewer ) {
});
//close on click outside content
$( 'body' ).one( 'click.close-modal', ".overlay", event => {
console.log("close modal", event, $node);
if($(event.target).hasClass("overlay")) {
//click directly on modal
($node).detach();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@
</div>
</div>
<script>
$(document).ready(() => {
riot.mount( "annotationBody", {
currentlang: "#{navigationHelper.localeString}",
resturl: "#{configurationBean.restApiUrl}",
mapboxtoken: "#{configurationBean.mapBoxToken}"
} );
});
</script>

</h:form>
Expand Down
4 changes: 3 additions & 1 deletion goobi-viewer-core/src/main/resources/config_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,9 @@

<maps>
<mapbox>
<token></token>
<token></token>
<user></user>
<styleId></styleId>
</mapbox>
</maps>

Expand Down

0 comments on commit 2b164f4

Please sign in to comment.