Package org.geotools.styling

Examples of org.geotools.styling.Style


    // we now replace the style filters by simple filters on an artificial extra style attribute
    for (FeatureStyleInfo style : copy.getStyle().getFeatureStyles()) {
      style.setFormula(STYLE_INDEX_ATTRIBUTE_NAME + " = " + style.getIndex());
    }
    // create the style
    Style style = styleFactoryService.createStyle(layer, copy);
    // estimate the buffer
    MetaBufferEstimator estimator = new MetaBufferEstimator();
    estimator.visit(style);
    int bufferInPixels = estimator.getBuffer();
    // expand area to include buffer
    Rectangle tileInpix = mapContext.getViewport().getScreenArea();
    ReferencedEnvelope metaArea = new ReferencedEnvelope(areaOfInterest);
    metaArea.expandBy(bufferInPixels / tileInpix.getWidth() * areaOfInterest.getWidth(),
        bufferInPixels / tileInpix.getHeight() * areaOfInterest.getHeight());
    // fetch features in meta area
    Crs layerCrs = vectorLayerService.getCrs(layer);
    Envelope layerBounds = geoService.transform(metaArea, (Crs) areaOfInterest.getCoordinateReferenceSystem(),
        layerCrs);
    Filter filter = filterService.createBboxFilter(layerCrs, layerBounds,
        layer.getLayerInfo().getFeatureInfo().getGeometryType().getName());
    if (extraInfo.getFilter() != null) {
      filter = filterService.createAndFilter(filter, filterService.parseFilter(extraInfo.getFilter()));
    }
    List<InternalFeature> features = vectorLayerService.getFeatures(vectorInfo.getServerLayerId(),
        mapContext.getCoordinateReferenceSystem(), filter, extraInfo.getStyle(),
        VectorLayerService.FEATURE_INCLUDE_ALL);

    FeatureLayer featureLayer = new FeatureLayer(createCollection(features, layer,
        mapContext.getCoordinateReferenceSystem(), style), style);
    featureLayer.setTitle(vectorInfo.getLabel());
    featureLayer.getUserData().put(USERDATA_KEY_SHOWING, extraInfo.isShowing());
    List<Rule> rules = new ArrayList<Rule>();
    double scaleDenominator = RendererUtilities.calculateOGCScale(mapContext.getAreaOfInterest(), (int) mapContext
        .getViewport().getScreenArea().getWidth(), null);
    // find the applicable rules
    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
      for (Rule rule : fts.rules()) {
        if (isWithInScale(rule, scaleDenominator)) {
          FeatureIterator<SimpleFeature> it;
          try {
            it = featureLayer.getSimpleFeatureSource().getFeatures().features();
View Full Code Here


      throw new IllegalStateException(
          "GeometryLayerFactory.createLayer() should only be called using ClientGeometryLayerInfo");
    }
    ClientGeometryLayerInfo layerInfo = (ClientGeometryLayerInfo) clientLayerInfo;
    LayerType layerType = layerInfo.getLayerType();
    Style style = styleFactoryService.createStyle(layerType, layerInfo.getStyle());
    GeometryDirectLayer layer = new GeometryDirectLayer(style, converterService.toInternal(layerType));
    for (Geometry geom : layerInfo.getGeometries()) {
      layer.getGeometries().add(converterService.toInternal(geom));
    }
    layer.getUserData().put(USERDATA_KEY_SHOWING, layerInfo.isShowing());
    layer.setTitle(layerInfo.getLabel());
    List<Rule> rules = new ArrayList<Rule>();
    // all rules are needed for map/legend
    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
      for (Rule rule : fts.rules()) {
        rules.add(rule);
      }
    }
    layer.getUserData().put(USERDATA_KEY_STYLE_RULES, rules);
View Full Code Here

      } catch (Exception e) {
        throw new LayerException(e, ExceptionCode.INVALID_SLD, location, layer.getId());
      }
      styleMap.put(location, styles);
    }
    Style style = null;
    for (Style s : styles) {
      if (s.getName().equals(vectorLayerRasterizingInfo.getStyle().getSldStyleName())) {
        style = s;
        break;
      }
View Full Code Here

    return (Style) visitor.getCopy();
  }

  private Style createNamedStyle(VectorLayer layer, VectorLayerRasterizingInfo vectorLayerRasterizingInfo)
      throws GeomajasException {
    Style style = styleBuilder.createStyle();
    String typeName = layer.getLayerInfo().getFeatureInfo().getDataSourceName();
    FeatureInfo featureInfo = layer.getLayerInfo().getFeatureInfo();
    LayerType layerType = layer.getLayerInfo().getLayerType();

    if (vectorLayerRasterizingInfo.isPaintGeometries()) {
      // apply the normal styles
      List<Rule> rules = new ArrayList<Rule>();
      for (FeatureStyleInfo featureStyle : vectorLayerRasterizingInfo.getStyle().getFeatureStyles()) {
        // create the filter
        Filter styleFilter;
        if (featureStyle.getFormula() != null && featureStyle.getFormula().length() > 0) {
          styleFilter = filterService.parseFilter(featureStyle.getFormula());
        } else {
          styleFilter = Filter.INCLUDE;
        }
        // create the rules
        rules.addAll(createRules(layerType, styleFilter, featureInfo, featureStyle));
      }
      // create the style
      FeatureTypeStyle normalStyle = styleBuilder.createFeatureTypeStyle(typeName,
          rules.toArray(new Rule[rules.size()]));
      style.featureTypeStyles().add(normalStyle);
      // apply the selection style
      rules.clear();
      if (vectorLayerRasterizingInfo.getSelectedFeatureIds() != null) {
        // create the filter
        Filter fidFilter = filterService.createFidFilter(vectorLayerRasterizingInfo.getSelectedFeatureIds());
        // create the rules
        rules.addAll(createRules(layerType, fidFilter, featureInfo,
            vectorLayerRasterizingInfo.getSelectionStyle()));
      }
      // create the style
      FeatureTypeStyle selectionStyle = styleBuilder.createFeatureTypeStyle(typeName,
          rules.toArray(new Rule[rules.size()]));
      style.featureTypeStyles().add(selectionStyle);
    }
    // apply the label style
    if (vectorLayerRasterizingInfo.isPaintLabels()) {
      // create the rule
      TextSymbolizer textSymbolizer = createTextSymbolizer(vectorLayerRasterizingInfo.getStyle().getLabelStyle(),
          layerType);
      Rule labelRule = styleBuilder.createRule(textSymbolizer);
      // create the style
      FeatureTypeStyle labelStyle = styleBuilder.createFeatureTypeStyle(typeName, labelRule);
      style.featureTypeStyles().add(labelStyle);
    }
    return style;
  }
