Exemplo n.º 1
0
  /**
   * Constructor for image of certain layer and style
   *
   * @param layer
   * @param styleName
   */
  public WFSImage(WFSLayerStore layer, String client, String styleName, String highlightStyleName) {
    if (layer == null || styleName == null) {
      log.error("Failed to construct image (undefined params)");
      return;
    }

    // check if tile buffer is given
    String tileBufferKey;
    if (styleName.startsWith(PREFIX_CUSTOM_STYLE)) {
      tileBufferKey = PREFIX_CUSTOM_STYLE;
    } else {
      tileBufferKey = styleName;
    }
    if (layer.getTileBuffer().containsKey(tileBufferKey)) {
      bufferSize = layer.getTileBuffer().get(tileBufferKey);
    }
    log.debug(tileBufferKey, "=", bufferSize);

    // TODO: possibility to change the custom style store key to sessionID (it is hard without
    // connection to get client)
    if (styleName.startsWith(PREFIX_CUSTOM_STYLE) && client != null) {
      try {
        this.customStyle = WFSCustomStyleStore.create(client, layer.getLayerId());
        if (this.customStyle == null) {
          this.style = null;
          log.error("WFSCustomStyleStore not created", client, layer.getLayerId());
          return;
        }
        this.customStyle.setGeometry(
            layer.getGMLGeometryProperty().replaceAll("^[^_]*:", "")); // set the geometry name
        log.debug(this.customStyle.getGeometry());

        if (highlightStyleName == null) {
          this.style = createCustomSLDStyle();
        } else {
          isHighlight = true;
          this.style = createCustomSLDStyle();
        }
      } catch (Exception e) {
        this.style = null;
        log.error(e, "JSON parsing failed for WFSCustomStyleStore");
        return;
      }
    } else if (highlightStyleName == null) {
      this.style = getSLDStyle(layer, styleName);
    } else {
      isHighlight = true;
      this.style = getSLDStyle(layer, highlightStyleName);
    }
  }
Exemplo n.º 2
0
  /**
   * Creates SLD style
   *
   * @param layer
   * @param styleName
   * @return style
   */
  private Style getSLDStyle(WFSLayerStore layer, String styleName) {
    Style style = null;
    log.debug("Trying to get style with name:", styleName);
    if (layer.getStyles().containsKey(styleName)) {
      style = createSLDStyle(layer.getStyles().get(styleName).getSLDStyle());
    } else if (STYLE_HIGHLIGHT.equals(styleName)) {
      style = createSLDStyle(layer.getSelectionSLDStyle());
    } else if (layer.getStyles().containsKey(STYLE_DEFAULT)) {
      style = createSLDStyle(layer.getStyles().get(STYLE_DEFAULT).getSLDStyle());
    }

    // if styles couldn't be parsed, use defaults
    if (style == null) {
      log.info("Layer style not customized or parsing failed. Using defaults.");
      if (STYLE_HIGHLIGHT.equals(styleName)) {
        // style = createDefaultHighlightSLDStyle(layer.getGMLGeometryProperty());
        // TODO: check if we really always want to use without namespace
        style = createDefaultHighlightSLDStyle(layer.getGMLGeometryPropertyNoNamespace());
      } else {
        style =
            createSLDStyle(
                WFSImage.class.getResourceAsStream(DEFAULT_SLD)); // getClass() (non-static)
      }
    }
    if (style == null) {
      // something is seriously wrong, even default styles can't be parsed
      log.error("Failed to get SLD style (even default failed)!!");
    }

    return style;
  }
Exemplo n.º 3
0
  /**
   * Creates SLD style
   *
   * @param layer
   * @param styleName
   * @return style
   */
  private Style getSLDStyle(WFSLayerStore layer, String styleName) {
    Style style;
    if (layer.getStyles().containsKey(styleName)) {
      style = createSLDStyle(layer.getStyles().get(styleName).getSLDStyle());
    } else if (styleName.equals(STYLE_HIGHLIGHT)) {
      if (layer.getSelectionSLDStyle() != null) {
        style = createSLDStyle(layer.getSelectionSLDStyle());
      } else { // default highlight
        style =
            createSLDStyle(
                WFSImage.class.getResourceAsStream(HIGHLIGHT_SLD)); // getClass() (non-static)
      }
    } else {
      if (layer.getStyles().containsKey(STYLE_DEFAULT)) {
        style = createSLDStyle(layer.getStyles().get(STYLE_DEFAULT).getSLDStyle());
      } else { // default
        style =
            createSLDStyle(
                WFSImage.class.getResourceAsStream(DEFAULT_SLD)); // getClass() (non-static)
      }
    }

    if (style == null) {
      log.error("Failed to get SLD style (default failed)");
    }

    return style;
  }