Java Code Examples for org.geotools.styling.Graphic#setDisplacement()
The following examples show how to use
org.geotools.styling.Graphic#setDisplacement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetMinimumVersionTest.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** Test method for PointFillDetails */ @Test public void testPointGetMinimumVersion() { PointFillDetails details = new PointFillDetails(); details.getMinimumVersion(null, null, null); Graphic graphic = styleFactory.createDefaultGraphic(); graphic.setDisplacement(styleFactory.createDisplacement(ff.literal(6.0), ff.literal(7.0))); graphic.setAnchorPoint(styleFactory.anchorPoint(ff.literal(6.0), ff.literal(7.0))); List<VendorOptionPresent> vendorOptionsPresentList = null; Object parentObj = null; details.getMinimumVersion(parentObj, graphic, vendorOptionsPresentList); vendorOptionsPresentList = new ArrayList<VendorOptionPresent>(); details.getMinimumVersion(parentObj, graphic, vendorOptionsPresentList); assertTrue(vendorOptionsPresentList.size() == 0); }
Example 2
Source File: SimpleMarkerSymbol.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Convert. * * @param element the element * @return the graphic marker list */ @Override public List<Graphic> convert(JsonElement element) { if(element == null) return null; JsonObject obj = element.getAsJsonObject(); List<Graphic> markList = new ArrayList<Graphic>(); double angle = getDouble(obj, CommonSymbolKeys.ANGLE); double outlineSize = getDouble(obj, SimpleMarkerSymbolKeys.OUTLINE_SIZE); double size = getDouble(obj, CommonSymbolKeys.SIZE); int style = getInt(obj, CommonSymbolKeys.STYLE); double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET); double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET); Expression markerColour = getColour(obj.get(CommonSymbolKeys.COLOUR)); Expression outlineColour = getColour(obj.get(SimpleMarkerSymbolKeys.OUTLINE_COLOUR)); Expression wellKnownName = ff.literal(styleMap.get(style)); Stroke stroke = null; if(outlineSize > 0.0) { stroke = styleFactory.createStroke(outlineColour, ff.literal(outlineSize)); } Fill fill = styleFactory.createFill(markerColour); Mark mark = styleFactory.createMark(wellKnownName, stroke, fill, ff.literal(size), ff.literal(angle)); Expression expressionOpacity = null; ExternalGraphic[] externalGraphics = null; Symbol[] symbols = null; Mark[] marks = new Mark[1]; marks[0] = mark; Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, expressionOpacity, ff.literal(size), ff.literal(angle)); // Set offset if((xOffset > 0.0) && (yOffset > 0.0)) { Displacement displacement = styleFactory.displacement(ff.literal(xOffset), ff.literal(yOffset)); graphic.setDisplacement(displacement); } markList.add(graphic); return markList; }
Example 3
Source File: CharacterMarkerSymbol.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Convert. * * @param element the element * @return the marker graphic */ @Override public List<Graphic> convert(JsonElement element) { if(element == null) return null; JsonObject obj = element.getAsJsonObject(); List<Graphic> markerList = new ArrayList<Graphic>(); double angle = getDouble(obj, CommonSymbolKeys.ANGLE); double symbolSize = getDouble(obj, CommonSymbolKeys.SIZE); double xOffset = getDouble(obj, CommonSymbolKeys.X_OFFSET); double yOffset = getDouble(obj, CommonSymbolKeys.Y_OFFSET); JsonElement fontElement = obj.get(CharacterMarkerSymbolKeys.FONT); if(fontElement != null) { JsonObject fontObj = fontElement.getAsJsonObject(); String fontName = getString(fontObj, FontSymbolKeys.FONT_NAME); int code = getInt(obj, CharacterMarkerSymbolKeys.CHARACTER_INDEX); Expression wellKnownName = ff.literal(String.format("ttf://%s#%s", fontName, code)); // Create colour Expression colour = getColour(obj.get(CommonSymbolKeys.COLOUR)); Fill fill = styleFactory.createFill(colour); Stroke stroke = null; Mark mark = styleFactory.mark(wellKnownName, fill, stroke); ExternalGraphic [] externalGraphics = null; Mark[] marks = new Mark[1]; marks[0] = mark; Symbol[] symbols = null; Expression opacity = null; Expression rotation = ff.literal(angle); Expression size = ff.literal(symbolSize); Graphic graphic = styleFactory.createGraphic(externalGraphics, marks, symbols, opacity, size, rotation); // Displacement (offsets) if((xOffset > 0.0) && (yOffset > 0.0)) { Expression expressionX = ff.literal(xOffset); Expression expressionY = ff.literal(yOffset); Displacement displacement = styleFactory.createDisplacement(expressionX, expressionY); graphic.setDisplacement(displacement); } markerList.add(graphic); } return markerList; }
Example 4
Source File: PolygonFillDetailsTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Test method for {@link * com.sldeditor.ui.detail.PolygonFillDetailsTest#PolygonFillDetailsTest(java.lang.Class, * com.sldeditor.filter.v2.function.FunctionNameInterface)}. */ @Test public void testFillDetailsPolygon() { StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(); PolygonFillDetails panel = new PolygonFillDetails(); 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 expectedNameValue = "rule test value"; rule.setName(expectedNameValue); PolygonSymbolizer symbolizer = DefaultSymbols.createDefaultPolygonSymbolizer(); 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); double expectedAngle = 14.5; FieldConfigDouble angleField = (FieldConfigDouble) fieldDataManager.get(FieldIdEnum.ANGLE); angleField.populateField(expectedAngle); FieldConfigSlider opacityField = (FieldConfigSlider) fieldDataManager.get(FieldIdEnum.OVERALL_OPACITY); double opacity = 0.15; opacityField.populateField(opacity); panel.dataChanged(FieldIdEnum.UNKNOWN); double actualValue = angleField.getDoubleValue(); assertTrue(Math.abs(actualValue - expectedAngle) < 0.01); assertTrue(panel.isDataPresent()); actualValue = opacityField.getDoubleValue(); assertTrue(Math.abs(actualValue - opacity) < 0.01); // Reset to default value panel.preLoadSymbol(); actualValue = angleField.getDoubleValue(); assertTrue(Math.abs(actualValue - 0.0) < 0.01); actualValue = opacityField.getDoubleValue(); assertTrue(Math.abs(actualValue - 1.0) < 0.01); // Increase the coverage, set the fill Fill fill = styleFactory.createFill(ff.literal("#123456")); Graphic graphic = styleFactory.createDefaultGraphic(); fill.setGraphicFill(graphic); symbolizer.setFill(fill); panel.populate(SelectedSymbol.getInstance()); Graphic graphic2 = styleFactory.createDefaultGraphic(); graphic2.setDisplacement(styleFactory.createDisplacement(ff.literal(6.0), ff.literal(7.0))); graphic2.setAnchorPoint(styleFactory.anchorPoint(ff.literal(6.0), ff.literal(7.0))); Fill fill2 = styleFactory.createFill(ff.literal("#123456")); fill2.setGraphicFill(graphic2); symbolizer.setFill(fill2); panel.populate(SelectedSymbol.getInstance()); symbolizer.setFill(null); panel.populate(SelectedSymbol.getInstance()); }