Search in sources :

Example 16 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class SLDExternalImages method externalGraphicSymbolVisitor.

/**
 * Find the SLD graphical symbols.
 *
 * @param resourceLocator the resource locator
 * @param sld the sld
 * @param externalImageList the external image list
 * @param process the process
 */
private static void externalGraphicSymbolVisitor(URL resourceLocator, StyledLayerDescriptor sld, List<String> externalImageList, ProcessGraphicSymbolInterface process) {
    if (sld == null) {
        return;
    }
    if (process == null) {
        return;
    }
    for (StyledLayer styledLayer : sld.layers()) {
        List<Style> styles = null;
        if (styledLayer instanceof NamedLayer) {
            NamedLayerImpl namedLayer = (NamedLayerImpl) styledLayer;
            styles = namedLayer.styles();
        } else if (styledLayer instanceof UserLayer) {
            UserLayerImpl userLayer = (UserLayerImpl) styledLayer;
            styles = userLayer.userStyles();
        }
        if (styles != null) {
            for (Style style : styles) {
                for (FeatureTypeStyle fts : style.featureTypeStyles()) {
                    for (Rule rule : fts.rules()) {
                        for (Symbolizer symbolizer : rule.symbolizers()) {
                            if (symbolizer instanceof PointSymbolizer) {
                                PointSymbolizer point = (PointSymbolizer) symbolizer;
                                if (point.getGraphic() != null) {
                                    process.processGraphicalSymbol(resourceLocator, point.getGraphic().graphicalSymbols(), externalImageList);
                                }
                            } else if (symbolizer instanceof LineSymbolizer) {
                                LineSymbolizer line = (LineSymbolizer) symbolizer;
                                updateStroke(resourceLocator, line.getStroke(), externalImageList, process);
                            } else if (symbolizer instanceof PolygonSymbolizer) {
                                PolygonSymbolizer polygon = (PolygonSymbolizer) symbolizer;
                                updateStroke(resourceLocator, polygon.getStroke(), externalImageList, process);
                                updateFill(resourceLocator, polygon.getFill(), externalImageList, process);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayer(org.geotools.styling.StyledLayer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) NamedLayerImpl(org.geotools.styling.NamedLayerImpl) Symbolizer(org.geotools.styling.Symbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) UserLayerImpl(org.geotools.styling.UserLayerImpl) LineSymbolizer(org.geotools.styling.LineSymbolizer) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) UserLayer(org.geotools.styling.UserLayer) NamedLayer(org.geotools.styling.NamedLayer)

Example 17 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class UserLayerDetails method updateSymbol.

/**
 * Update symbol.
 *
 * @param changedField the changed field
 */
private void updateSymbol(FieldIdEnum changedField) {
    if (!Controller.getInstance().isPopulating()) {
        UserLayer userLayer = getStyleFactory().createUserLayer();
        String name = fieldConfigVisitor.getText(FieldIdEnum.NAME);
        userLayer.setName(name);
        // Feature type constraints
        List<FeatureTypeConstraint> ftcList = fieldConfigVisitor.getFeatureTypeConstraint(FieldIdEnum.LAYER_FEATURE_CONSTRAINTS);
        if ((ftcList != null) && !ftcList.isEmpty()) {
            FeatureTypeConstraint[] ftcArray = new FeatureTypeConstraint[ftcList.size()];
            userLayer.setLayerFeatureConstraints(ftcList.toArray(ftcArray));
        }
        // Source
        GroupConfigInterface group = getGroup(GroupIdEnum.USER_LAYER_SOURCE);
        if (group != null) {
            MultiOptionGroup userLayerSourceGroup = (MultiOptionGroup) group;
            OptionGroup selectedOption = userLayerSourceGroup.getSelectedOptionGroup();
            switch(selectedOption.getId()) {
                case REMOTE_OWS_OPTION:
                    {
                        RemoteOWS remoteOWS = new RemoteOWSImpl();
                        String service = fieldConfigVisitor.getText(FieldIdEnum.REMOTE_OWS_SERVICE);
                        remoteOWS.setService(service);
                        String onlineResource = fieldConfigVisitor.getText(FieldIdEnum.REMOTE_OWS_ONLINERESOURCE);
                        remoteOWS.setOnlineResource(onlineResource);
                        userLayer.setRemoteOWS(remoteOWS);
                    }
                    break;
                case INLINE_FEATURE_OPTION:
                    {
                        String inlineFeatures = fieldConfigVisitor.getText(FieldIdEnum.INLINE_FEATURE);
                        if ((inlineFeatures != null) && (!inlineFeatures.isEmpty())) {
                            InlineFeatureUtils.setInlineFeatures(userLayer, inlineFeatures);
                        }
                    }
                    break;
                default:
                    break;
            }
        }
        StyledLayer existingStyledLayer = SelectedSymbol.getInstance().getStyledLayer();
        if (existingStyledLayer instanceof UserLayerImpl) {
            UserLayerImpl existingUserLayer = (UserLayerImpl) existingStyledLayer;
            for (Style style : existingUserLayer.userStyles()) {
                userLayer.addUserStyle(style);
            }
        }
        SelectedSymbol.getInstance().replaceStyledLayer(userLayer);
        // reduces creation of datasources
        if (changedField != null) {
            if (changedField == FieldIdEnum.INLINE_FEATURE) {
                DataSourceInterface dataSource = DataSourceFactory.getDataSource();
                if (dataSource != null) {
                    dataSource.updateUserLayers();
                }
            }
        }
        this.fireUpdateSymbol();
    }
}
Also used : RemoteOWS(org.geotools.styling.RemoteOWS) StyledLayer(org.geotools.styling.StyledLayer) RemoteOWSImpl(org.geotools.styling.RemoteOWSImpl) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) FeatureTypeConstraint(org.geotools.styling.FeatureTypeConstraint) OptionGroup(com.sldeditor.ui.detail.config.base.OptionGroup) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup) UserLayerImpl(org.geotools.styling.UserLayerImpl) Style(org.geotools.styling.Style) GroupConfigInterface(com.sldeditor.ui.detail.config.base.GroupConfigInterface) UserLayer(org.geotools.styling.UserLayer) MultiOptionGroup(com.sldeditor.ui.detail.config.base.MultiOptionGroup)

Example 18 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class FieldConfigInlineFeature method setTestValue.

/**
 * Sets the test string value.
 *
 * @param fieldId the field id
 * @param testValue the test value
 */
@Override
public void setTestValue(FieldIdEnum fieldId, String testValue) {
    UserLayer userLayer = DefaultSymbols.createNewUserLayer();
    InlineFeatureUtils.setInlineFeatures(userLayer, testValue);
    populateField(userLayer);
}
Also used : UserLayer(org.geotools.styling.UserLayer)

Example 19 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class MapRender method renderSymbol.

/**
 * Render symbol.
 *
 * @param mapContent the map content
 * @param styledLayer the styled layer
 * @param style the style
 */
private void renderSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) {
    for (Layer layer : mapContent.layers()) {
        mapContent.removeLayer(layer);
    }
    switch(geometryType) {
        case RASTER:
            {
                GridReaderLayer gridLayer = new GridReaderLayer(gridCoverage, (org.geotools.styling.Style) style);
                mapContent.addLayer(gridLayer);
                mapContent.getViewport().setBounds(gridLayer.getBounds());
                if (gridCoverage != null) {
                    mapPane.setDisplayArea(gridCoverage.getOriginalEnvelope());
                }
            }
            break;
        case POINT:
        case LINE:
        case POLYGON:
            {
                FeatureSource<SimpleFeatureType, SimpleFeature> tmpFeatureList = null;
                if (styledLayer instanceof UserLayer) {
                    if (userLayerFeatureListMap != null) {
                        tmpFeatureList = userLayerFeatureListMap.get(styledLayer);
                    }
                } else {
                    tmpFeatureList = featureList;
                }
                if (tmpFeatureList != null) {
                    mapContent.addLayer(new FeatureLayer(tmpFeatureList, (org.geotools.styling.Style) style));
                    try {
                        mapPane.setDisplayArea(tmpFeatureList.getBounds());
                    } catch (IOException e) {
                        ConsoleManager.getInstance().exception(this, e);
                    }
                }
            }
            break;
        default:
            break;
    }
    wmsEnvVarValues.setMapBounds(mapBounds);
    EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);
}
Also used : GridReaderLayer(org.geotools.map.GridReaderLayer) FeatureSource(org.geotools.data.FeatureSource) FeatureLayer(org.geotools.map.FeatureLayer) Style(org.opengis.style.Style) IOException(java.io.IOException) UserLayer(org.geotools.styling.UserLayer) GridReaderLayer(org.geotools.map.GridReaderLayer) FeatureLayer(org.geotools.map.FeatureLayer) Layer(org.geotools.map.Layer) UserLayer(org.geotools.styling.UserLayer) StyledLayer(org.geotools.styling.StyledLayer)

Example 20 with UserLayer

use of org.geotools.styling.UserLayer in project sldeditor by robward-scisys.

the class UserLayerDetailsTest method testUserLayerDetails.

/**
 * Test method for {@link com.sldeditor.ui.detail.UserLayerDetails#UserLayerDetails(com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 * Test method for {@link com.sldeditor.ui.detail.UserLayerDetails#populate(com.sldeditor.common.data.SelectedSymbol)}.
 * Test method for {@link com.sldeditor.ui.detail.UserLayerDetails#dataChanged(com.sldeditor.ui.detail.config.FieldId)}.
 * Test method for {@link com.sldeditor.ui.detail.UserLayerDetails#getFieldDataManager()}.
 * Test method for {@link com.sldeditor.ui.detail.UserLayerDetails#isDataPresent()}.
 * Test method for {@link com.sldeditor.ui.detail.UserLayerDetails#preLoadSymbol()}.
 */
@Test
public void testUserLayerDetails() {
    UserLayerDetails panel = new UserLayerDetails();
    panel.populate(null);
    // Set up test data
    StyledLayerDescriptor sld = DefaultSymbols.createNewSLD();
    SelectedSymbol.getInstance().createNewSLD(sld);
    UserLayer userLayer = DefaultSymbols.createNewUserLayer();
    String expectedUserValue = "user layer test value";
    userLayer.setName(expectedUserValue);
    userLayer.addUserStyle(DefaultSymbols.createNewStyle());
    sld.layers().add(userLayer);
    SelectedSymbol.getInstance().addNewStyledLayer(userLayer);
    SelectedSymbol.getInstance().setStyledLayer(userLayer);
    panel.populate(SelectedSymbol.getInstance());
    panel.dataChanged(null);
    GraphicPanelFieldManager fieldDataManager = panel.getFieldDataManager();
    assertNotNull(fieldDataManager);
    panel.dataChanged(FieldIdEnum.INLINE_FEATURE);
    FieldConfigString nameField = (FieldConfigString) fieldDataManager.get(FieldIdEnum.NAME);
    assertTrue(expectedUserValue.compareTo(nameField.getStringValue()) == 0);
    assertTrue(panel.isDataPresent());
    // Reset to default value
    panel.preLoadSymbol();
    assertTrue("".compareTo(nameField.getStringValue()) == 0);
}
Also used : StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) UserLayerDetails(com.sldeditor.ui.detail.UserLayerDetails) FieldConfigString(com.sldeditor.ui.detail.config.FieldConfigString) UserLayer(org.geotools.styling.UserLayer) GraphicPanelFieldManager(com.sldeditor.ui.detail.GraphicPanelFieldManager) Test(org.junit.Test)

Aggregations

UserLayer (org.geotools.styling.UserLayer)29 Test (org.junit.Test)17 DummyInlineSLDFile (com.sldeditor.test.unit.datasource.impl.DummyInlineSLDFile)10 InLineFeatureModel (com.sldeditor.ui.detail.config.inlinefeature.InLineFeatureModel)8 Style (org.geotools.styling.Style)6 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)6 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)4 NamedLayer (org.geotools.styling.NamedLayer)4 Rule (org.geotools.styling.Rule)4 StyledLayer (org.geotools.styling.StyledLayer)4 UndoEvent (com.sldeditor.common.undo.UndoEvent)3 IOException (java.io.IOException)3 FeatureSource (org.geotools.data.FeatureSource)3 LineSymbolizer (org.geotools.styling.LineSymbolizer)3 PointSymbolizer (org.geotools.styling.PointSymbolizer)3 PolygonSymbolizer (org.geotools.styling.PolygonSymbolizer)3 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)3 SLDData (com.sldeditor.common.data.SLDData)2 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)2 FieldConfigInlineFeature (com.sldeditor.ui.detail.config.inlinefeature.FieldConfigInlineFeature)2