]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Improve GIS
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 22 Feb 2011 23:10:42 +0000 (23:10 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 22 Feb 2011 23:10:42 +0000 (23:10 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@4169 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

12 files changed:
eclipse/plugins/org.argeo.slc.ui.gis/.classpath [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/.project [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/META-INF/MANIFEST.MF [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-osgi.xml [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-views.xml [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/build.properties [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/icons/sample.gif [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/plugin.xml [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/ClientGisActivator.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/GisPerspectiveFactory.java [new file with mode: 0644]
eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/views/GeoToolsMapView.java [new file with mode: 0644]

diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/.classpath b/eclipse/plugins/org.argeo.slc.ui.gis/.classpath
new file mode 100644 (file)
index 0000000..92f19d2
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+       <classpathentry kind="src" path="src/main/java"/>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/.project b/eclipse/plugins/org.argeo.slc.ui.gis/.project
new file mode 100644 (file)
index 0000000..f0dfed9
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>org.argeo.slc.client.gis</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.ManifestBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.pde.SchemaBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.pde.PluginNature</nature>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/.settings/org.eclipse.jdt.core.prefs b/eclipse/plugins/org.argeo.slc.ui.gis/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..14c8f81
--- /dev/null
@@ -0,0 +1,8 @@
+#Wed Oct 13 08:00:18 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/MANIFEST.MF b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..31e5274
--- /dev/null
@@ -0,0 +1,33 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Gis
+Bundle-SymbolicName: org.argeo.slc.client.gis; singleton:=true
+Bundle-Version: 0.13.1.SNAPSHOT
+Bundle-Activator: org.argeo.slc.client.gis.ClientGisActivator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.argeo.dep.osgi.jai.imageio;bundle-version="1.1.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: com.vividsolutions.jts.geom;version="1.10.0",
+ org.apache.commons.logging;version="1.1.1",
+ org.argeo.eclipse.spring,
+ org.argeo.slc.geotools,
+ org.argeo.slc.geotools.data,
+ org.argeo.slc.geotools.swing,
+ org.argeo.slc.gis.model,
+ org.argeo.slc.jts,
+ org.geotools.data,
+ org.geotools.gce.image,
+ org.geotools.geometry,
+ org.geotools.map,
+ org.geotools.renderer,
+ org.geotools.renderer.lite,
+ org.geotools.styling,
+ org.geotools.swing,
+ org.geotools.swing.event,
+ org.geotools.swing.tool,
+ org.opengis.feature.simple,
+ org.opengis.geometry,
+ org.opengis.referencing.crs,
+ org.springframework.osgi.util;version="1.2.1"
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-osgi.xml b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-osgi.xml
new file mode 100644 (file)
index 0000000..69235e8
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans:beans xmlns="http://www.springframework.org/schema/osgi"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"\r
+       xsi:schemaLocation="http://www.springframework.org/schema/osgi  \r
+       http://www.springframework.org/schema/osgi/spring-osgi-1.1.xsd\r
+       http://www.springframework.org/schema/beans   \r
+       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
+\r
+       <reference id="positionProvider" interface="org.argeo.slc.jts.PositionProvider" />\r
+\r
+       <reference id="backend" interface="org.argeo.slc.geotools.Backend" />\r
+</beans:beans>
\ No newline at end of file
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-views.xml b/eclipse/plugins/org.argeo.slc.ui.gis/META-INF/spring/gisclient-views.xml
new file mode 100644 (file)
index 0000000..f395c7b
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
+       xsi:schemaLocation="
+               http://www.springframework.org/schema/beans
+        http://www.springframework.org/schema/beans/spring-beans.xsd
+       ">
+
+       <bean id="org.argeo.slc.client.gis.mapView" class="org.argeo.slc.client.gis.views.GeoToolsMapView"
+               scope="prototype">
+               <property name="positionProvider" ref="positionProvider" />
+               <property name="backend" ref="backend" />
+               <property name="mapContext" ref="mapContext" />
+       </bean>
+
+       <bean id="mapContext" class="org.geotools.map.DefaultMapContext" />
+
+</beans>
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/build.properties b/eclipse/plugins/org.argeo.slc.ui.gis/build.properties
new file mode 100644 (file)
index 0000000..8950055
--- /dev/null
@@ -0,0 +1,6 @@
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = plugin.xml,\
+               META-INF/,\
+               .,\
+               icons/
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/icons/sample.gif b/eclipse/plugins/org.argeo.slc.ui.gis/icons/sample.gif
new file mode 100644 (file)
index 0000000..34fb3c9
Binary files /dev/null and b/eclipse/plugins/org.argeo.slc.ui.gis/icons/sample.gif differ
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/plugin.xml b/eclipse/plugins/org.argeo.slc.ui.gis/plugin.xml
new file mode 100644 (file)
index 0000000..b482a4d
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+   <extension
+         point="org.eclipse.ui.views">
+      <category
+            name="GIS"
+            id="org.argeo.slc.client.gis">
+      </category>
+      <view
+            name="Map"
+            icon="icons/sample.gif"
+            category="org.argeo.slc.client.gis"
+            class="org.argeo.eclipse.spring.SpringExtensionFactory"
+            id="org.argeo.slc.client.gis.mapView">
+      </view>
+   </extension>
+   <extension
+         point="org.eclipse.ui.perspectiveExtensions">
+      <perspectiveExtension
+            targetID="org.argeo.slc.client.gis.perspective">
+         <view
+               ratio="0.5"
+               relative="org.eclipse.ui.editorss"
+               relationship="right"
+               id="org.argeo.slc.client.gis.mapView">
+         </view>
+      </perspectiveExtension>
+   </extension>
+   <extension
+         point="org.eclipse.ui.perspectives">
+      <perspective
+            class="org.argeo.slc.client.gis.GisPerspectiveFactory"
+            id="org.argeo.slc.client.gis.perspective"
+            name="GIS">
+      </perspective>
+   </extension>
+
+</plugin>
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/ClientGisActivator.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/ClientGisActivator.java
new file mode 100644 (file)
index 0000000..7c2d235
--- /dev/null
@@ -0,0 +1,61 @@
+package org.argeo.slc.client.gis;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ClientGisActivator extends AbstractUIPlugin {
+
+       // The plug-in ID
+       public static final String PLUGIN_ID = "org.argeo.slc.client.gis"; //$NON-NLS-1$
+
+       // The shared instance
+       private static ClientGisActivator plugin;
+       
+       /**
+        * The constructor
+        */
+       public ClientGisActivator() {
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+        */
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+               plugin = this;
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+        */
+       public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        *
+        * @return the shared instance
+        */
+       public static ClientGisActivator getDefault() {
+               return plugin;
+       }
+
+       /**
+        * Returns an image descriptor for the image file at the given
+        * plug-in relative path
+        *
+        * @param path the path
+        * @return the image descriptor
+        */
+       public static ImageDescriptor getImageDescriptor(String path) {
+               return imageDescriptorFromPlugin(PLUGIN_ID, path);
+       }
+}
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/GisPerspectiveFactory.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/GisPerspectiveFactory.java
new file mode 100644 (file)
index 0000000..c9de664
--- /dev/null
@@ -0,0 +1,19 @@
+package org.argeo.slc.client.gis;
+
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+public class GisPerspectiveFactory implements IPerspectiveFactory {
+
+       public void createInitialLayout(IPageLayout layout) {
+               String editorArea = layout.getEditorArea();
+               layout.setEditorAreaVisible(false);
+               layout.setFixed(false);
+
+               IFolderLayout topLeft = layout.createFolder("topLeft",
+                               IPageLayout.LEFT, 0.5f, editorArea);
+               topLeft.addView("org.argeo.slc.client.gis.mapView");
+       }
+
+}
diff --git a/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/views/GeoToolsMapView.java b/eclipse/plugins/org.argeo.slc.ui.gis/src/main/java/org/argeo/slc/client/gis/views/GeoToolsMapView.java
new file mode 100644 (file)
index 0000000..3697987
--- /dev/null
@@ -0,0 +1,241 @@
+package org.argeo.slc.client.gis.views;
+
+import java.awt.Color;
+import java.awt.Frame;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+
+import javax.swing.SwingUtilities;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.geotools.Backend;
+import org.argeo.slc.geotools.DataDescriptor;
+import org.argeo.slc.geotools.data.FeatureSourceDataDescriptor;
+import org.argeo.slc.geotools.data.PostgisDataDescriptor;
+import org.argeo.slc.geotools.data.WorldImageDataDescriptor;
+import org.argeo.slc.geotools.swing.VersatileZoomTool;
+import org.argeo.slc.gis.model.FieldPosition;
+import org.argeo.slc.jts.PositionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.awt.SWT_AWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+import org.geotools.geometry.DirectPosition2D;
+import org.geotools.geometry.Envelope2D;
+import org.geotools.map.MapContext;
+import org.geotools.renderer.lite.StreamingRenderer;
+import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.Style;
+import org.geotools.styling.StyleBuilder;
+import org.geotools.swing.JMapPane;
+import org.geotools.swing.event.MapPaneAdapter;
+import org.geotools.swing.event.MapPaneEvent;
+
+import com.vividsolutions.jts.geom.Coordinate;
+
+public class GeoToolsMapView extends ViewPart {
+       public static final String ID = "org.argeo.slc.client.gis.views.GeoToolsMapView";
+       private final static Log log = LogFactory.getLog(GeoToolsMapView.class);
+
+       private Composite embedded;
+
+       private PositionProvider positionProvider;
+
+       private Backend backend;
+
+       private MapContext mapContext;
+       private JMapPane mapPane;
+
+       /** in s */
+       private Integer positionRefreshPeriod = 1;
+       private FieldPosition currentPosition = null;
+       private Boolean positionProviderDisconnected = false;
+       private VersatileZoomTool versatileZoomTool;
+
+       public void createPartControl(Composite parent) {
+               embedded = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
+               Frame frame = SWT_AWT.new_Frame(embedded);
+
+               mapPane = new JMapPane(new StreamingRenderer(), mapContext);
+               versatileZoomTool = new VersatileZoomTool();
+               mapPane.setCursorTool(versatileZoomTool);
+
+               mapPane.addMapPaneListener(new CustomMapPaneListener());
+
+               frame.add(mapPane);
+
+               centerOnPosition();
+
+               for (DataDescriptor dd : backend.getAvailableData(null)) {
+                       if (dd instanceof WorldImageDataDescriptor) {
+                               StyleBuilder styleBuilder = new StyleBuilder();
+                               RasterSymbolizer rs = styleBuilder.createRasterSymbolizer();
+                               rs.setGeometryPropertyName("geom");
+                               Style rasterStyle = styleBuilder.createStyle(rs);
+                               try {
+                                       mapContext.addLayer(backend.loadGridCoverage(dd),
+                                                       rasterStyle);
+                               } catch (Exception e) {
+                                       log.warn(e);
+                               }
+
+                       } else if (dd instanceof FeatureSourceDataDescriptor) {
+                               try {
+                                       mapContext.addLayer(backend.loadFeatureSource(dd), null);
+                               } catch (Exception e) {
+                                       log.warn(e);
+                               }
+                       } else if (dd instanceof PostgisDataDescriptor) {
+                               // DataStore dataStore = backend.loadDataStore(dd);
+                               for (DataDescriptor dd2 : backend.getAvailableData(dd))
+                                       mapContext.addLayer(backend.loadFeatureSource(dd2), null);
+                       }
+               }
+               // GisFieldViewer gisFieldViewer = new GisFieldViewer(frame);
+               // gisFieldViewer.setPostGisDataStore(postGisDataStore);
+               // gisFieldViewer.setPositionProvider(positionProvider);
+               // gisFieldViewer.setJaiImageIoClassLoader(jaiImageIoClassLoader);
+               // gisFieldViewer.afterPropertiesSet();
+
+               new Thread(new PositionUpdater()).start();
+
+       }
+
+       protected void receiveNewPosition(FieldPosition position) {
+               if (position != null && versatileZoomTool != null) {
+                       positionProviderDisconnected = false;
+                       currentPosition = position;
+                       Point2D point2d = new DirectPosition2D(currentPosition
+                                       .getLocation().getCoordinate().x, currentPosition
+                                       .getLocation().getCoordinate().y);
+                       versatileZoomTool.setFieldPosition(point2d);
+                       drawPositionLocation();
+               } else {
+                       positionProviderDisconnected = true;
+               }
+       }
+
+       protected void drawPositionLocation() {
+               SwingUtilities.invokeLater(new Runnable() {
+                       public void run() {
+                               if (currentPosition == null)
+                                       return;
+
+                               AffineTransform tr = getMapPane().getWorldToScreenTransform();
+                               DirectPosition2D geoCoords = new DirectPosition2D(
+                                               currentPosition.getLocation().getCoordinate().x,
+                                               currentPosition.getLocation().getCoordinate().y);
+                               if (tr == null)
+                                       return;
+                               tr.transform(geoCoords, geoCoords);
+                               geoCoords.setCoordinateReferenceSystem(getMapPane()
+                                               .getMapContext().getCoordinateReferenceSystem());
+
+                               final int halfRefSize = 3;
+                               Rectangle rect = new Rectangle((int) Math.round(geoCoords
+                                               .getX() - halfRefSize), (int) Math.round(geoCoords
+                                               .getY() - halfRefSize), halfRefSize * 2 + 1,
+                                               halfRefSize * 2 + 1);
+                               Graphics2D g2D = (Graphics2D) getMapPane().getGraphics();
+                               if (g2D == null)
+                                       return;
+                               g2D.setColor(Color.WHITE);
+                               if (positionProviderDisconnected)
+                                       g2D.setXORMode(Color.ORANGE);
+                               else
+                                       g2D.setXORMode(Color.RED);
+                               g2D.drawRect(rect.x, rect.y, rect.width, rect.height);
+                               g2D.drawRect(rect.x - 1, rect.y - 1, rect.width + 2,
+                                               rect.height + 2);
+                       }
+               });
+       }
+
+       protected void centerOnPosition() {
+               if (currentPosition == null)
+                       return;
+               Envelope2D env = new Envelope2D();
+               final double increment = 1d;
+               Coordinate positionCoo = currentPosition.getLocation().getCoordinate();
+               env.setFrameFromDiagonal(positionCoo.x - increment, positionCoo.y
+                               - increment, positionCoo.x + increment, positionCoo.y
+                               + increment);
+               getMapPane().setDisplayArea(env);
+
+       }
+
+       public void setFocus() {
+               if (embedded != null)
+                       embedded.setFocus();
+       }
+
+       protected JMapPane getMapPane() {
+               return mapPane;
+       }
+
+       public void setPositionProvider(PositionProvider positionProvider) {
+               this.positionProvider = positionProvider;
+       }
+
+       public void setBackend(Backend backend) {
+               this.backend = backend;
+       }
+
+       public void setMapContext(MapContext mapContext) {
+               this.mapContext = mapContext;
+       }
+
+       private class CustomMapPaneListener extends MapPaneAdapter {
+
+               @Override
+               public void onRenderingStopped(MapPaneEvent ev) {
+                       drawPositionLocation();
+               }
+
+               @Override
+               public void onDisplayAreaChanged(MapPaneEvent ev) {
+                       drawPositionLocation();
+               }
+
+               @Override
+               public void onRenderingProgress(MapPaneEvent ev) {
+                       drawPositionLocation();
+               }
+
+               @Override
+               public void onRenderingStarted(MapPaneEvent ev) {
+                       drawPositionLocation();
+               }
+
+               @Override
+               public void onResized(MapPaneEvent ev) {
+                       drawPositionLocation();
+               }
+
+       }
+
+       private class PositionUpdater implements Runnable {
+
+               public void run() {
+                       while (true) {
+                               FieldPosition currentPosition = positionProvider
+                                               .currentPosition();
+
+                               receiveNewPosition(currentPosition);
+
+                               if (currentPosition != null) {
+                               }
+
+                               try {
+                                       Thread.sleep(positionRefreshPeriod * 1000);
+                               } catch (InterruptedException e) {
+                                       e.printStackTrace();
+                               }
+                       }
+               }
+       }
+
+}
\ No newline at end of file