Package org.geomajas.plugin.rasterizing.api

Examples of org.geomajas.plugin.rasterizing.api.RasterizingContainer


    MapRasterizingInfo mapInfo = (MapRasterizingInfo) clientMapInfo.getWidgetInfo(MapRasterizingInfo.WIDGET_KEY);
    mapContext.setAreaOfInterest(new ReferencedEnvelope(dtoConverterService.toInternal(mapInfo.getBounds()),
        mapContext.getCoordinateReferenceSystem()));
    RenderingHints renderingHints = new Hints();
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    RasterizingContainer response = new RasterizingContainer();
    context.put(RasterizingPipelineCode.CLIENT_MAP_INFO_KEY, clientMapInfo);
    context.put(RasterizingPipelineCode.RENDERING_HINTS, renderingHints);
    context.put(RasterizingPipelineCode.MAP_CONTEXT_KEY, mapContext);
    pipelineService.execute(RasterizingPipelineCode.PIPELINE_RASTERIZING_GET_MAP_IMAGE, null, context, response);
    mapContext.dispose();
    try {
      stream.write(response.getImage());
    } catch (IOException e) {
      throw new RasterException(RasterException.IMAGE_WRITING_FAILED, e);
    }
  }
View Full Code Here


    MapRasterizingInfo mapInfo = (MapRasterizingInfo) clientMapInfo.getWidgetInfo(MapRasterizingInfo.WIDGET_KEY);
    mapContext.setAreaOfInterest(new ReferencedEnvelope(dtoConverterService.toInternal(mapInfo.getBounds()),
        mapContext.getCoordinateReferenceSystem()));
    RenderingHints renderingHints = new Hints();
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    RasterizingContainer response = new RasterizingContainer();
    context.put(RasterizingPipelineCode.CLIENT_MAP_INFO_KEY, clientMapInfo);
    context.put(RasterizingPipelineCode.RENDERING_HINTS, renderingHints);
    context.put(RasterizingPipelineCode.MAP_CONTEXT_KEY, mapContext);
    pipelineService.execute(RasterizingPipelineCode.PIPELINE_RASTERIZING_GET_LEGEND_IMAGE, null, context, response);
    mapContext.dispose();
    try {
      stream.write(response.getImage());
    } catch (IOException e) {
      throw new RasterException(RasterException.IMAGE_WRITING_FAILED, e);
    }

  }
View Full Code Here

  public void execute(PipelineContext context, GetTileContainer tileContainer) throws GeomajasException {
    VectorLayer layer = context.get(PipelineCode.LAYER_KEY, VectorLayer.class);
    TileMetadata tileMetadata = context.get(PipelineCode.TILE_METADATA_KEY, TileMetadata.class);
    // put the image in a raster container
    RasterizingContainer rasterizingContainer = new RasterizingContainer();
    NamedStyleInfo style = tileMetadata.getStyleInfo();
    if (style == null) {
      // no style specified, take the first
      style = layer.getLayerInfo().getNamedStyleInfos().get(0);
    } else if (style.getFeatureStyles().isEmpty()) {
      // only name specified, find it
      style = layer.getLayerInfo().getNamedStyleInfo(style.getName());
    }
    ClientMapInfo mapInfo = new ClientMapInfo();
    MapRasterizingInfo mapRasterizingInfo = new MapRasterizingInfo();
    mapRasterizingInfo.setBounds(converterService.toDto(tileContainer.getTile().getBounds()));
    mapInfo.setCrs(tileMetadata.getCrs());
    mapRasterizingInfo.setScale(tileMetadata.getScale());
    mapInfo.getWidgetInfo().put(MapRasterizingInfo.WIDGET_KEY, mapRasterizingInfo);
    ClientVectorLayerInfo clientVectorLayerInfo = new ClientVectorLayerInfo();
    clientVectorLayerInfo.setServerLayerId(tileMetadata.getLayerId());
    clientVectorLayerInfo.setNamedStyleInfo(style);
    VectorLayerRasterizingInfo vectorLayerRasterizingInfo = new VectorLayerRasterizingInfo();
    vectorLayerRasterizingInfo.setFilter(tileMetadata.getFilter());
    vectorLayerRasterizingInfo.setPaintGeometries(tileMetadata.isPaintGeometries());
    vectorLayerRasterizingInfo.setPaintLabels(tileMetadata.isPaintLabels());
    vectorLayerRasterizingInfo.setFilter(tileMetadata.getFilter());
    vectorLayerRasterizingInfo.setStyle(style);
    clientVectorLayerInfo.getWidgetInfo().put(VectorLayerRasterizingInfo.WIDGET_KEY, vectorLayerRasterizingInfo);
    mapInfo.getLayers().add(clientVectorLayerInfo);

    ByteArrayOutputStream imageStream = new ByteArrayOutputStream(1024 * 10);
    try {
      imageService.writeMap(imageStream, mapInfo);
      // rasterizingService.rasterize(imageStream, layer, style, tileMetadata, tileContainer.getTile());
      recorder.record(CacheCategory.RASTER, "Rasterization success");
    } catch (Exception ex) {
      recorder.record(CacheCategory.RASTER, "Rasterization failed");
      log.error("Problem while rasterizing tile, image will be zero-length.", ex);
    }

    byte[] image = imageStream.toByteArray();
    rasterizingContainer.setImage(image);
    context.put(RasterizingPipelineCode.CONTAINER_KEY, rasterizingContainer);
  }
