Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
added print preview and fixed test for new geoserver host location (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdstruijk authored Jan 25, 2024
1 parent 89bc50c commit fce17ea
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 30 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.3</version>
<version>2.7.2</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
Expand Down Expand Up @@ -583,12 +583,12 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.15.0</version>
<version>2.16.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Resolution view() {

checks.add(new UpgradeCheck("PDOK WMS", "https://geodata.nationaalgeoregister.nl/inspire/au/wms?&request=GetCapabilities&service=WMS"));
checks.add(new UpgradeCheck("Openbasiskaart", "https://openbasiskaart.nl/mapcache/wmts/?SERVICE=WMTS&REQUEST=GetCapabilities&VERSION=1.0.0"));
checks.add(new UpgradeCheck("Flamingo5 Geoserver", "https://flamingo5.b3p.nl/geoserver/Test_omgeving/ows?service=wms&version=1.1.1&request=GetCapabilities"));
checks.add(new UpgradeCheck("Flamingo5 Geoserver", "https://test.tailormap.com/geoserver/Test_omgeving/ows?service=wms&version=1.1.1&request=GetCapabilities"));
String solrurl = context.getServletContext().getInitParameter("flamingo.solr.url");
if (!solrurl.equals("http://SERVER/solr")) {
checks.add(new UpgradeCheck("Solr", solrurl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public class WFSTypeNamingTest extends TestUtil {
public static Collection params() {
return Arrays.asList(new Object[][]{
// {"url","name","wfs",typecount},
{"https://flamingo5.b3p.nl:443/geoserver/Test_omgeving/wfs?SERVICE=WFS&", "geoserver-namespaced-wfsurl", "wfs", 4, 0},
{"https://flamingo5.b3p.nl:443/geoserver/Test_omgeving/wms?SERVICE=WMS&", "geoserver-namespaced-wmsurl", "wms", 5, 0}
{"https://test.tailormap.com/geoserver/Test_omgeving/wfs?SERVICE=WFS&", "geoserver-namespaced-wfsurl", "wfs", 4, 0},
{"https://test.tailormap.com/geoserver/Test_omgeving/wms?SERVICE=WMS&", "geoserver-namespaced-wmsurl", "wms", 5, 0}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public class WMSGeoServiceABTest extends TestUtil {
public static Collection params() {
return Arrays.asList(new Object[][]{
// {"url",skipWFS,"serviceProtocol", "attrServiceProtocol",serviceTypecount,groupLayerCount},
{"https://flamingo5.b3p.nl:443/geoserver/Test_omgeving/wms?SERVICE=WMS&", true, "wms", null, 5, 0},
{"https://flamingo5.b3p.nl:443/geoserver/Test_omgeving/wms?SERVICE=WMS&", false, "wms", "wfs", 5, 0}
{"https://test.tailormap.com/geoserver/Test_omgeving/wms?SERVICE=WMS&", true, "wms", null, 5, 0},
{"https://test.tailormap.com/geoserver/Test_omgeving/wms?SERVICE=WMS&", false, "wms", "wfs", 5, 0}
});
}
private ActionBeanContext context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public abstract class TestUtil extends LoggingTestUtil {

protected String layerName = "Test_omgeving:unittest";
protected String geometryAttribute = "geom";
protected String url = "https://flamingo5.b3p.nl/geoserver/Test_omgeving/ows";
protected String url = "https://test.tailormap.com/geoserver/Test_omgeving/ows";
protected List<ConfiguredAttribute> attributes = new ArrayList<ConfiguredAttribute>();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ INSERT INTO geo_service_keywords (geo_service, keyword) VALUES (2, 'WMS');
INSERT INTO geo_service_keywords (geo_service, keyword) VALUES (2, 'http://x12.b3p.nl/cgi-bin/mapserv?map=/srv/maps/solparc/groen_productie.map&');
INSERT INTO geo_service_keywords (geo_service, keyword) VALUES (3, 'http://x12.b3p.nl/cgi-bin/mapserv?map=/srv/maps/solparc/woonplaats_productie.map');
INSERT INTO geo_service_keywords (geo_service, keyword) VALUES (3, 'WMS');
INSERT INTO geo_service_keywords (geo_service, keyword) VALUES (4, 'https://flamingo5.b3p.nl/geoserver/test_omgeving_fla5/wms');
INSERT INTO geo_service_keywords (geo_service, keyword) VALUES (4, 'https://test.tailormap.com/geoserver/test_omgeving_fla5/wms');
INSERT INTO geo_service_keywords (geo_service, keyword) VALUES (4, 'WMS');


Expand Down
80 changes: 77 additions & 3 deletions viewer/src/main/java/nl/b3p/viewer/image/CombineImageSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
*/
package nl.b3p.viewer.image;

import nl.b3p.viewer.print.PaperFormat;
import java.awt.Color;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
Expand Down Expand Up @@ -47,12 +51,29 @@ public class CombineImageSettings {
private Integer width = null;
private Integer height = null;
private Integer angle = null;
private Double scale = 0.0;
public static Color defaultWktGeomColor= Color.RED;
private String mimeType="image/png";

private PaperFormat paperFormat = null;
// bbox + ";"+ resolutions + ";" + tileSize + ";" + serviceUrl;

private String tilingServiceUrl = null;
private String tilingServiceUrl = null;

private static final Map<String, PaperFormat> FORMAT_MAP = new HashMap<>();
static {
FORMAT_MAP.put("a0_landscape", PaperFormat.A0_landscape);
FORMAT_MAP.put("a0_portrait", PaperFormat.A0_portrait);
FORMAT_MAP.put("a1_landscape", PaperFormat.A1_landscape);
FORMAT_MAP.put("a1_portrait", PaperFormat.A1_portrait);
FORMAT_MAP.put("a2_landscape", PaperFormat.A2_landscape);
FORMAT_MAP.put("a2_portrait", PaperFormat.A2_portrait);
FORMAT_MAP.put("a3_landscape", PaperFormat.A3_landscape);
FORMAT_MAP.put("a3_portrait", PaperFormat.A3_portrait);
FORMAT_MAP.put("a4_landscape", PaperFormat.A4_landscape);
FORMAT_MAP.put("a4_portrait", PaperFormat.A4_portrait);
FORMAT_MAP.put("a5_landscape", PaperFormat.A5_landscape);
FORMAT_MAP.put("a5_portrait", PaperFormat.A5_portrait);
}

/**
* Calculate the urls in the combineImageSettings.
Expand Down Expand Up @@ -246,7 +267,27 @@ public void setAngle(Integer angle) {
this.angle = angle;
}

//</editor-fold>
public void setBbox(Bbox bbox) {
this.bbox = bbox;
}

public Double getScale() {
return scale;
}

public void setScale(Double scale) {
this.scale = scale;
}

public PaperFormat getPaperFormat() {
return paperFormat;
}

public void setPaperFormat(PaperFormat paperFormat) {
this.paperFormat = paperFormat;
}

//</editor-fold>
/**
* Create a new BBOX that covers the original and the rotated bbox.
*
Expand Down Expand Up @@ -518,6 +559,39 @@ public static CombineImageSettings fromJson(JSONObject settings) throws JSONExce
cis.setHeight(quality);
}
}

if (settings.has("scale")){
cis.setScale(settings.getDouble("scale"));
}
if(settings.has("pageformat") && settings.has("orientation")) {
cis.setPaperFormat(cis.getPaperFormat(settings.getString("pageformat"), settings.getString("orientation")));
}

return cis;
}

private PaperFormat getPaperFormat(String pageFormat, String orientation) {
String key = pageFormat.toLowerCase() + "_" + orientation.toLowerCase();
return FORMAT_MAP.getOrDefault(key, PaperFormat.A4_portrait);
}

public String correctBoundingBoxForScale(Bbox bbox, double scale, PaperFormat paperFormat) {
if(scale == 0.0 || paperFormat == null) {
return bbox.toString();
}
double widthPx = paperFormat.getWidth();
double heightPx = paperFormat.getHeight();
double ppm = 2.8;

double widthCorrected = (widthPx / ppm) * (scale / 1000);
double heightCorrected = (heightPx / ppm) * (scale / 1000);

double xMid = (bbox.getMinx() + bbox.getMaxx()) / 2;
double yMid = (bbox.getMiny() + bbox.getMaxy()) / 2;
bbox.setMinx(xMid - (widthCorrected / 2));
bbox.setMiny(yMid - (heightCorrected / 2));
bbox.setMaxx(xMid + (widthCorrected / 2));
bbox.setMaxy(yMid + (heightCorrected / 2));
return bbox.toString();
}
}
32 changes: 32 additions & 0 deletions viewer/src/main/java/nl/b3p/viewer/print/PaperFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package nl.b3p.viewer.print;

public enum PaperFormat {
A0_landscape(3140, 2198),
A0_portrait(2100, 3192),
A1_landscape(2110, 1501),
A1_portrait(1400, 2198),
A2_landscape(1436, 1020),
A2_portrait(920, 1500),
A3_landscape(940, 667),
A3_portrait(600, 1008),
A4_landscape(600, 418),
A4_portrait(350, 660),
A5_landscape(375, 240),
A5_portrait(200, 420);

private final double widthPx;
private final double heightPx;

PaperFormat(double widthPx, double heightPx) {
this.widthPx = widthPx;
this.heightPx = heightPx;
}

public double getWidth() {
return widthPx;
}

public double getHeight() {
return heightPx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public Resolution create() throws JSONException, Exception {
this.prepareImageSettings(jRequest);
String url = this.context.getRequest().getRequestURL().toString();
url += "?getImage=t&imageId=" + imageId;
final CombineImageSettings settings = imageSettings.get(imageId);
jResponse.put("bbox",settings.correctBoundingBoxForScale(settings.getBbox(), settings.getScale(), settings.getPaperFormat()));
String jsessionId = null;
String j = "jsessionid";
int index = url.toLowerCase().indexOf(j);
Expand Down Expand Up @@ -218,6 +220,8 @@ public Resolution getImage() throws Exception {
}
if (bbox != null) {
settings.setBbox(bbox);
} else {
settings.setBbox(settings.correctBoundingBoxForScale(settings.getBbox(), settings.getScale(), settings.getPaperFormat()));
}
if (this.getGeom() != null) {
String firstChar = geom.substring(0, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Ext.define("viewer.CombineImage", {
success: function(result) {
var response = Ext.JSON.decode(result.responseText);
if(response.success) {
successFunction(response.imageUrl);
successFunction(response.imageUrl, response.bbox);
} else {
if(failureFunction != undefined) {
failureFunction(response.error);
Expand Down
65 changes: 60 additions & 5 deletions viewer/src/main/webapp/viewer-html/components/Print.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,27 @@ Ext.define("viewer.components.Print", {
this.extraInfoCallbacks = new Array();
this.extraLayerCallbacks = new Array();

this.vectorLayer = this.viewerController.mapComponent.createVectorLayer({
name: 'Printpreview VectorLayer',
geometrytypes: ["Polygon"],
showmeasures: false,
mustCreateVertices: true,
allowselection: false,
viewerController: this.config.viewerController,
style: {
fillopacity: 10,
strokecolor: "FF0000",
}
});
this.viewerController.mapComponent.getMap().addLayer(this.vectorLayer);
this.viewerController.mapComponent.getMap().addListener(viewer.viewercontroller.controller.Event.ON_LAYER_VISIBILITY_CHANGED,this.layerVisibilityChanged,this);
this.viewerController.mapComponent.getMap().addListener(viewer.viewercontroller.controller.Event.ON_LAYER_ADDED,this.layerAdded,this);
this.viewerController.mapComponent.getMap().addListener(viewer.viewercontroller.controller.Event.ON_LAYER_REMOVED,this.layerRemoved,this);

this.popup.addListener('hide', function() {
this.vectorLayer.getFrameworkLayer().removeAllFeatures();
}, this);

return this;
},
// Handler for changes to the visibility of layers
Expand Down Expand Up @@ -438,7 +455,15 @@ Ext.define("viewer.components.Print", {
name: 'orientation',
inputValue: 'portrait',
checked: !(me.getOrientation()==='landscape')
}]
}],
listeners: {
change: {
scope: this,
fn: function () {
this.redrawPreview();
}
}
}
},{
xtype: 'checkbox',
name: 'includeLegend',
Expand Down Expand Up @@ -474,7 +499,15 @@ Ext.define("viewer.components.Print", {
itemId: 'scale',
fieldLabel: i18next.t('viewer_components_print_12'),
xtype:"textfield",
value: this.config.viewerController.mapComponent.getMap().getActualScale()
value: this.config.viewerController.mapComponent.getMap().getActualScale(),
listeners: {
blur: {
fn: function(){
this.redrawPreview();
},
scope:this
}
}
},{
xtype: 'checkbox',
name: 'includeOverview',
Expand Down Expand Up @@ -518,7 +551,15 @@ Ext.define("viewer.components.Print", {
// 2014, Eddy Scheper, ARIS B.V. - A5 and A0 added.
store: pageFormats,
width: 100,
value: me.getDefault_format()? me.getDefault_format(): "a4"
value: me.getDefault_format()? me.getDefault_format(): "a4",
listeners: {
change:{
fn: function(){
this.redrawPreview();
},
scope:this
}
}
},{
xtype: 'slider',
itemId: 'rotateSlider',
Expand Down Expand Up @@ -579,6 +620,7 @@ Ext.define("viewer.components.Print", {
click:{
scope: this,
fn: function (){
this.vectorLayer.getFrameworkLayer().removeAllFeatures();
this.popup.hide();
}
}
Expand Down Expand Up @@ -684,9 +726,15 @@ Ext.define("viewer.components.Print", {
* Call to redraw the preview
*/
redrawPreview: function (){
this.vectorLayer.getFrameworkLayer().removeAllFeatures();
document.getElementById('previewImg').innerHTML = i18next.t('viewer_components_print_29');
var properties = this.getProperties();
this.combineImageService.getImageUrl(Ext.JSON.encode(properties),this.imageSuccess,this.imageFailure);
var me = this;
this.combineImageService.getImageUrl(Ext.JSON.encode(properties),function (url, bbox){
var bboxFeature = me.imageSuccess(url,bbox);
me.vectorLayer.getFrameworkLayer().addFeatures(bboxFeature);
me.vectorLayer.bringToFront();
},this.imageFailure);
},
/**
*
Expand Down Expand Up @@ -856,7 +904,9 @@ Ext.define("viewer.components.Print", {
* Called when a button is clicked and the form must be submitted.
*/
submitSettings: function(action){
this.vectorLayer.setVisible(false);
var properties = this.getAllProperties(action);
this.vectorLayer.setVisible(true);
// console.debug("submitting print values:", properties);
Ext.getCmp('formParams').setValue(Ext.JSON.encode(properties));
//this.combineImageService.getImageUrl(Ext.JSON.encode(properties),this.imageSuccess,this.imageFailure);
Expand Down Expand Up @@ -885,10 +935,14 @@ Ext.define("viewer.components.Print", {
*Called when the imageUrl is succesfully returned
*@param imageUrl the url to the image
*/
imageSuccess: function(imageUrl){
imageSuccess: function(imageUrl, bbox){
if(Ext.isEmpty(imageUrl) || !Ext.isDefined(imageUrl)) imageUrl = null;
if(imageUrl === null) document.getElementById('previewImg').innerHTML = i18next.t('viewer_components_print_31');
else {
bbox = bbox.split(",");
var bounds = new OpenLayers.Bounds(bbox[0],bbox[1],bbox[2],bbox[3]);
var geom = bounds.toGeometry();
var feat = new OpenLayers.Feature.Vector(geom,{name: 'print-preview-bbox-feature'});
var image = new Image();
image.onload = function() {
var img = document.createElement('img');
Expand All @@ -901,6 +955,7 @@ Ext.define("viewer.components.Print", {
preview.appendChild(img);
};
image.src = imageUrl;
return [feat];
}
},
/**
Expand Down
Loading

0 comments on commit fce17ea

Please sign in to comment.