View Full Code Here

    }
    return style;
  }

  public Style createStyle(LayerType type, FeatureStyleInfo featureStyleInfo) throws GeomajasException {
    Style style = styleBuilder.createStyle();
    Symbolizer symbolizer = createGeometrySymbolizer(type, featureStyleInfo);
    FeatureTypeStyle fts = styleBuilder.createFeatureTypeStyle(symbolizer);
    style.featureTypeStyles().add(fts);
    return style;
  }
View Full Code Here

    SLDParser parser = new SLDParser(styleFactory);
    parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
    Style[] styles = parser.readXML();
    Assert.assertEquals(1, styles.length);
    visitor.visit(styles[0]);
    Style copy = (Style) visitor.getCopy();
    FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
    Rule rule = featureTypeStyle.rules().iterator().next();
    Iterator<Symbolizer> it = rule.symbolizers().iterator();
    Assert.assertTrue(it.next() instanceof TextSymbolizer);
    Assert.assertFalse(it.hasNext());
  }
View Full Code Here

    SLDParser parser = new SLDParser(styleFactory);
    parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
    Style[] styles = parser.readXML();
    Assert.assertEquals(1, styles.length);
    visitor.visit(styles[0]);
    Style copy = (Style) visitor.getCopy();
    FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
    Rule rule = featureTypeStyle.rules().iterator().next();
    Iterator<Symbolizer> it = rule.symbolizers().iterator();
    Assert.assertTrue(it.next() instanceof PointSymbolizer);
    Assert.assertFalse(it.hasNext());
  }
View Full Code Here

    SLDParser parser = new SLDParser(styleFactory);
    parser.setInput(getClass().getResource("point_pointwithdefaultlabel.sld"));
    Style[] styles = parser.readXML();
    Assert.assertEquals(1, styles.length);
    visitor.visit(styles[0]);
    Style copy = (Style) visitor.getCopy();
    FeatureTypeStyle featureTypeStyle = copy.featureTypeStyles().iterator().next();
    Rule rule = featureTypeStyle.rules().iterator().next();
    Iterator<Symbolizer> it = rule.symbolizers().iterator();
    Assert.assertTrue(it.next() instanceof PointSymbolizer);
    Assert.assertTrue(it.next() instanceof TextSymbolizer);
    Assert.assertFalse(it.hasNext());
View Full Code Here

    }

    public static Style getDefaultStyle( StyledLayerDescriptor sld ) {
        Style[] styles = styles(sld);
        for( int i = 0; i < styles.length; i++ ) {
            Style style = styles[i];
            List<FeatureTypeStyle> ftStyles = style.featureTypeStyles();
            genericizeftStyles(ftStyles);
            if (style.isDefault()) {
                return style;
            }
        }
        // no default, so just grab the first one
        return styles[0];
View Full Code Here

            }
        }
        // The SLD 1.0 parser is far more forgiving
        StyleFactory factory = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints());
        SLDParser styleReader = new SLDParser(factory, url);
        Style style = styleReader.readXML()[0];
        return style;
    }
View Full Code Here

TOP

Related Classes of org.geotools.styling.Style

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.