View Full Code Here

  @Autowired
  private TestRecorder recorder;

  public void execute(PipelineContext context, GetTileContainer container) throws GeomajasException {
    RasterizingContainer rc = context.getOptional(RasterizingPipelineCode.CONTAINER_KEY,
        RasterizingContainer.class);
    if (rc != null) {
      recorder.record(CacheCategory.RASTER, "Put item in cache");
      cachingSupportService.putContainer(context, securityContextAdder, CacheCategory.RASTER, KEYS,
          RasterizingPipelineCode.IMAGE_ID_KEY, RasterizingPipelineCode.IMAGE_ID_CONTEXT, rc,
View Full Code Here

    response.setMapKey(mapKey);
    response.setLegendKey(legendKey);
  }

  private String putInCache(byte[] byteArray, Bbox bounds) {
    RasterizingContainer container = new RasterizingContainer();
    container.setImage(byteArray);
    String key = UUID.randomUUID().toString();
    cacheManagerService.put(null, CacheCategory.RASTER, key, container, dtoConverterService.toInternal(bounds));
    return key;
  }
View Full Code Here

  public void getImage(@PathVariable String layerId, @PathVariable String key, HttpServletResponse response)
      throws Exception {

    try {
      VectorLayer layer = configurationService.getVectorLayer(layerId);
      RasterizingContainer rasterizeContainer = cacheManagerService.get(layer, CacheCategory.RASTER, key,
          RasterizingContainer.class);
      // if not in cache, try the rebuild cache and invoke the pipeline directly
      if (rasterizeContainer == null) {
        GetTileContainer tileContainer = new GetTileContainer();
        PipelineContext context = pipelineService.createContext();
        context.put(RasterizingPipelineCode.IMAGE_ID_KEY, key);
        context.put(PipelineCode.LAYER_ID_KEY, layerId);
        context.put(PipelineCode.LAYER_KEY, layer);

        // get data from rebuild cache
        RebuildCacheContainer rebuildCacheContainer = cacheManagerService.get(layer, CacheCategory.REBUILD, key,
            RebuildCacheContainer.class);
        if (null == rebuildCacheContainer) {
          log.error("Data to rebuild the raster image is no longer available for key " + key);
          response.sendError(HttpServletResponse.SC_NO_CONTENT);
          return;
        }
        recorder.record(CacheCategory.REBUILD, "Got rebuild info from cache");
        TileMetadata tileMetadata = rebuildCacheContainer.getMetadata();
        context.put(PipelineCode.TILE_METADATA_KEY, tileMetadata);
        Crs crs = geoService.getCrs2(tileMetadata.getCrs());
        context.put(PipelineCode.CRS_KEY, crs);
        CrsTransform layerToMap = geoService.getCrsTransform(layer.getCrs(), crs);
        context.put(PipelineCode.CRS_TRANSFORM_KEY, layerToMap);
        Envelope layerExtent = dtoConverterService.toInternal(layer.getLayerInfo().getMaxExtent());
        Envelope tileExtent = geoService.transform(layerExtent, layerToMap);
        context.put(PipelineCode.TILE_MAX_EXTENT_KEY, tileExtent);
        // can't stop here, we have only prepared the context, not built the tile !
        InternalTile tile = new InternalTileImpl(tileMetadata.getCode(), tileExtent, tileMetadata.getScale());
        tileContainer.setTile(tile);
        securityContextAdder.restoreSecurityContext(rebuildCacheContainer.getContext());

        pipelineService.execute(RasterizingPipelineCode.PIPELINE_GET_VECTOR_TILE_RASTERIZING, layerId, context,
            tileContainer);
        rasterizeContainer = context.get(RasterizingPipelineCode.CONTAINER_KEY, RasterizingContainer.class);
      } else {
        recorder.record(CacheCategory.RASTER, "Got item from cache");
      }
      // Prepare the response:
      CacheFilter.configureNoCaching(response);
      response.setContentType("image/png");
      response.getOutputStream().write(rasterizeContainer.getImage());
    } catch (Exception e) {
      log.error("Could not rasterize image " + key, e);
      response.sendError(HttpServletResponse.SC_NO_CONTENT);
    }
  }
View Full Code Here

  }

  @RequestMapping(value = "/rasterizing/image/{key}.png", method = RequestMethod.GET)
  public void getMap(@PathVariable String key, HttpServletResponse response) throws Exception {
    try {
      RasterizingContainer rasterizeContainer = (RasterizingContainer) cacheManagerService.get(null,
          CacheCategory.RASTER, key);
      // Prepare the response:
      CacheFilter.configureNoCaching(response);
      response.setContentType("image/png");
      response.getOutputStream().write(rasterizeContainer.getImage());
    } catch (Exception e) {
      log.error("Could not rasterize image " + key, e);
      response.sendError(HttpServletResponse.SC_NO_CONTENT);
    }
  }
View Full Code Here

TOP

Related Classes of org.geomajas.plugin.rasterizing.api.RasterizingContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.