Hi!

We're having problems with the ZoomSelection tool and point selections. The 
zoom goes to 1:0 scale which isn't very nice. I think I was able to fix the 
ZoomSelection tool to use the ScaleUtils.fitToMinAndMax(...) so that I can use 
the map blackboard to set a minimum scale. I've attached a patch to the 
ZoomSelection.java.

Could you, please, take this patch to uDig? Or do you have some other ideas of 
how to fix the ZoomSelection tool?

Thanks,

                Pirkka Jokela
### Eclipse Workspace Patch 1.0
#P net.refractions.udig.tool.select
Index: src/net/refractions/udig/tool/select/internal/ZoomSelection.java
===================================================================
--- src/net/refractions/udig/tool/select/internal/ZoomSelection.java    
(revision 31446)
+++ src/net/refractions/udig/tool/select/internal/ZoomSelection.java    
(working copy)
@@ -17,6 +17,7 @@
 import java.io.IOException;
 
 import net.refractions.udig.project.ILayer;
+import net.refractions.udig.project.internal.render.impl.ScaleUtils;
 import net.refractions.udig.project.ui.tool.AbstractActionTool;
 import net.refractions.udig.tool.select.SelectPlugin;
 import net.refractions.udig.ui.ProgressManager;
@@ -24,6 +25,7 @@
 import org.geotools.data.DefaultQuery;
 import org.geotools.data.FeatureSource;
 import org.geotools.data.Query;
+import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 
@@ -50,10 +52,21 @@
                FeatureSource<SimpleFeatureType, SimpleFeature> resource = 
layer.getResource(FeatureSource.class, ProgressManager.instance().get());
                 Query query = new DefaultQuery( 
resource.getSchema().getName().getLocalPart(), layer.getFilter(), 
                         new 
String[]{resource.getSchema().getGeometryDescriptor().getName().getLocalPart()});
-                Envelope bounds = resource.getBounds(query);
+                ReferencedEnvelope bounds = resource.getBounds(query);
                 if( bounds==null ){
-                    bounds=resource.getFeatures(query).getBounds();
+                    ReferencedEnvelope envelope = 
resource.getFeatures(query).getBounds();
+                    if (envelope != null) {
+                        bounds = new ReferencedEnvelope(envelope, 
layer.getCRS());
+                    }
                 }
+                // If the selection is a single point the bounds will 
+                // have height == 0 and width == 0. This will break
+                // in ScaleUtils:306. Adding 1 to the extent fixes the problem:
+                if (bounds.getHeight() <= 0 || bounds.getWidth() <= 0) {
+                    bounds.expandBy(1);
+                }
+                bounds = ScaleUtils.fitToMinAndMax(bounds, layer);
+                
                 
getContext().sendASyncCommand(getContext().getNavigationFactory().createSetViewportBBoxCommand(bounds,
                         layer.getCRS()));
             } catch (IOException e) {
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to