/** * Sends image as an URL to IE 8 & 9, base64 data for others * * @param url * @param bufferedImage * @param bbox * @param isTiled */ protected void sendWFSImage( String url, BufferedImage bufferedImage, Double[] bbox, boolean isTiled, boolean isboundaryTile) { if (bufferedImage == null) { log.warn("Failed to send image"); return; } Map<String, Object> output = new HashMap<String, Object>(); output.put(OUTPUT_LAYER_ID, this.layerId); Location location = this.session.getLocation(); Tile tileSize = null; if (isTiled) { tileSize = this.session.getTileSize(); } else { tileSize = this.session.getMapSize(); } output.put(OUTPUT_IMAGE_SRS, location.getSrs()); output.put(OUTPUT_IMAGE_BBOX, bbox); output.put(OUTPUT_IMAGE_ZOOM, location.getZoom()); output.put(OUTPUT_IMAGE_TYPE, this.type.toString()); // "normal" | "highlight" output.put(OUTPUT_KEEP_PREVIOUS, this.session.isKeepPrevious()); output.put(OUTPUT_BOUNDARY_TILE, isboundaryTile); output.put(OUTPUT_IMAGE_WIDTH, tileSize.getWidth()); output.put(OUTPUT_IMAGE_HEIGHT, tileSize.getHeight()); output.put(OUTPUT_IMAGE_URL, url); byte[] byteImage = WFSImage.imageToBytes(bufferedImage); String base64Image = WFSImage.bytesToBase64(byteImage); int base64Size = (base64Image.length() * 2) / 1024; // IE6 & IE7 doesn't support base64, max size in base64 for IE8 is 32KB if (!(this.session.getBrowser().equals(BROWSER_MSIE) && this.session.getBrowserVersion() < 8 || this.session.getBrowser().equals(BROWSER_MSIE) && this.session.getBrowserVersion() == 8 && base64Size >= 32)) { output.put(OUTPUT_IMAGE_DATA, base64Image); } this.service.addResults(this.session.getClient(), ResultProcessor.CHANNEL_IMAGE, output); }
public boolean runHighlightJob() { if (!this.sendHighlight) { // highlight job with a flag for not sending images, what is going on in here? return true; } if (!this.requestHandler(null)) { return false; } this.featuresHandler(); if (!goNext()) { return false; } // Send geometries, if requested as well if (this.session.isGeomRequest()) { this.sendWFSFeatureGeometries( this.geomValuesList, ResultProcessor.CHANNEL_FEATURE_GEOMETRIES); } log.debug("highlight image handling", this.features.size()); // IMAGE HANDLING log.debug("sending"); Location location = this.session.getLocation(); if (this.image == null) { this.image = new WFSImage( this.layer, this.session.getClient(), this.session.getLayers().get(this.layerId).getStyleName(), JobType.HIGHLIGHT.toString()); } BufferedImage bufferedImage = this.image.draw(this.session.getMapSize(), location, this.features); if (bufferedImage == null) { this.imageParsingFailed(); throw new RuntimeException("Image parsing failed!"); } Double[] bbox = location.getBboxArray(); // cache (non-persistant) setImageCache( bufferedImage, JobType.HIGHLIGHT.toString() + "_" + this.session.getSession(), bbox, false); String url = createImageURL(JobType.HIGHLIGHT.toString(), bbox); this.sendWFSImage(url, bufferedImage, bbox, false, false); return true; }
/** * Creates a image of the WFS layer's data * * @return image */ private BufferedImage draw() { MapContent content = new MapContent(); MapViewport viewport = new MapViewport(); CoordinateReferenceSystem crs = location.getCrs(); ReferencedEnvelope bounds = location.getEnvelope(); Rectangle screenArea; if (isTile && bufferSize != 0.0d) { double width = (location.getRight() - location.getLeft()) / 2 * bufferSize; double height = (location.getTop() - location.getBottom()) / 2 * bufferSize; bounds = location.createEnlargedEnvelope(width, height); screenArea = new Rectangle(0, 0, bufferedImageWidth, bufferedImageHeight); } else { screenArea = new Rectangle(0, 0, imageWidth, imageHeight); // image size } viewport.setCoordinateReferenceSystem(crs); viewport.setScreenArea(screenArea); viewport.setBounds(bounds); viewport.setMatchingAspectRatio(true); if (features.size() > 0) { Layer featureLayer = new FeatureLayer(features, style); content.addLayer(featureLayer); } content.setViewport(viewport); return saveImage(content); }
/** * Creates a image of the WFS layer's data * * @param tile * @param location * @param bounds * @param features * @return image */ public BufferedImage draw( Tile tile, Location location, List<Double> bounds, FeatureCollection<SimpleFeatureType, SimpleFeature> features) { this.imageWidth = tile.getWidth(); this.imageHeight = tile.getHeight(); if (bounds == null) { this.location = location; } else { this.location = new Location(location.getSrs()); this.location.setBbox(bounds); // enlarge if tile and buffer is defined this.isTile = true; if (bufferSize != 0.0d) { this.bufferedImageWidth = imageWidth + (int) (imageWidth * bufferSize); this.bufferedImageHeight = imageHeight + (int) (imageWidth * bufferSize); } } this.features = features; if (imageWidth == 0 || imageHeight == 0 || this.location == null || style == null || features == null) { log.warn("Not enough information to draw"); log.warn(imageWidth); log.warn(imageHeight); log.warn(location); log.warn(style); log.warn(features.isEmpty()); return null; } return this.draw(); }