branch feature/6944 updated (f9fa186 -> 82b697f)
This is an automated email from the git hooks/post-receive script. New change to branch feature/6944 in repository observe. See http://git.codelutin.com/observe.git from f9fa186 add Date on map new 82b697f use style file for map The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 82b697f0d6ae0bedb222abd214b196c6f219bd70 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri Apr 17 15:16:05 2015 +0200 use style file for map Summary of changes: .../main/java/fr/ird/observe/ObserveConfig.java | 5 + .../java/fr/ird/observe/ObserveConfigOption.java | 12 +- .../ird/observe/ui/actions/ShowConfigAction.java | 1 + .../ui/content/open/impl/seine/TripMapHandler.java | 399 +++++++++++++++++++++ .../open/impl/seine/TripSeineUIHandler.java | 365 +------------------ .../resources/i18n/observe-swing_en_GB.properties | 1 + .../resources/i18n/observe-swing_es_ES.properties | 1 + .../resources/i18n/observe-swing_fr_FR.properties | 3 +- .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.dbf | Bin .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.prj | 0 .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.sbn | Bin .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.sbx | Bin .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.shp | Bin .../shapeFiles/zee/World_EEZ_v8_2014.shp.xml | 0 .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.shx | Bin observe-swing/src/main/resources/map/style.xml | 126 +++++++ 16 files changed, 556 insertions(+), 357 deletions(-) create mode 100644 observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripMapHandler.java rename observe-swing/src/main/resources/{ => map}/shapeFiles/zee/World_EEZ_v8_2014.dbf (100%) rename observe-swing/src/main/resources/{ => map}/shapeFiles/zee/World_EEZ_v8_2014.prj (100%) rename observe-swing/src/main/resources/{ => map}/shapeFiles/zee/World_EEZ_v8_2014.sbn (100%) rename observe-swing/src/main/resources/{ => map}/shapeFiles/zee/World_EEZ_v8_2014.sbx (100%) rename observe-swing/src/main/resources/{ => map}/shapeFiles/zee/World_EEZ_v8_2014.shp (100%) rename observe-swing/src/main/resources/{ => map}/shapeFiles/zee/World_EEZ_v8_2014.shp.xml (100%) rename observe-swing/src/main/resources/{ => map}/shapeFiles/zee/World_EEZ_v8_2014.shx (100%) create mode 100644 observe-swing/src/main/resources/map/style.xml -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/6944 in repository observe. See http://git.codelutin.com/observe.git commit 82b697f0d6ae0bedb222abd214b196c6f219bd70 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri Apr 17 15:16:05 2015 +0200 use style file for map --- .../main/java/fr/ird/observe/ObserveConfig.java | 5 + .../java/fr/ird/observe/ObserveConfigOption.java | 12 +- .../ird/observe/ui/actions/ShowConfigAction.java | 1 + .../ui/content/open/impl/seine/TripMapHandler.java | 399 +++++++++++++++++++++ .../open/impl/seine/TripSeineUIHandler.java | 365 +------------------ .../resources/i18n/observe-swing_en_GB.properties | 1 + .../resources/i18n/observe-swing_es_ES.properties | 1 + .../resources/i18n/observe-swing_fr_FR.properties | 3 +- .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.dbf | Bin .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.prj | 0 .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.sbn | Bin .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.sbx | Bin .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.shp | Bin .../shapeFiles/zee/World_EEZ_v8_2014.shp.xml | 0 .../{ => map}/shapeFiles/zee/World_EEZ_v8_2014.shx | Bin observe-swing/src/main/resources/map/style.xml | 126 +++++++ 16 files changed, 556 insertions(+), 357 deletions(-) diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveConfig.java b/observe-swing/src/main/java/fr/ird/observe/ObserveConfig.java index b8909dc..ec8ab64 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveConfig.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveConfig.java @@ -835,6 +835,11 @@ public class ObserveConfig extends ApplicationConfig implements IObserveConfig { return layers; } + public File getMapStyleFile() { + File result = getOptionAsFile(ObserveConfigOption.MAP_STYLE_FILE.key); + return result; + } + public String[] getUnsavables() { if (unsavables == null) { List<String> tmp = new ArrayList<String>(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ObserveConfigOption.java b/observe-swing/src/main/java/fr/ird/observe/ObserveConfigOption.java index ad47893..27731d2 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ObserveConfigOption.java +++ b/observe-swing/src/main/java/fr/ird/observe/ObserveConfigOption.java @@ -630,7 +630,7 @@ public enum ObserveConfigOption implements ConfigOptionDef { MAP_LAYER_1( "map.layer1.path", n("observe.config.map.layer1.description"), - "${user.home}/.observe/shapeFiles/zee/World_EEZ_v8_2014.shp", + "${user.home}/.observe/map/shapeFiles/zee/World_EEZ_v8_2014.shp", File.class, false, false @@ -715,7 +715,15 @@ public enum ObserveConfigOption implements ConfigOptionDef { File.class, false, false - ); + ), + /** style Maps */ + MAP_STYLE_FILE( + "map.style.path", + n("observe.config.map.style.description"), + "${user.home}/.observe/map/style.xml", + File.class, + false, + false); public static List<ObserveConfigOption> MAP_LAYERS = ImmutableList.of(MAP_LAYER_1, MAP_LAYER_2, MAP_LAYER_3, MAP_LAYER_4, MAP_LAYER_5, MAP_LAYER_6, MAP_LAYER_7, MAP_LAYER_8, MAP_LAYER_9, MAP_LAYER_10); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java b/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java index 7bf7367..95fcad1 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/actions/ShowConfigAction.java @@ -337,6 +337,7 @@ public class ShowConfigAction extends AbstractAction { for (ObserveConfigOption layerOption : ObserveConfigOption.MAP_LAYERS) { helper.addOption(layerOption); } + helper.addOption(ObserveConfigOption.MAP_STYLE_FILE); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripMapHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripMapHandler.java new file mode 100644 index 0000000..a00e296 --- /dev/null +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripMapHandler.java @@ -0,0 +1,399 @@ +package fr.ird.observe.ui.content.open.impl.seine; + +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.LineString; +import com.vividsolutions.jts.geom.MultiPoint; +import fr.ird.observe.DataService; +import fr.ird.observe.ObserveConfig; +import fr.ird.observe.db.DataSource; +import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.entities.constants.seine.SchoolType; +import fr.ird.observe.tripMap.TripMapPoint; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.geotools.data.FileDataStore; +import org.geotools.data.FileDataStoreFinder; +import org.geotools.data.simple.SimpleFeatureSource; +import org.geotools.factory.CommonFactoryFinder; +import org.geotools.feature.DefaultFeatureCollection; +import org.geotools.feature.simple.SimpleFeatureBuilder; +import org.geotools.feature.simple.SimpleFeatureTypeBuilder; +import org.geotools.geometry.DirectPosition2D; +import org.geotools.geometry.jts.JTSFactoryFinder; +import org.geotools.geometry.jts.ReferencedEnvelope; +import org.geotools.map.FeatureLayer; +import org.geotools.map.Layer; +import org.geotools.map.MapContent; +import org.geotools.referencing.CRS; +import org.geotools.styling.NamedLayer; +import org.geotools.styling.SLD; +import org.geotools.styling.SLDParser; +import org.geotools.styling.Style; +import org.geotools.styling.StyleFactory; +import org.geotools.styling.StyledLayer; +import org.geotools.styling.StyledLayerDescriptor; +import org.geotools.styling.UserLayer; +import org.geotools.swing.JMapPane; +import org.opengis.feature.simple.SimpleFeature; +import org.opengis.feature.simple.SimpleFeatureType; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.io.File; +import java.io.FileNotFoundException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.List; + +/** + * @author Sylvain Bavencoff - bavencoff@codelutin.com + */ +public class TripMapHandler { + + public static final String TRIP_LINES_LAYER_NAME = "Trip lines"; + public static final String TRIP_POINTS_LAYER_NAME = "Trip points"; + + + private static final Log log = LogFactory.getLog(TripMapHandler.class); + + protected JMapPane tripMapUI; + protected ObserveConfig config; + protected MapContent mapContent; + protected ReferencedEnvelope tripArea; + protected List<TripMapPoint> tripMapPoints; + + public TripMapHandler(JMapPane tripMapUI, ObserveConfig config) { + this.tripMapUI = tripMapUI; + this.config = config; + + tripMapUI.setBackground(config.getMapBackgroundColor()); + + MouseMapListener mouseMapListener = new MouseMapListener(); + tripMapUI.addMouseWheelListener(mouseMapListener); + tripMapUI.addMouseMotionListener(mouseMapListener); + tripMapUI.addMouseListener(mouseMapListener); + + } + + public void doOpenMap(DataService dataService, DataSource source, String tripId) { + + getTipMapPoints(dataService, source, tripId); + + tripMapUI.setMapContent(getMapContent()); + tripMapUI.setDisplayArea(tripArea); + } + + protected List<TripMapPoint> getTipMapPoints(DataService dataService, DataSource source, String tripId) { + + if (tripMapPoints == null) { + try { + tripMapPoints = dataService.loadTripMapActivityPoints(source, tripId); + } catch (DataSourceException e) { + if (log.isErrorEnabled()) { + log.error("error in loadTripMapActivityPoints", e); + } + } + } + return tripMapPoints; + + } + + public MapContent getMapContent() { + if (/*mapContent == null &&*/ tripMapPoints != null) { + try { + + mapContent = new MapContent(); + mapContent.setTitle("Un titre"); + + for (File layerFile : config.getMapLayerFiles()) { + FileDataStore store = FileDataStoreFinder.getDataStore(layerFile); + SimpleFeatureSource featureSource = store.getFeatureSource(); + Style style = SLD.createSimpleStyle(featureSource.getSchema()); + Layer layer = new FeatureLayer(featureSource, style); + mapContent.addLayer(layer); + } + + StyledLayerDescriptor styledLayerDescriptor = importStyledLayerDescriptor(); + SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); + + GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); + + SimpleFeatureTypeBuilder lineFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); + lineFeatureTypeBuilder.setName("lineBuilder"); + lineFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); + lineFeatureTypeBuilder.add("line", LineString.class); + lineFeatureTypeBuilder.add("label", String.class); + lineFeatureTypeBuilder.add("type", String.class); + + SimpleFeatureType lineFeatureType = lineFeatureTypeBuilder.buildFeatureType(); + SimpleFeatureBuilder lineBuilder = new SimpleFeatureBuilder(lineFeatureType); + + DefaultFeatureCollection linesFeatures = new DefaultFeatureCollection(); + + List<Coordinate> coordinatesByDay = null; + + TripMapPoint previousPoint = null; + + for (TripMapPoint point : tripMapPoints) { + if (previousPoint == null) { + coordinatesByDay = Lists.newLinkedList(); + } else if (!DateUtils.isSameDay(previousPoint.getTime(), point.getTime())) { + + if (coordinatesByDay.size() > 1) { + LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); + lineBuilder.add(line); + lineBuilder.add(dateFormat.format(previousPoint.getTime())); + lineBuilder.add("tripDay"); + SimpleFeature feature = lineBuilder.buildFeature(null); + + linesFeatures.add(feature); + } + + + Coordinate[] coordinates = { + new Coordinate(previousPoint.getLongitude(), previousPoint.getLatitude()), + new Coordinate(point.getLongitude(), point.getLatitude()), + }; + LineString lineBetweenTwoDays = geometryFactory.createLineString(coordinates); + lineBuilder.add(lineBetweenTwoDays); + lineBuilder.add(DateFormat.getDateInstance().format(previousPoint.getTime())); + lineBuilder.add("tripBetweenTwoDays"); + linesFeatures.add(lineBuilder.buildFeature(null)); + + coordinatesByDay = Lists.newLinkedList(); + } + + Coordinate coordinate = new Coordinate(point.getLongitude(), point.getLatitude()); + coordinatesByDay.add(coordinate); + + previousPoint = point; + } + + if (coordinatesByDay.size() > 1) { + LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); + lineBuilder.add(line); + lineBuilder.add(dateFormat.format(previousPoint.getTime())); + lineBuilder.add("tripDay"); + linesFeatures.add(lineBuilder.buildFeature(null)); + } + + Style styleLines = findStyle(styledLayerDescriptor, TRIP_LINES_LAYER_NAME, null); + Layer layerLines = new FeatureLayer(linesFeatures, styleLines); + mapContent.addLayer(layerLines); + + + // add Point + SimpleFeatureTypeBuilder pointFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); + pointFeatureTypeBuilder.setName("point Builder"); + pointFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); + pointFeatureTypeBuilder.add("points", MultiPoint.class); + pointFeatureTypeBuilder.add("schoolType", String.class); + + SimpleFeatureType pointFeatureType = pointFeatureTypeBuilder.buildFeatureType(); + SimpleFeatureBuilder pointBuilder = new SimpleFeatureBuilder(pointFeatureType); + + DefaultFeatureCollection pointsFeatures = new DefaultFeatureCollection(); + + for (final SchoolType schoolType : SchoolType.values()) { + + Iterable<Coordinate> coordinates = Iterables.transform( + Iterables.filter(tripMapPoints, new Predicate<TripMapPoint>() { + @Override + public boolean apply(TripMapPoint input) { + return input.getSchoolType() == schoolType; + } + }), + new Function<TripMapPoint, Coordinate>() { + @Override + public Coordinate apply(TripMapPoint input) { + return new Coordinate(input.getLongitude(), input.getLatitude()); + } + }); + + MultiPoint points = geometryFactory.createMultiPoint(Lists.newArrayList(coordinates).toArray(new Coordinate[0])); + pointBuilder.add(points); + pointBuilder.add(schoolType.name()); + pointsFeatures.add(pointBuilder.buildFeature(null)); + } + + Style stylePoints = findStyle(styledLayerDescriptor, TRIP_POINTS_LAYER_NAME, null); + Layer pointsLayer = new FeatureLayer(pointsFeatures, stylePoints); + mapContent.addLayer(pointsLayer); + // set zoom + + tripArea = new ReferencedEnvelope(); + for (TripMapPoint point : tripMapPoints) { + tripArea.expandToInclude(new DirectPosition2D(point.getLongitude(), point.getLatitude())); + } + tripArea.expandBy(1.1); + + + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("error in getMapContent", e); + } + } + } + + return mapContent; + } + + protected StyledLayerDescriptor importStyledLayerDescriptor() throws FileNotFoundException { + File styleFile = config.getMapStyleFile(); + StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory(null); + + SLDParser stylereader = new SLDParser(styleFactory, styleFile); + + StyledLayerDescriptor styledLayerDescriptor = stylereader.parseSLD(); + + return styledLayerDescriptor; + } + + protected Style findStyle(StyledLayerDescriptor styledLayerDescriptor, final String layerName, String styleName) throws Exception { + + Optional<StyledLayer> styledLayerOptional = Iterables.tryFind(styledLayerDescriptor.layers(), new Predicate<StyledLayer>() { + @Override + public boolean apply(StyledLayer input) { + return input.getName().equals(layerName); + } + }); + + Style style = null; + + if (styledLayerOptional.isPresent()) { + + StyledLayer styledLayer = styledLayerOptional.get(); + + Style[] styles = new Style[0]; + + if (styledLayer instanceof UserLayer) { + + styles = ((UserLayer) styledLayer).getUserStyles(); + + } else if (styledLayer instanceof NamedLayer) { + + styles = ((NamedLayer) styledLayer).getStyles(); + + } + + if (styles.length == 1) { + + style = styles[0]; + + } else { + + for (Style styleTmp : styles) { + + if (StringUtils.isBlank(styleName) && styleTmp.isDefault() + || styleTmp.getName().equals(styleName)) { + + style = styleTmp; + } + } + } + } + + if (style == null) { + throw new Exception(String.format("No style found for layer name '%s' and style name '%s'", layerName, styleName)); + } + + return style; + } + + + private class MouseMapListener implements MouseWheelListener, MouseListener, MouseMotionListener { + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + int notches = e.getWheelRotation(); + double scale = notches; + + if (log.isDebugEnabled()) { + log.debug(String.format("Map mouse zoom (rotation : %s, scale : %s)", notches, scale)); + } + + ReferencedEnvelope displayArea = tripMapUI.getDisplayArea(); + displayArea.expandBy(scale); + if (! displayArea.isEmpty()) { + tripMapUI.setDisplayArea(displayArea); + } + } + + @Override + public void mouseClicked(MouseEvent e) { + + } + + protected Point2D startPointInWorld; + protected AffineTransform startScreenToWorldTransform; + protected ReferencedEnvelope startDisplayArea; + + @Override + public void mousePressed(MouseEvent e) { + startMove(e.getPoint()); + } + + @Override + public void mouseReleased(MouseEvent e) { + endMove(e.getPoint()); + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + + @Override + public void mouseDragged(MouseEvent e) { +// endMove(e.getPoint()); + } + + @Override + public void mouseMoved(MouseEvent e) { + + } + + protected void startMove(Point2D startPointInScreen) { + startDisplayArea = tripMapUI.getDisplayArea(); + startScreenToWorldTransform = tripMapUI.getScreenToWorldTransform(); + startPointInWorld = new Point2D.Double(); + startScreenToWorldTransform.transform(startPointInScreen, startPointInWorld); + } + + protected void endMove(Point2D endPointInScreen) { + Point2D endPointInWorld = new Point2D.Double(); + startScreenToWorldTransform.transform(endPointInScreen, endPointInWorld); + double transX = startPointInWorld.getX() - endPointInWorld.getX(); + double transY = startPointInWorld.getY() - endPointInWorld.getY(); + + ReferencedEnvelope endDisplayArea = new ReferencedEnvelope(startDisplayArea); + endDisplayArea.translate(transX, transY); + + tripMapUI.setDisplayArea(endDisplayArea); + if (log.isDebugEnabled()) { + log.debug(String.format("Translate (x : %s, y : %s)", transX, transY)); + } + } + } + + + +} diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java index d7ba4e0..180233f 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/TripSeineUIHandler.java @@ -21,14 +21,6 @@ */ package fr.ird.observe.ui.content.open.impl.seine; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.MultiPoint; import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveDAOHelper; @@ -36,41 +28,14 @@ import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.db.util.TopiaExecutor2; -import fr.ird.observe.entities.constants.seine.SchoolType; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.seine.Routes; import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.tripMap.TripMapPoint; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.open.ContentOpenableUIHandler; import fr.ird.observe.ui.content.open.ContentOpenableUIModel; -import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.geotools.data.FileDataStore; -import org.geotools.data.FileDataStoreFinder; -import org.geotools.data.simple.SimpleFeatureSource; -import org.geotools.factory.CommonFactoryFinder; -import org.geotools.feature.DefaultFeatureCollection; -import org.geotools.feature.FeatureCollection; -import org.geotools.feature.simple.SimpleFeatureBuilder; -import org.geotools.feature.simple.SimpleFeatureTypeBuilder; -import org.geotools.geometry.DirectPosition2D; -import org.geotools.geometry.jts.JTSFactoryFinder; -import org.geotools.geometry.jts.ReferencedEnvelope; -import org.geotools.map.FeatureLayer; -import org.geotools.map.Layer; -import org.geotools.map.MapContent; -import org.geotools.referencing.CRS; -import org.geotools.styling.Fill; -import org.geotools.styling.Font; -import org.geotools.styling.LinePlacementImpl; -import org.geotools.styling.LineSymbolizer; -import org.geotools.styling.SLD; -import org.geotools.styling.Stroke; -import org.geotools.styling.Style; -import org.geotools.styling.StyleFactory; -import org.geotools.styling.TextSymbolizer; import org.geotools.swing.JMapPane; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -78,27 +43,11 @@ import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.opengis.feature.simple.SimpleFeature; -import org.opengis.feature.simple.SimpleFeatureType; -import org.opengis.filter.FilterFactory; -import org.opengis.referencing.FactoryException; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.awt.Color; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.awt.geom.AffineTransform; -import java.awt.geom.Point2D; -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; import java.util.Date; -import java.util.List; import static org.nuiton.i18n.I18n.n; import static org.nuiton.i18n.I18n.t; @@ -112,6 +61,8 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { /** Logger */ static private final Log log = LogFactory.getLog(TripSeineUIHandler.class); + protected TripMapHandler tripMapHandler; + public TripSeineUIHandler(TripSeineUI ui) { super(ui, DataContextType.Program, @@ -153,7 +104,7 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { ContentMode mode = computeContentMode(); String programId = getSelectedParentId(); - String tripId = getSelectedId(); + final String tripId = getSelectedId(); if (log.isInfoEnabled()) { log.info(prefix + "programId = " + programId); @@ -191,27 +142,26 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { } - + JMapPane tripMap = getUi().getTripMap(); ObserveConfig config = ui.getContextValue(ObserveConfig.class); - final JMapPane tripMap = getUi().getTripMap(); + tripMapHandler = new TripMapHandler(tripMap, config); + + - tripMap.setBackground(config.getMapBackgroundColor()); getUi().getTripSeineTabPane().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JTabbedPane tripSeineTabPane = (JTabbedPane) e.getSource(); - if (tripSeineTabPane.getSelectedComponent() == tripMap) { - doOpenMap(); + TripSeineUI ui = getUi(); + if (tripSeineTabPane.getSelectedComponent() == ui.getTripMap()) { + tripMapHandler.doOpenMap(ui.getDataService(), ui.getDataSource(), tripId); } } }); - MouseMapListener mouseMapListener = new MouseMapListener(); - tripMap.addMouseWheelListener(mouseMapListener); - tripMap.addMouseMotionListener(mouseMapListener); - tripMap.addMouseListener(mouseMapListener); + finalizeOpenUI(mode, create); } @@ -370,297 +320,4 @@ public class TripSeineUIHandler extends ContentOpenableUIHandler<TripSeine> { } - public void doOpenMap() { - JMapPane tripMap = getUi().getTripMap(); - tripMap.setMapContent(getMapContent()); - tripMap.setDisplayArea(tripArea); - tripMap.invalidate(); - } - - protected MapContent mapContent; - protected ReferencedEnvelope tripArea; - - public MapContent getMapContent() { -// if (mapContent == null) { - try { - - mapContent = new MapContent(); - mapContent.setTitle("Un titre"); - - // add map layers - ObserveConfig config = ui.getContextValue(ObserveConfig.class); - - for (File layerFile : config.getMapLayerFiles()) { - FileDataStore store = FileDataStoreFinder.getDataStore(layerFile); - SimpleFeatureSource featureSource = store.getFeatureSource(); - Style style = SLD.createSimpleStyle(featureSource.getSchema()); - Layer layer = new FeatureLayer(featureSource, style); - mapContent.addLayer(layer); - } - - - SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); - - // add lines - DataService dataService = getDataService(); - DataSource source = getDataSource(); - String tripId = getSelectedId(); - - List<TripMapPoint> tripMapPoints = dataService.loadTripMapActivityPoints(source, tripId); - - GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); - - SimpleFeatureTypeBuilder lineFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); - lineFeatureTypeBuilder.setName("lineBuilder"); - lineFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); - lineFeatureTypeBuilder.add("line", LineString.class); - lineFeatureTypeBuilder.add("label", String.class); - - SimpleFeatureType lineFeatureType = lineFeatureTypeBuilder.buildFeatureType(); - SimpleFeatureBuilder lineBuilder = new SimpleFeatureBuilder(lineFeatureType); - - DefaultFeatureCollection featuresDays = new DefaultFeatureCollection(); - DefaultFeatureCollection featuresBetweenTowDays = new DefaultFeatureCollection(); - - List<Coordinate> coordinatesByDay = null; - - TripMapPoint previousPoint = null; - - for (TripMapPoint point : tripMapPoints) { - if (previousPoint == null) { - coordinatesByDay = Lists.newLinkedList(); - } else if (!DateUtils.isSameDay(previousPoint.getTime(), point.getTime())) { - - if (coordinatesByDay.size() > 1) { - LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); - lineBuilder.add(line); - lineBuilder.add(dateFormat.format(previousPoint.getTime())); - SimpleFeature feature = lineBuilder.buildFeature(null); - - featuresDays.add(feature); - } - - - Coordinate[] coordinates = { - new Coordinate(previousPoint.getLongitude(), previousPoint.getLatitude()), - new Coordinate(point.getLongitude(), point.getLatitude()), - }; - LineString lineBetweenTwoDays = geometryFactory.createLineString(coordinates); - lineBuilder.add(lineBetweenTwoDays); - lineBuilder.add(DateFormat.getDateInstance().format(previousPoint.getTime())); - featuresBetweenTowDays.add(lineBuilder.buildFeature(null)); - - coordinatesByDay = Lists.newLinkedList(); - } - - Coordinate coordinate = new Coordinate(point.getLongitude(), point.getLatitude()); - coordinatesByDay.add(coordinate); - - previousPoint = point; - } - - if (coordinatesByDay.size() > 1) { - LineString line = geometryFactory.createLineString(coordinatesByDay.toArray(new Coordinate[0])); - lineBuilder.add(line); - lineBuilder.add(dateFormat.format(previousPoint.getTime())); - featuresDays.add(lineBuilder.buildFeature(null)); - } - - Layer layerDays = new FeatureLayer(featuresDays, getStyleLineDay()); - Layer layerBetweenTowDays = new FeatureLayer(featuresBetweenTowDays, getStyleLineBetweenTwoDays()); - mapContent.addLayer(layerDays); - mapContent.addLayer(layerBetweenTowDays); - - // add Point - FeatureCollection featurePointsLibres = generateFeaturePoints(tripMapPoints, SchoolType.libre); - FeatureCollection featurePointsObjets = generateFeaturePoints(tripMapPoints, SchoolType.objet); - - Layer layerPointsLibres = new FeatureLayer(featurePointsLibres, getStylePointLibre()); - Layer layerPointsObjets = new FeatureLayer(featurePointsObjets, getStylePointObjet()); - mapContent.addLayer(layerPointsLibres); - mapContent.addLayer(layerPointsObjets); - - - - // set zoom - - tripArea = new ReferencedEnvelope(); - for (TripMapPoint point : tripMapPoints) { - tripArea.expandToInclude(new DirectPosition2D(point.getLongitude(), point.getLatitude())); - } - tripArea.expandBy(1.1); - - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Error on generate Map", e); - } - } -// } - return mapContent; - } - - private Style getStylePointObjet() { - return SLD.createPointStyle("Triangle", Color.BLACK, Color.ORANGE, 1, 16); - } - - protected Style getStylePointLibre() { - return SLD.createPointStyle("X", Color.BLACK, Color.GREEN, 1, 16); - } - - protected FeatureCollection generateFeaturePoints(List<TripMapPoint> tripMapPoints, final SchoolType schoolType) throws FactoryException { - SimpleFeatureTypeBuilder pointFeatureTypeBuilder = new SimpleFeatureTypeBuilder(); - pointFeatureTypeBuilder.setName("point Builder"); - pointFeatureTypeBuilder.setCRS(CRS.decode("EPSG:4326", true)); - pointFeatureTypeBuilder.add("point", MultiPoint.class); - - SimpleFeatureType pointFeatureType = pointFeatureTypeBuilder.buildFeatureType(); - SimpleFeatureBuilder pointBuilder = new SimpleFeatureBuilder(pointFeatureType); - - DefaultFeatureCollection featuresPoint = new DefaultFeatureCollection(); - - Iterable<Coordinate> coordinates = Iterables.transform( - Iterables.filter(tripMapPoints, new Predicate<TripMapPoint>() { - @Override - public boolean apply(TripMapPoint input) { - return input.getSchoolType() == schoolType; - } - }), - new Function<TripMapPoint, Coordinate>() { - @Override - public Coordinate apply(TripMapPoint input) { - return new Coordinate(input.getLongitude(), input.getLatitude()); - } - }); - - GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); - - MultiPoint points = geometryFactory.createMultiPoint(Lists.newArrayList(coordinates).toArray(new Coordinate[0])); - pointBuilder.add(points); - featuresPoint.add(pointBuilder.buildFeature(null)); - - return featuresPoint; - } - - protected Style getStyleLineDay() { - StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); - FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); - - Stroke stroke = sf.createStroke(ff.literal(Color.BLACK), ff.literal(1)); - LineSymbolizer lineSym = sf.createLineSymbolizer(stroke, null); - - - Font font = sf.getDefaultFont(); - font.setSize(ff.literal(14)); - Fill labelFill = sf.createFill(ff.literal(Color.BLACK)); - - LinePlacementImpl labelPlacement = new LinePlacementImpl(ff, true, true, false, null, null); - labelPlacement.setPerpendicularOffset(ff.literal(10)); - - TextSymbolizer textSym = sf.createTextSymbolizer( - labelFill, new Font[]{font}, null, ff.property("label"), labelPlacement, null); - - return SLD.wrapSymbolizers( lineSym, textSym ); - - } - - protected Style getStyleLineBetweenTwoDays() { - StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); - FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); - float[] dashArray = {5f, 5f}; - org.geotools.styling.Stroke stroke = sf.createStroke(ff.literal(Color.BLACK), - ff.literal(1), - null, - null, - null, - dashArray, - null, - null, - null); - - return SLD.wrapSymbolizers(sf.createLineSymbolizer(stroke, null)); - } - - private class MouseMapListener implements MouseWheelListener, MouseListener, MouseMotionListener { - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - int notches = e.getWheelRotation(); - double scale = notches; - - if (log.isDebugEnabled()) { - log.debug(String.format("Map mouse zoom (rotation : %s, scale : %s)", notches, scale)); - } - - JMapPane tripMap = getUi().getTripMap(); - ReferencedEnvelope displayArea = tripMap.getDisplayArea(); - displayArea.expandBy(scale); - if (! displayArea.isEmpty()) { - tripMap.setDisplayArea(displayArea); - } - } - - @Override - public void mouseClicked(MouseEvent e) { - - } - - protected Point2D startPointInWorld; - protected AffineTransform startScreenToWorldTransform; - protected ReferencedEnvelope startDisplayArea; - - @Override - public void mousePressed(MouseEvent e) { - startMove(e.getPoint()); - } - - @Override - public void mouseReleased(MouseEvent e) { - endMove(e.getPoint()); - } - - @Override - public void mouseEntered(MouseEvent e) { - - } - - @Override - public void mouseExited(MouseEvent e) { - - } - - @Override - public void mouseDragged(MouseEvent e) { -// endMove(e.getPoint()); - } - - @Override - public void mouseMoved(MouseEvent e) { - - } - - protected void startMove(Point2D startPointInScreen) { - JMapPane tripMap = getUi().getTripMap(); - startDisplayArea = tripMap.getDisplayArea(); - startScreenToWorldTransform = tripMap.getScreenToWorldTransform(); - startPointInWorld = new Point2D.Double(); - startScreenToWorldTransform.transform(startPointInScreen, startPointInWorld); - } - - protected void endMove(Point2D endPointInScreen) { - Point2D endPointInWorld = new Point2D.Double(); - startScreenToWorldTransform.transform(endPointInScreen, endPointInWorld); - double transX = startPointInWorld.getX() - endPointInWorld.getX(); - double transY = startPointInWorld.getY() - endPointInWorld.getY(); - - ReferencedEnvelope endDisplayArea = new ReferencedEnvelope(startDisplayArea); - endDisplayArea.translate(transX, transY); - - JMapPane tripMap = getUi().getTripMap(); - tripMap.setDisplayArea(endDisplayArea); - if (log.isDebugEnabled()) { - log.debug(String.format("Translate (x : %s, y : %s)", transX, transY)); - } - } - } - } diff --git a/observe-swing/src/main/resources/i18n/observe-swing_en_GB.properties b/observe-swing/src/main/resources/i18n/observe-swing_en_GB.properties index 7081d6d..cb46acf 100644 --- a/observe-swing/src/main/resources/i18n/observe-swing_en_GB.properties +++ b/observe-swing/src/main/resources/i18n/observe-swing_en_GB.properties @@ -970,6 +970,7 @@ observe.config.map.layer6.description= observe.config.map.layer7.description= observe.config.map.layer8.description= observe.config.map.layer9.description= +observe.config.map.style.description= observe.config.observation.activitysDetaillees= observe.config.observation.fauneAssociee= observe.config.observation.floatingObject= diff --git a/observe-swing/src/main/resources/i18n/observe-swing_es_ES.properties b/observe-swing/src/main/resources/i18n/observe-swing_es_ES.properties index 1bad99e..776d3e9 100644 --- a/observe-swing/src/main/resources/i18n/observe-swing_es_ES.properties +++ b/observe-swing/src/main/resources/i18n/observe-swing_es_ES.properties @@ -970,6 +970,7 @@ observe.config.map.layer6.description= observe.config.map.layer7.description= observe.config.map.layer8.description= observe.config.map.layer9.description= +observe.config.map.style.description= observe.config.observation.activitysDetaillees=Observación de actividades detalladas observe.config.observation.fauneAssociee=Observación de Fauna asociada observe.config.observation.floatingObject=Observación de objetos flotantes diff --git a/observe-swing/src/main/resources/i18n/observe-swing_fr_FR.properties b/observe-swing/src/main/resources/i18n/observe-swing_fr_FR.properties index 790634b..58bd292 100644 --- a/observe-swing/src/main/resources/i18n/observe-swing_fr_FR.properties +++ b/observe-swing/src/main/resources/i18n/observe-swing_fr_FR.properties @@ -925,7 +925,7 @@ observe.config.category.gps=GPS observe.config.category.gps.description=Configuration GPS observe.config.category.h2=Base locale observe.config.category.h2.description=Configuration base locale -observe.config.category.map=Fonds de carte +observe.config.category.map=Carte observe.config.category.map.description=Configuration des fonds à utiliser pour les cartes observe.config.category.observation=Qualification des observations observe.config.category.observation.description=Gestion des indicateurs de qualification des programmes @@ -970,6 +970,7 @@ observe.config.map.layer6.description=Fichier (shapeFiles) du sixième calque de observe.config.map.layer7.description=Fichier (shapeFiles) du septième calque de la carte observe.config.map.layer8.description=Fichier (shapeFiles) du huitième calque de la carte observe.config.map.layer9.description=Fichier (shapeFiles) du neuvième calque de la carte +observe.config.map.style.description=Fichier des style à appliquer sur les calques de la carte observe.config.observation.activitysDetaillees=Observation des activités détaillées observe.config.observation.fauneAssociee=Observation des Faunes associées observe.config.observation.floatingObject=Observation des objets flottants diff --git a/observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.dbf b/observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.dbf similarity index 100% rename from observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.dbf rename to observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.dbf diff --git a/observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.prj b/observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.prj similarity index 100% rename from observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.prj rename to observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.prj diff --git a/observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.sbn b/observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.sbn similarity index 100% rename from observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.sbn rename to observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.sbn diff --git a/observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.sbx b/observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.sbx similarity index 100% rename from observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.sbx rename to observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.sbx diff --git a/observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.shp b/observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.shp similarity index 100% rename from observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.shp rename to observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.shp diff --git a/observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.shp.xml b/observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.shp.xml similarity index 100% rename from observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.shp.xml rename to observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.shp.xml diff --git a/observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.shx b/observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.shx similarity index 100% rename from observe-swing/src/main/resources/shapeFiles/zee/World_EEZ_v8_2014.shx rename to observe-swing/src/main/resources/map/shapeFiles/zee/World_EEZ_v8_2014.shx diff --git a/observe-swing/src/main/resources/map/style.xml b/observe-swing/src/main/resources/map/style.xml new file mode 100644 index 0000000..b04fa28 --- /dev/null +++ b/observe-swing/src/main/resources/map/style.xml @@ -0,0 +1,126 @@ +<StyledLayerDescriptor version="1.0.0" + xmlns="http://www.opengis.net/sld" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ogc="http://www.opengis.net/ogc" + xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd + http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.0.0/filter.xsd"> + + <NamedLayer> + <Name>Trip lines</Name> + <UserStyle> + <IsDefault>true</IsDefault> + <Title>SLD Cook Book: Simple Line</Title> + <FeatureTypeStyle> + <Rule> + <Name>Trip day</Name> + <ogc:Filter> + <ogc:PropertyIsEqualTo> + <ogc:PropertyName>type</ogc:PropertyName> + <ogc:Literal>tripDay</ogc:Literal> + </ogc:PropertyIsEqualTo> + </ogc:Filter> + <LineSymbolizer> + <Stroke> + <CssParameter name="stroke">#000000</CssParameter> + <CssParameter name="stroke-width">2</CssParameter> + </Stroke> + </LineSymbolizer> + <TextSymbolizer> + <Label> + <ogc:PropertyName>label</ogc:PropertyName> + </Label> + <LabelPlacement> + <LinePlacement> + <PerpendicularOffset>10</PerpendicularOffset> + </LinePlacement> + </LabelPlacement> + <Fill> + <CssParameter name="fill">#000000</CssParameter> + </Fill> + <Font> + <CssParameter name="font-size">14</CssParameter> + <CssParameter name="font-style">normal</CssParameter> + <CssParameter name="font-weight">bold</CssParameter> + </Font> + </TextSymbolizer> + </Rule> + </FeatureTypeStyle> + <FeatureTypeStyle> + <Rule> + <Name>Trip between two days</Name> + <ogc:Filter> + <ogc:PropertyIsEqualTo> + <ogc:PropertyName>type</ogc:PropertyName> + <ogc:Literal>tripBetweenTwoDays</ogc:Literal> + </ogc:PropertyIsEqualTo> + </ogc:Filter> + <LineSymbolizer> + <Stroke> + <CssParameter name="stroke">#000000</CssParameter> + <CssParameter name="stroke-width">2</CssParameter> + <CssParameter name="stroke-dasharray">6 4</CssParameter> + </Stroke> + </LineSymbolizer> + </Rule> + </FeatureTypeStyle> + </UserStyle> + </NamedLayer> + <NamedLayer> + <Name>Trip points</Name> + <UserStyle> + <IsDefault>true</IsDefault> + <FeatureTypeStyle> + <Rule> + <Name>Point libre</Name> + <ogc:Filter> + <ogc:PropertyIsEqualTo> + <ogc:PropertyName>schoolType</ogc:PropertyName> + <ogc:Literal>libre</ogc:Literal> + </ogc:PropertyIsEqualTo> + </ogc:Filter> + <PointSymbolizer> + <Graphic> + <Mark> + <WellKnownName>Triangle</WellKnownName> + <Fill> + <CssParameter name="fill">#FFC800</CssParameter> + </Fill> + <Stroke> + <CssParameter name="stroke">#000000</CssParameter> + <CssParameter name="stroke-width">1</CssParameter> + </Stroke> + </Mark> + <Size>16</Size> + </Graphic> + </PointSymbolizer> + </Rule> + </FeatureTypeStyle> + <FeatureTypeStyle> + <Rule> + <Name>Point objet</Name> + <ogc:Filter> + <ogc:PropertyIsEqualTo> + <ogc:PropertyName>schoolType</ogc:PropertyName> + <ogc:Literal>objet</ogc:Literal> + </ogc:PropertyIsEqualTo> + </ogc:Filter> + <PointSymbolizer> + <Graphic> + <Mark> + <WellKnownName>X</WellKnownName> + <Fill> + <CssParameter name="fill">#00FF00</CssParameter> + </Fill> + <Stroke> + <CssParameter name="stroke">#000000</CssParameter> + <CssParameter name="stroke-width">1</CssParameter> + </Stroke> + </Mark> + <Size>16</Size> + </Graphic> + </PointSymbolizer> + </Rule> + </FeatureTypeStyle> + </UserStyle> + </NamedLayer> +</StyledLayerDescriptor> \ No newline at end of file -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm