Package org.locationtech.udig.project

Examples of org.locationtech.udig.project.IMap


*/
public class AddReshapedToMap implements PostReshapeAction {


    public void execute( IGeoResource original, IGeoResource reshaped ) {
        IMap map = ApplicationGIS.getActiveMap();
        if( map==ApplicationGIS.NO_MAP ){
            ApplicationGIS.addLayersToMap(null, Collections.singletonList(reshaped), 0);
        } else {
            ApplicationGIS.addLayersToMap(map, Collections.singletonList(reshaped), map.getMapLayers().size());
        }
    }
View Full Code Here


     * TODO: this requires some testing
     */
    public static LayerPointInfo info2( ILayer layer, ReferencedEnvelope query ) throws IOException {       

    Envelope reprojected = null;
    IMap map = layer.getMap();
        try {
            reprojected = query.transform(map.getViewportModel().getCRS(), true);
        } catch (Exception e) {
            InfoPlugin.log("", e); //$NON-NLS-1$
            return null;
        }
        Point centre = map.getViewportModel().worldToPixel(reprojected.centre());

        Envelope sanebbox = map.getViewportModel().getBounds();
        ReferencedEnvelope bbox = new ReferencedEnvelope(sanebbox, query.getCoordinateReferenceSystem());
   
      Layer wmslayer;
        wmslayer = layer.getResource( Layer.class, null );
       
        if( wmslayer == null ) {
            throw new IllegalArgumentException("Provided layer is not a WMS layer" ); //$NON-NLS-1$
        }
        if( !wmslayer.isQueryable() ){
            return null;
        }
        // TODO: Fix wmslayer so we can ask who its "source" is.
        final WebMapServer wms = layer.getResource( WebMapServer.class, null );       
        if( wms == null ) {
            throw new IllegalArgumentException("Provided layer cannot resolve to a wms" ); //$NON-NLS-1$
        }
        String desiredFormat = desiredInfoFormat( wms );               
        if( desiredFormat == null ){
            return null;
        }
        GetMapRequest getmap = wms.createGetMapRequest();       
        String code = BasicWMSRenderer2.findRequestCRS(
                Collections.singletonList( wmslayer ), map.getViewportModel().getCRS(), map );

        getmap.setBBox( bbox );
        String srs = CRS.toSRS(bbox.getCoordinateReferenceSystem() );
        //getmap.setSRS( code != null ? code : srs );
       
        getmap.setProperty( GetMapRequest.LAYERS, wmslayer.getName() );
        int width = map.getRenderManager().getMapDisplay().getWidth();
        int height = map.getRenderManager().getMapDisplay().getHeight();
        getmap.setDimensions(width, height);
        //getmap.setSRS(code);
       
        List<String> formats = wms.getCapabilities().getRequest().getGetMap().getFormats();
        if (formats.contains("image/png")) { //$NON-NLS-1$
View Full Code Here

     * Calls a command which makes a spatial filter and puts it on the
     * styleBlackboard
     */
    public void op( Display display, Object target, IProgressMonitor monitor ) throws Exception {
        final ILayer layer = (ILayer) target;
        final IMap map = layer.getMap();

        //get all selected features
        Query query = new DefaultQuery(layer.getSchema().getTypeName(), layer.getFilter());
       
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = layer.getResource(FeatureSource.class, new SubProgressMonitor(monitor, 1));
        FeatureCollection<SimpleFeatureType, SimpleFeature>  features = featureSource.getFeatures(query);
       
        //combine them into one large polygon
        final Geometry union[] = new Geometry[1];
        features.accepts( new FeatureVisitor(){
            public void visit( Feature feature ) {
                SimpleFeature simple = (SimpleFeature) feature;
                Geometry geometry = (Geometry ) simple.getDefaultGeometry();
                if( union[0] == null ){
                    union[0] = geometry;
                }
                else {
                    union[0] = union[0].union( geometry );
                }
            }                   
        }, GeoToolsAdapters.progress(monitor) );
       
        final Geometry hole = union[0];
       
        MapCommand drillHoleCommand = new AbstractCommand(){
           
            public void run( IProgressMonitor monitor ) throws Exception {
                for( Layer targetLayer : getMap().getLayersInternal() ){
                    //make hole filter for target layer
                    if( targetLayer == layer ){
                        continue; // skip the source layer (because that would be silly)
                    }
                    SimpleFeatureType targetType = targetLayer.getSchema();
                    if( targetType == null ){
                        // must be a grid coverage or something
                        continue;
                    }
                    String targetGeomName = targetType.getGeometryDescriptor().getLocalName();
   
                    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2( GeoTools.getDefaultHints() );
                    Filter cut= ff.not( ff.within( ff.property( targetGeomName ), ff.literal(hole) ) );
                   
                    //put it on style blackboard
                    //Key:  ProjectBlackboardConstants    String LAYER__DATA_QUERY = "org.locationtech.udig.project.view"; //$NON-NLS-1$
                    IStyleBlackboard styleBlackboard = layer.getStyleBlackboard();
                    styleBlackboard.put(ProjectBlackboardConstants.LAYER__DATA_QUERY, cut);
                }
            }

            public Command copy() {
                return this;
            }

            public String getName() {
                return "Create Hole Command"; //$NON-NLS-1$
            }
           
        };
        map.sendCommandSync( drillHoleCommand );
    }
View Full Code Here

public class SeagullGlassPaneOp implements IOp {

    public void op( Display display, Object target, IProgressMonitor monitor ) throws Exception {

        //get the map
        final IMap map = (IMap) target;  //ApplicationGIS.getActiveMap();
        if (map == null)
            return;
       
       
        final ViewportPane viewer = (ViewportPane)map.getRenderManager().getMapDisplay();
       
        //create a flock of seagulls
        final Collection<Seagull> gulls = createSeagulls(map.getViewportModel().getCenter(), map.getViewportModel().getCRS());
       
        //create a glass pane that draws the seagulls
        addFlockGlassPane(viewer, gulls);
    
        //timer to update map
        int refreshrate = 250;

        //draws the map at given intervals
        Timer mapupdatetimer = new Timer();
        mapupdatetimer.scheduleAtFixedRate(new TimerTask(){

            @Override
            public void run() {
                viewer.repaint();
               
            }}, new Date(), refreshrate);
       

        //moves the seagulls at given intervals
        Timer gulltimer = new Timer();
        gulltimer.scheduleAtFixedRate(new TimerTask(){

            @Override
            public void run() {
               //move gulls
                ReferencedEnvelope mapbounds = map.getViewportModel().getBounds();
                Envelope bounds = new Envelope(mapbounds.getMinX(),mapbounds.getMaxX(), mapbounds.getMinY(), mapbounds.getMaxY());
                for( Iterator<Seagull> iterator = gulls.iterator(); iterator.hasNext(); ) {
                    Seagull seagull = (Seagull) iterator.next();
                    seagull.moveSeagull(bounds);
                }
View Full Code Here

public class TrackSeagullOp implements IOp {

    public void op( Display display, Object target, IProgressMonitor monitor ) throws Exception {

        //get the map
        final IMap map = (IMap) target;  //ApplicationGIS.getActiveMap();
        if (map == null)
            return;

       
        final ViewportPane viewer = (ViewportPane)map.getRenderManager().getMapDisplay();
       
        //create a flock of seagulls
        final Collection<Seagull> gulls = createSeagulls(map.getViewportModel().getCenter(), map.getViewportModel().getCRS());
       
        Seagull trackingGull = gulls.iterator().next();
        trackingGull.setColor(SWT.COLOR_RED);
        trackingGull.moveSeagull(new Coordinate(0,0));
        trackingGull.setLocationListener(new Seagull.SeagullLocationListener(){
            public void gullMoved( final Coordinate newLoc ) {
                Display.getDefault().asyncExec(new Runnable(){

                    private void scroll(int newx, int newy, int startx, int starty){
                        ViewportModelImpl vm =  (ViewportModelImpl)map.getViewportModel();
                        final ViewportPaneTiledSWT viewera = (ViewportPaneTiledSWT)viewer;
                       
                        org.eclipse.swt.graphics.Point p = Display.getCurrent().map((Canvas)viewera, null, newx, newy);
                        org.eclipse.swt.graphics.Point p2 = Display.getCurrent().map((Canvas)viewera, null, startx, starty);
                        int xdiff = p2.x - p.x;
                        int ydiff = p2.y - p.y;
                        ((Canvas)viewera).scroll(xdiff, ydiff, 0,0, map.getRenderManager().getMapDisplay().getWidth(), map.getRenderManager().getMapDisplay().getHeight(), true);
                       
                    }
                    public void run() {
                        ViewportModelImpl vm =  (ViewportModelImpl)map.getViewportModel();
                        final ViewportPaneTiledSWT viewera = (ViewportPaneTiledSWT)viewer;
                        final ReferencedEnvelope bounds = vm.getBounds();
                        Coordinate currentc = vm.getCenter();
                     
                        final Point newpnt = vm.worldToPixel(newLoc);
                        final Point oldpnt = vm.worldToPixel(currentc);
                       
                        vm.setIsBoundsChanging(true);
                       
                        int xoffset =  oldpnt.x - newpnt.x;
                        int yoffset = oldpnt.y - newpnt.y;
                       
                        int diffx = 0;
                        int diffy = 0;
                       
                        int xdiff = (int)(xoffset / 10.0);
                        int ydiff = (int)(yoffset / 10.0);
                        if (xdiff == 0){
                            if (xoffset > 0){
                                xdiff = 1;
                            }else{
                                xdiff = -1;
                            }
                        }
                        if (ydiff == 0){
                            if (yoffset > 0){
                                ydiff = 1;
                            }else{
                                ydiff = -1;
                            }
                        }
                        int lastx = oldpnt.x;
                        int lasty = oldpnt.y;
                       
                        while(Math.abs(diffx) < Math.abs(xoffset|| Math.abs(diffy) < Math.abs(yoffset) ){
                            if (Math.abs(diffx) < Math.abs(xoffset))
                                diffx += xdiff;
                            if (Math.abs(diffy) < Math.abs(yoffset))
                                diffy += ydiff;
                           
                            scroll(lastx - xdiff, lasty-ydiff, lastx,lasty  );
                            lastx -= xdiff;
                            lasty -= ydiff;    
                        }
                        lastx -= xdiff;
                        lasty -=ydiff;
                        Coordinate newCoo = vm.pixelToWorld(lastx, lasty);
                        vm.setIsBoundsChanging(false);
                        vm.setCenter(newCoo);
                    }});
               
//                SetViewportCenterCommand cmd = new SetViewportCenterCommand(newLoc);
//                map.sendCommandASync(cmd);
            }
        });
       
       
       
        //create a glass pane that draws the seagulls
        addFlockGlassPane(viewer, gulls);
    
        //timer to update map
        int refreshrate = 300;

        //draws the map at given intervals
        Timer mapupdatetimer = new Timer();
        mapupdatetimer.scheduleAtFixedRate(new TimerTask(){

            @Override
            public void run() {
                viewer.repaint();
               
            }}, new Date(), refreshrate);
       

        //moves the seagulls at given intervals
        Timer gulltimer = new Timer();
        gulltimer.scheduleAtFixedRate(new TimerTask(){

            @Override
            public void run() {
               //move gulls
                ReferencedEnvelope mapbounds = map.getViewportModel().getBounds();
                Envelope bounds = new Envelope(mapbounds.getMinX(),mapbounds.getMaxX(), mapbounds.getMinY(), mapbounds.getMaxY());
                for( Iterator<Seagull> iterator = gulls.iterator(); iterator.hasNext(); ) {
                    Seagull seagull = (Seagull) iterator.next();
                    seagull.moveSeagull(bounds);
                }
View Full Code Here

public class SyncProjection implements IOp {

    public void op( Display display, Object target, IProgressMonitor monitor ) throws Exception {
        ILayer layer = (ILayer) target;
        IMap map = layer.getMap();
       
        final CoordinateReferenceSystem after = layer.getCRS();
       
        MapCommand changeProjection = new ChangeCRSCommand(after);
        map.sendCommandASync( changeProjection );
       
    }
View Full Code Here

    /**
     * Sets up the glass pane and seagull flock
     */
    private void init() {
        // get the map
        IMap map = getContext().getMap();
        if (map == null)
            return;

        final ViewportPane viewer = (ViewportPane) map.getRenderManager().getMapDisplay();
        // creates seagulls
        gulls = createSeagulls(map.getViewportModel().getBounds(), map.getViewportModel().getCRS());
        // creates glass panel
        addFlockGlassPane(viewer, gulls);

        // timer to update map
        int refreshrate = 100;
View Full Code Here

     */
    public static List<? extends ILayer> addLayersToMap(IMap map2,
            List<IGeoResource> resourceList, int startPosition2,
            IProject project2, boolean wait) {
       
        IMap map = map2;
        if (map == null && project2 == null)
            map = (IMap) getActiveMap();

        if(map==NO_MAP){
            map = null;
        }
       
        IProject project = project2;
        if (project == null) {
            if (map == null)
                project = ProjectPlugin.getPlugin().getProjectRegistry()
                        .getCurrentProject();
            else
                project = map.getProject();
        }
        List<? extends ILayer> layers;
       
        /*
         * Check or not for duplicate layers in context of the map where georesources are added.
         */
        List<IGeoResource> cleanedGeoResources;
        if(ProjectPlugin.getPlugin().getPluginPreferences().getBoolean(PreferenceConstants.P_CHECK_DUPLICATE_LAYERS)){
            cleanedGeoResources = ProjectUtil.cleanDuplicateGeoResources(resourceList, map);
        }else{
            cleanedGeoResources = resourceList;
        }
       
        if (map == null) {
            CreateMapCommand cmCommand = new CreateMapCommand(null, cleanedGeoResources, project);
            project.sendSync(cmCommand);
            map = cmCommand.getCreatedMap();
            layers=map.getMapLayers();
        } else {
            AddLayersCommand alCommand = new AddLayersCommand(cleanedGeoResources, startPosition2);
            map.sendCommandSync(alCommand);
            layers=alCommand.getLayers();
        }

        if (!ApplicationGISInternal.getOpenMaps().contains(map)) {
            openMap(map, wait);
View Full Code Here

    @SuppressWarnings("unchecked")
    @Override
    public void mousePressed( MapMouseEvent e ) {
       
        //throw a coordinate onto the current map blackboard
        IMap map = ApplicationGIS.getActiveMap();
        if (map == null)
            return
       
        IBlackboard blackboard = map.getBlackboard();
        List<Coordinate> points =
            (List<Coordinate>) blackboard.get("locations");
        if (points == null) {
            points = new ArrayList<Coordinate>();
            blackboard.put("locations",points);
View Full Code Here

    private Display display;

    private static Java2dDrawing java2dDrawing = Java2dDrawing.create();

    public void draw( MapGraphicContext context ) {
        IMap activeMap = ApplicationGIS.getActiveMap();
        IMap currentMap = context.getLayer().getMap();
        if (!activeMap.equals(currentMap)) {
            return;
        }

        IBlackboard blackboard = context.getLayer().getStyleBlackboard();
View Full Code Here

TOP

Related Classes of org.locationtech.udig.project.IMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.