Revision 47356

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/MapControl.java
43 43
import java.awt.geom.Point2D;
44 44
import java.awt.image.BufferedImage;
45 45
import java.awt.image.MemoryImageSource;
46
import java.util.ArrayList;
46 47
import java.util.Comparator;
47 48
import java.util.HashMap;
48 49
import java.util.List;
......
2495 2496
        if (previousPoint != null) {
2496 2497
            lastPoint = new Point2D.Double(previousPoint[0], previousPoint[1]);
2497 2498
        }
2499
        List<Geometry> geomsToSnap = new ArrayList();
2498 2500
        for (FLyrVect lyrVect : layersToSnap) {
2499 2501
            SpatialCache cache = lyrVect.getSpatialCache();
2500 2502
            if (lyrVect.isVisible()) {
2501
                // La lista de snappers esta siempre ordenada por prioridad. Los
2502
                // de mayor prioridad estan primero.
2503 2503
                List geoms = cache.query(r);
2504

  
2505
                for (int i = 0; i < mapControlManager.getSnapperCount(); i++)
2506
                {
2507
                    ISnapper theSnapper = mapControlManager.getSnapperAt(i);
2508
                    if (theSnapper instanceof ISnapperGeometriesVectorial)
2509
                    {
2510
                        ((ISnapperGeometriesVectorial)theSnapper).setGeometries(geoms);
2504
                for (Object geom : geoms) {
2505
                    if(geom instanceof Geometry){
2506
                        geomsToSnap.add((Geometry)geom);
2507
                        if(geomsToSnap.size() > 1000){
2508
                            break;
2509
                        }
2511 2510
                    }
2512 2511
                }
2512
                if(geomsToSnap.size() > 1000){
2513
                    break;
2514
                }
2515
            }
2516
        }
2513 2517

  
2514
                for (int n = 0; n < geoms.size(); n++) {
2515
                    Geometry geom = (Geometry) geoms.get(n);
2516
                    for (int i = 0; i < mapControlManager.getSnapperCount(); i++) {
2517
                        ISnapper theSnapper = mapControlManager.getSnapperAt(i);
2518
                        if (!theSnapper.isEnabled())
2519
                            continue;
2518
        for (int i = 0; i < mapControlManager.getSnapperCount(); i++) {
2519
            ISnapper theSnapper = mapControlManager.getSnapperAt(i);
2520
            if (theSnapper instanceof ISnapperGeometriesVectorial) {
2521
                ((ISnapperGeometriesVectorial)theSnapper).setGeometries(geomsToSnap);
2522
            }
2523
        }
2520 2524

  
2521
                        if (usedSnap != null) {
2522
                            // Si ya tenemos un snap y es de alta prioridad,
2523
                            // cogemos ese. (A no ser que en otra capa
2524
                            // encontremos un snapper mejor)
2525
                            if (theSnapper.getPriority() > usedSnap
2526
                                .getPriority())
2527
                                break;
2528
                        }
2529
                        // SnappingVisitor snapVisitor = null;
2530
                        Point2D theSnappedPoint = null;
2531
                        if (theSnapper instanceof ISnapperVectorial) {
2532
                            theSnappedPoint =
2533
                                ((ISnapperVectorial) theSnapper).getSnapPoint(
2534
                                    point, geom, mapTolerance, lastPoint);
2535
                        }
2536
                        if (theSnapper instanceof ISnapperRaster) {
2537
                            ISnapperRaster snapRaster =
2538
                                (ISnapperRaster) theSnapper;
2539
                            theSnappedPoint =
2540
                                snapRaster.getSnapPoint(this, point,
2541
                                    mapTolerance, lastPoint);
2542
                        }
2525
        for (int n = 0; n < geomsToSnap.size(); n++) {
2526
            Geometry geom = (Geometry) geomsToSnap.get(n);
2527
            // La lista de snappers esta siempre ordenada por prioridad. Los
2528
            // de mayor prioridad estan primero.
2529
            for (int i = 0; i < mapControlManager.getSnapperCount(); i++) {
2530
                ISnapper theSnapper = mapControlManager.getSnapperAt(i);
2531
                if (!theSnapper.isEnabled())
2532
                    continue;
2543 2533

  
2544
                        if (theSnappedPoint != null) {
2545
                            double distAux = theSnappedPoint.distance(point);
2546
                            if (minDist > distAux) {
2547
                                minDist = distAux;
2548
                                usedSnap = theSnapper;
2549
                                mapHandlerAdjustedPoint
2550
                                    .setLocation(theSnappedPoint);
2551
                            }
2552
                        }
2534
                if (usedSnap != null) {
2535
                    // Si ya tenemos un snap y es de alta prioridad,
2536
                    // cogemos ese. (A no ser que en otra capa
2537
                    // encontremos un snapper mejor)
2538
                    if (theSnapper.getPriority() > usedSnap.getPriority()) {
2539
                        break;
2553 2540
                    }
2554
                } // for n
2555
            } // visible
2541
                }
2542
                // SnappingVisitor snapVisitor = null;
2543
                Point2D theSnappedPoint = null;
2544
                if (theSnapper instanceof ISnapperVectorial) {
2545
                    theSnappedPoint =
2546
                        ((ISnapperVectorial) theSnapper).getSnapPoint(
2547
                            point, geom, mapTolerance, lastPoint);
2548
                }
2549
                if (theSnapper instanceof ISnapperRaster) {
2550
                    ISnapperRaster snapRaster =
2551
                        (ISnapperRaster) theSnapper;
2552
                    theSnappedPoint =
2553
                        snapRaster.getSnapPoint(this, point,
2554
                            mapTolerance, lastPoint);
2555
                }
2556

  
2557
                if (theSnappedPoint != null) {
2558
                    double distAux = theSnappedPoint.distance(point);
2559
                    if (minDist > distAux) {
2560
                        minDist = distAux;
2561
                        usedSnap = theSnapper;
2562
                        mapHandlerAdjustedPoint
2563
                            .setLocation(theSnappedPoint);
2564
                    }
2565
                }
2566
            }
2556 2567
        }
2557
        if (usedSnap != null)
2568
        
2569
        if (usedSnap != null) {
2558 2570
            return minDist;
2571
        }
2559 2572
        return Double.MAX_VALUE;
2560 2573

  
2561 2574
    }

Also available in: Unified diff