use of org.geotools.styling.PointSymbolizer in project sldeditor by robward-scisys.
the class PointFillDetails method populate.
/**
* Populate.
*
* @param selectedSymbol the selected symbol
*/
/*
* (non-Javadoc)
*
* @see com.sldeditor.ui.iface.PopulateDetailsInterface#populate(com.sldeditor.ui.detail.SelectedSymbol)
*/
@Override
public void populate(SelectedSymbol selectedSymbol) {
Expression expSize = null;
Expression expRotation = null;
Expression expAnchorPointX = null;
Expression expAnchorPointY = null;
Expression expDisplacementX = null;
Expression expDisplacementY = null;
Expression expGap = null;
Expression expInitialGap = null;
PointSymbolizer pointSymbolizer = null;
if (selectedSymbol != null) {
Symbolizer symbolizer = selectedSymbol.getSymbolizer();
if (symbolizer instanceof PointSymbolizerImpl) {
pointSymbolizer = (PointSymbolizer) symbolizer;
Graphic graphic = pointSymbolizer.getGraphic();
if (graphic != null) {
expSize = graphic.getSize();
expRotation = graphic.getRotation();
// Anchor point
AnchorPoint anchorPoint = graphic.getAnchorPoint();
if (anchorPoint != null) {
expAnchorPointX = anchorPoint.getAnchorPointX();
expAnchorPointY = anchorPoint.getAnchorPointY();
} else {
expAnchorPointX = AnchorPoint.DEFAULT.getAnchorPointX();
expAnchorPointY = AnchorPoint.DEFAULT.getAnchorPointY();
}
// Offset
Displacement displacement = graphic.getDisplacement();
if (displacement != null) {
expDisplacementX = displacement.getDisplacementX();
expDisplacementY = displacement.getDisplacementY();
} else {
expDisplacementX = Displacement.DEFAULT.getDisplacementX();
expDisplacementY = Displacement.DEFAULT.getDisplacementY();
}
expGap = graphic.getGap();
expInitialGap = graphic.getInitialGap();
List<GraphicalSymbol> graphicalSymbolList = graphic.graphicalSymbols();
if (!graphicalSymbolList.isEmpty()) {
GraphicalSymbol symbol = graphicalSymbolList.get(0);
symbolTypeFactory.setValue(PointSymbolizer.class, this.fieldConfigManager, graphic, symbol);
}
}
}
}
fieldConfigVisitor.populateField(FieldIdEnum.SIZE, expSize);
fieldConfigVisitor.populateField(FieldIdEnum.ANGLE, expRotation);
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_H, expAnchorPointX);
fieldConfigVisitor.populateField(FieldIdEnum.ANCHOR_POINT_V, expAnchorPointY);
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_X, expDisplacementX);
fieldConfigVisitor.populateField(FieldIdEnum.DISPLACEMENT_Y, expDisplacementY);
fieldConfigVisitor.populateField(FieldIdEnum.GAP, expGap);
fieldConfigVisitor.populateField(FieldIdEnum.INITIAL_GAP, expInitialGap);
if (vendorOptionFillFactory != null) {
vendorOptionFillFactory.populate(pointSymbolizer);
}
updateSymbol();
}
use of org.geotools.styling.PointSymbolizer in project sldeditor by robward-scisys.
the class PointSymbolizerDetails method updateSymbol.
/**
* Update symbol.
*/
private void updateSymbol() {
if (!Controller.getInstance().isPopulating()) {
StandardData standardData = getStandardData();
Expression geometryField = ExtractGeometryField.getGeometryField(fieldConfigVisitor);
PointSymbolizer pointSymbolizer = (PointSymbolizer) SelectedSymbol.getInstance().getSymbolizer();
if (pointSymbolizer != null) {
pointSymbolizer.setName(standardData.name);
pointSymbolizer.setDescription(standardData.description);
pointSymbolizer.setUnitOfMeasure(standardData.unit);
pointSymbolizer.setGeometry(geometryField);
this.fireUpdateSymbol();
}
}
}
use of org.geotools.styling.PointSymbolizer in project sldeditor by robward-scisys.
the class CreateInternalDataSourceTest method testDetermineGeometryType.
/**
* Test method for
* {@link com.sldeditor.datasource.impl.CreateInternalDataSource#determineGeometryType(StyledLayerDescriptor)}.
*/
@Test
public void testDetermineGeometryType() {
TestCreateInternalDataSource ds = new TestCreateInternalDataSource();
assertEquals(GeometryTypeEnum.UNKNOWN, ds.callDetermineGeometryType(null));
// Create StyledLayerDescriptor
StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
NamedLayer namedLayer = styleFactory.createNamedLayer();
sld.addStyledLayer(namedLayer);
UserLayer userLayer = styleFactory.createUserLayer();
sld.addStyledLayer(userLayer);
Style style = styleFactory.createStyle();
namedLayer.addStyle(style);
List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
ftsList.add(fts);
Rule rule = styleFactory.createRule();
fts.rules().add(rule);
// Raster
RasterSymbolizer raster = DefaultSymbols.createDefaultRasterSymbolizer();
rule.symbolizers().add(raster);
assertEquals(GeometryTypeEnum.RASTER, ds.callDetermineGeometryType(sld));
// Polygon
rule.symbolizers().clear();
PolygonSymbolizer polygon = DefaultSymbols.createDefaultPolygonSymbolizer();
rule.symbolizers().add(polygon);
assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
// Line
rule.symbolizers().clear();
LineSymbolizer line = DefaultSymbols.createDefaultLineSymbolizer();
rule.symbolizers().add(line);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Point
rule.symbolizers().clear();
PointSymbolizer point = DefaultSymbols.createDefaultPointSymbolizer();
rule.symbolizers().add(point);
assertEquals(GeometryTypeEnum.POINT, ds.callDetermineGeometryType(sld));
// Add line to point
rule.symbolizers().add(line);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Add point, line
rule.symbolizers().clear();
rule.symbolizers().add(line);
rule.symbolizers().add(point);
assertEquals(GeometryTypeEnum.LINE, ds.callDetermineGeometryType(sld));
// Add polygon, line
rule.symbolizers().clear();
rule.symbolizers().add(point);
rule.symbolizers().add(polygon);
assertEquals(GeometryTypeEnum.POLYGON, ds.callDetermineGeometryType(sld));
}
use of org.geotools.styling.PointSymbolizer in project sldeditor by robward-scisys.
the class PointSymbolizerDetailsTest method testPointSymbolizerDetails.
/**
* Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
* Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
* Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#getFieldDataManager()}.
* Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#isDataPresent()}.
* Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#preLoadSymbol()}.
* Test method for {@link com.sldeditor.ui.detail.PointSymbolizerDetails#PointSymbolizerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
*/
@Test
public void testPointSymbolizerDetails() {
SelectedSymbol.destroyInstance();
PointSymbolizerDetails panel = new PointSymbolizerDetails();
panel.populate(null);
// Set up test data
StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
SelectedSymbol.getInstance().createNewSLD(sld);
NamedLayer namedLayer = DefaultSymbols.createNewNamedLayer();
String expectedNameLayerValue = "named layer test value";
namedLayer.setName(expectedNameLayerValue);
Style style = DefaultSymbols.createNewStyle();
String expectedNameStyleValue = "style test value";
style.setName(expectedNameStyleValue);
namedLayer.addStyle(style);
FeatureTypeStyle fts = DefaultSymbols.createNewFeatureTypeStyle();
String expectedNameFTSValue = "feature type style test value";
fts.setName(expectedNameFTSValue);
style.featureTypeStyles().add(fts);
Rule rule = DefaultSymbols.createNewRule();
String expectedRuleValue = "rule test value";
rule.setName(expectedRuleValue);
PointSymbolizer symbolizer = DefaultSymbols.createDefaultPointSymbolizer();
String expectedNameValue = "symbolizer test value";
symbolizer.setName(expectedNameValue);
rule.symbolizers().add(symbolizer);
fts.rules().add(rule);
sld.layers().add(namedLayer);
SelectedSymbol.getInstance().addNewStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyledLayer(namedLayer);
SelectedSymbol.getInstance().setStyle(style);
SelectedSymbol.getInstance().setFeatureTypeStyle(fts);
SelectedSymbol.getInstance().setRule(rule);
SelectedSymbol.getInstance().setSymbolizer(symbolizer);
panel.populate(SelectedSymbol.getInstance());
GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
assertNotNull(fieldDataManager);
panel.dataChanged(null);
FieldConfigString descriptionField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.DESCRIPTION);
assertNull(descriptionField);
assertTrue(panel.isDataPresent());
// Reset to default value
panel.preLoadSymbol();
}
use of org.geotools.styling.PointSymbolizer in project polymap4-core by Polymap4.
the class PointStyleSerializer method serialize.
@Override
public void serialize(PointStyle style, Style result) {
// default symbolizer
Graphic gr = sf.createGraphic(null, new Mark[] {}, null, null, null, null);
PointSymbolizer point = sf.createPointSymbolizer(gr, null);
// basics / init symbolizer
FeatureTypeStyle fts = defaultFeatureTypeStyle(result, style, point);
fts.setName(style.title.opt().orElse("PointStyle"));
fts.getDescription().setTitle(style.title.opt().orElse("PointStyle"));
accessor.set(rule -> (PointSymbolizer) rule.symbolizers().get(0));
serialize(style, fts);
// fill
style.fill.opt().ifPresent(fill -> {
// color
set(fts, style.fill.get().color, (value, sym) -> {
GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
// Mark
if (symbol instanceof Mark) {
((Mark) symbol).getFill().setColor(value);
} else // ExternalGraphic
if (symbol instanceof ExternalGraphic) {
addParam((ExternalGraphic) symbol, "fill", SLDSerializer2.toHexString(literalValue(value)));
addParam((ExternalGraphic) symbol, "fill-color", SLDSerializer2.toHexString(literalValue(value)));
} else {
throw new RuntimeException("Unhandled symbol type" + symbol);
}
});
// opacity
set(fts, style.fill.get().opacity, (value, sym) -> {
GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
// Mark
if (symbol instanceof Mark) {
((Mark) symbol).getFill().setOpacity(value);
} else // ExternalGraphic
if (symbol instanceof ExternalGraphic) {
addParam((ExternalGraphic) symbol, "fill-opacity", literalValue(value).toString());
} else {
throw new RuntimeException("Unhandled symbol type" + symbol);
}
});
});
// stroke
style.stroke.opt().ifPresent(stroke -> {
// color
set(fts, style.stroke.get().color, (value, sym) -> {
GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
if (symbol instanceof Mark) {
((Mark) symbol).getStroke().setColor(value);
} else if (symbol instanceof ExternalGraphic) {
addParam((ExternalGraphic) symbol, "stroke-color", SLDSerializer2.toHexString(literalValue(value)));
} else {
throw new RuntimeException("Unhandled symbol type" + symbol);
}
});
// opacity
set(fts, style.stroke.get().opacity, (value, sym) -> {
GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
if (symbol instanceof Mark) {
((Mark) symbol).getStroke().setOpacity(value);
} else if (symbol instanceof ExternalGraphic) {
addParam((ExternalGraphic) symbol, "stroke-opacity", literalValue(value).toString());
} else {
throw new RuntimeException("Unhandled symbol type" + symbol);
}
});
// width
set(fts, style.stroke.get().width, (value, sym) -> {
GraphicalSymbol symbol = sym.getGraphic().graphicalSymbols().get(0);
if (symbol instanceof Mark) {
((Mark) symbol).getStroke().setWidth(value);
} else if (symbol instanceof ExternalGraphic) {
addParam((ExternalGraphic) symbol, "stroke-width", literalValue(value).toString() + "px");
} else {
throw new RuntimeException("Unhandled symbol type" + symbol);
}
});
});
}
Aggregations