Examples of TileSet


Examples of org.locationtech.udig.catalog.wmsc.server.TileSet

                return null;
            }
            IGeoResourceInfo info = resource.getInfo( new SubProgressMonitor(monitor, 50));
   
            String srs = CRS.toSRS(info.getCRS());
            TileSet tileset = new WMSTileSet();
   
            ReferencedEnvelope bounds = info.getBounds();
            if (bounds == null ) { //$NON-NLS-1$
                WmsPlugin.log("Bounds required for TileSet definition", new NullPointerException("Bounds required for tileset definitio")); //$NON-NLS-1$
                return null;
            }
            double minX = bounds.getMinimum(0);
            double maxX = bounds.getMaximum(0);
            double minY = bounds.getMinimum(1);
            double maxY = bounds.getMaximum(1);
   
            CRSEnvelope bbox = new CRSEnvelope(srs, minX, minY, maxX, maxY);
            tileset.setBoundingBox(bbox);
            tileset.setCoorindateReferenceSystem(srs);
   
            Map<String, Serializable> properties = resource.getPersistentProperties();
            Integer width = Integer.parseInt((String) properties.get(PreferenceConstants.P_TILESET_WIDTH));
            Integer height = Integer.parseInt((String) properties.get(PreferenceConstants.P_TILESET_HEIGHT));
   
            if (width == null) {
                width = PreferenceConstants.DEFAULT_TILE_SIZE;
            }
   
            if (height == null) {
                height = PreferenceConstants.DEFAULT_TILE_SIZE;
            }
   
            tileset.setWidth(width);
            tileset.setHeight(height);
   
            String imageType = (String) properties.get(PreferenceConstants.P_TILESET_IMAGE_TYPE);
   
            if (imageType == null || "".equals(imageType)) { //$NON-NLS-1$
                imageType = PreferenceConstants.DEFAULT_IMAGE_TYPE;
            }
   
            tileset.setFormat(imageType);
   
            /*
             * The layer ID
             */
            tileset.setLayers(info.getName());
   
            String scales = (String) properties.get(PreferenceConstants.P_TILESET_SCALES);
   
            String resolutions = workoutResolutions(scales, new ReferencedEnvelope(bbox), width);
   
            /*
             * If we have no resolutions to try - we wont.
             */
            if ("".equals(resolutions)) { //$NON-NLS-1$
                WmsPlugin.log("Resolutions are required for TileSet generation", new ServiceNotFoundException()); //$NON-NLS-1$
                return null;
            }
            tileset.setResolutions(resolutions);
   
            /*
             * The styles
             */
            String style = ""; //$NON-NLS-1$
            if (resource.canResolve(Layer.class)) {
                Layer layer = resource.resolve(Layer.class, new SubProgressMonitor(monitor, 50));
                StringBuilder sb = new StringBuilder(""); //$NON-NLS-1$
                for( StyleImpl layerStyle : layer.getStyles() ) {
                    sb.append(layerStyle.getName()+","); //$NON-NLS-1$
                }
                style = sb.toString();
            }
            if (style.length()>0){
                tileset.setStyles(style.substring(0, style.length()-1));
            } else {
                tileset.setStyles(style);
            }
   
            /*
             * The server is where tiles can be retrieved
             */
            tileset.setServer(server);
            return tileset;
        }
        finally {
             monitor.done();
        }
View Full Code Here

Examples of org.locationtech.udig.catalog.wmsc.server.TileSet

    }

    private TileRange createTileRange( WMTSource wmtSource, WMTRenderJob renderJob,
            Map<String, Tile> tileList ) {
        TileRange range;
        TileSet tileset = new WMTTileSetWrapper(wmtSource);
   
        String value = CatalogPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_WMSCTILE_CACHING);
        if (value.equals(WMSCTileCaching.ONDISK.toString())) {
            String dir = CatalogPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_WMSCTILE_DISKDIR);
            WMTTileImageReadWriter tileReadWriter = new WMTTileImageReadWriter(dir);
View Full Code Here

Examples of org.locationtech.udig.catalog.wmsc.server.TileSet

            return null;
        }

        if (resolve instanceof IGeoResource && adapter.isAssignableFrom(TileSet.class)) {
            IGeoResource resource = (IGeoResource) resolve;
            TileSet tileSet = WMSCTileUtils.toTileSet(resource, server, monitor);
           
            return adapter.cast( tileSet );
        }
        return null;
    }
View Full Code Here

Examples of org.locationtech.udig.catalog.wmsc.server.TileSet

        return false;
    }

    public AbstractRenderMetrics createMetrics( IRenderContext context ) {
        TileSet tileset = null;
        try {
            tileset = context.getLayer().getResource(TileSet.class, null);
        } catch (IOException e) {
            WMSPlugin.log("Cannot create render metrics from wmsc", e);
        }
View Full Code Here

Examples of org.locationtech.udig.catalog.wmsc.server.TileSet

        setState(STARTING);

        IGeoResource handle = getContext().getLayer().findGeoResource(TileSet.class);

        try {
            TileSet tileset = handle.resolve(TileSet.class, new SubProgressMonitor(monitor, 30));
            AbstractOpenWebService server = null;

            if (handle.canResolve(WebMapServer.class)) {
                server = handle.resolve(WebMapServer.class, new SubProgressMonitor(monitor, 30));
            }
            if (handle.canResolve(TiledWebMapServer.class)) {
                server = handle.resolve(TiledWebMapServer.class,
                        new SubProgressMonitor(monitor, 30));
            }

            // determine the bounds that need to be rendered
            ReferencedEnvelope bounds = getRenderBounds();
            if (bounds == null) {
                ReferencedEnvelope viewbounds = getContext().getImageBounds();
                if (getContext().getCRS().equals(viewbounds.getCoordinateReferenceSystem())) {
                    bounds = viewbounds;
                }
            }

            // ensure the bounds are in the right CRS
            if (!bounds.getCoordinateReferenceSystem().equals(
                    tileset.getCoordinateReferenceSystem())) {
                // need to reproject the bounds to the tile coordinate reference system.
                MathTransform transform = CRS.findMathTransform(
                        bounds.getCoordinateReferenceSystem(),
                        tileset.getCoordinateReferenceSystem());
                bounds = new ReferencedEnvelope(JTS.transform(bounds, transform),
                        tileset.getCoordinateReferenceSystem());
            }

            // determine scale factor used to determine zoom level
            // compute the scale factor based on the viewport size; we cannot use the bounds and
            // tile size becuase the
            // bounds may not be the full size of the tile and we might get the wrong scale
            double scaleFactor = getContext().getViewportModel().getBounds().getWidth()
                    / getContext().getMapDisplay().getWidth();

            // create a TileRange to handle loading the tiles
            com.vividsolutions.jts.geom.Envelope bnds = new com.vividsolutions.jts.geom.Envelope(
                    bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY());

            Map<String, Tile> tilesInRange = tileset.getTilesFromViewportScale(bnds, scaleFactor);

            // look up the preference for caching tiles on-disk or in
            // memory and use the proper tilerange for that.
            TileRange range = null;
            String value = CatalogPlugin.getDefault().getPreferenceStore()
                    .getString(PreferenceConstants.P_WMSCTILE_CACHING);
            if (value.equals(WMSCTileCaching.ONDISK.toString())) {
                range = new TileRangeOnDisk(server, tileset, bnds, tilesInRange,
                        requestTileWorkQueue, writeTileWorkQueue);
            } else {
                range = new TileRangeInMemory(server, tileset, bnds, tilesInRange,
                        requestTileWorkQueue);
            }

            // create an empty raster symbolizer for rendering
            RasterSymbolizer style = styleBuilder.createRasterSymbolizer();

            // setup how much each tile is worth for the monitor work %
            int tileCount = range.getTileCount();
            int tileWorth = (tileCount / 100) * tileCount;

            int thisid = 0;
            if (testing) {
                staticid++;
                thisid = staticid;
            }

            // first render any tiles that are ready and render non-ready tiles with blank images
            Map<String, Tile> tiles = range.getTiles();
            Set<String> notRenderedTiles = new HashSet<String>();
            Set<String> renderedTiles = new HashSet<String>();

            for( String key : tiles.keySet() ) {
                if (monitor.isCanceled()) {
                    setState(CANCELLED);
                    if (testing) {
                        System.out.println("monitor CANCELED!!!: " + thisid); //$NON-NLS-1$
                    }
                    return;
                }
                Tile tile = tiles.get(key);
                if (tile != null && tile.getBufferedImage() != null
                        && tile.getTileState() != WMSTile.INERROR) {
                    renderTile(graphics, tile, tileset.getCoordinateReferenceSystem(), style);
                    renderedTiles.add(key);
                    monitor.worked(tileWorth); // inc the monitor work by 1 tile
                } else {
                    // set the tile blank (removing any previous content) and add it
                    // to be drawn later
                    renderBlankTile(graphics, tile, tileset.getCoordinateReferenceSystem());
                    notRenderedTiles.add(key);
                }
            }
            setState(RENDERING);

            // if the tilerange is not already completed, then load
            // the missing tiles
            if (!notRenderedTiles.isEmpty()) {
                if (monitor.isCanceled()) {
                    setState(CANCELLED);
                    if (testing) {
                        System.out.println("monitor CANCELED!!!: " + thisid); //$NON-NLS-1$
                    }
                    return;
                }

                // set the listener on the tile range
                range.addListener(listener);

                // load the missing tiles by sending requests for them
                range.loadTiles(monitor);

                // block until all the missing tiles have come through (and draw them
                // as they are added to the blocking queue
                while( !notRenderedTiles.isEmpty() ) {
                    // check that the rendering is not canceled
                    if (monitor.isCanceled()) {
                        setState(CANCELLED);
                        if (testing) {
                            System.out.println("monitor CANCELED!!!: " + thisid); //$NON-NLS-1$
                        }
                        tilesToDraw_queue.clear();
                        return;
                    }

                    if (testing) {
                        System.out.println("BLOCKED: " + thisid); //$NON-NLS-1$
                        System.out.println("waiting on: " + notRenderedTiles.size() + " tiles"); //$NON-NLS-1$ //$NON-NLS-2$
                    }

                    Tile tile = null;
                    try {
                        tile = (Tile) tilesToDraw_queue.take(); // blocks until a tile is ready to
                                                                // take
                        if (testing) {
                            System.out.println("removed from queue: " + tile.getId()); //$NON-NLS-1$
                        }
                    } catch (InterruptedException ex) {
                        if (testing) {
                            System.out.println("InterruptedException trying to take: " + ex); //$NON-NLS-1$
                        }
                    }

                    if (testing) {
                        System.out.println("UNBLOCKED!!!: " + thisid); //$NON-NLS-1$
                    }

                    // check that the rendering is not canceled again after block
                    if (monitor.isCanceled()) {
                        setState(CANCELLED);
                        if (testing) {
                            System.out.println("monitor CANCELED!!!: " + thisid); //$NON-NLS-1$
                        }

                        tilesToDraw_queue.clear();
                        return;
                    }

                    // check that the tile's bounds are within the current
                    // context's bounds (if it's not, don't bother drawing it) and also
                    // only draw tiles that haven't already been drawn (panning fast
                    // can result in listeners being notified the same tile is ready multiple
                    // times but we don't want to draw it more than once per render cycle)
                    // ReferencedEnvelope viewbounds = getContext().getViewportModel().getBounds();
                    ReferencedEnvelope viewbounds = getContext().getImageBounds();
                    if (tile != null && tile.getBufferedImage() != null && viewbounds != null
                            && viewbounds.intersects(tile.getBounds())
                            && !renderedTiles.contains(tile.getId())) {

                        renderTile(graphics, tile, tileset.getCoordinateReferenceSystem(), style);
                        renderedTiles.add(tile.getId());
                        monitor.worked(tileWorth); // inc the monitor work by 1 tile
                        setState(RENDERING); // tell renderer new data is ready
                    }

View Full Code Here

Examples of tiled.core.TileSet

    return false;
  }

  private void removeUnusedTilesets(final Map map) {
    for (final Iterator< ? > sets = map.getTilesets().iterator(); sets.hasNext();) {
      final TileSet tileset = (TileSet) sets.next();

      if (!isUsedTileset(map, tileset)) {
        sets.remove();
      }
    }
View Full Code Here

Examples of tiled.core.TileSet

   *
   * @param map the map to be broomed
   */
  private void removeUnusedTilesets(final Map map) {
    for (final Iterator< ? > sets = map.getTilesets().iterator(); sets.hasNext();) {
      final TileSet tileset = (TileSet) sets.next();

      if (!isUsedTileset(map, tileset)) {
        sets.remove();
      }
    }
View Full Code Here

Examples of tiled.core.TileSet

        continue;
      }
     
      if (!setByName.containsKey(name)) {
        // The tileset's not yet included. Add it to the map
        TileSet set = new TileSet();
        set.setName(constructTilesetName(name));
        BasicTileCutter cutter = new BasicTileCutter(32, 32, 0, 0);
        set.importTileBitmap(name, cutter);
       
        setByName.put(name, set);
        map.addTileset(set);
      }
    }
View Full Code Here

Examples of tiled.core.TileSet

   * @param tile The tile to be translated
   * @return Translated tile
   */
  Tile translateTile(Tile tile) {
    int id = tile.getId();
    TileSet set = tile.getTileSet();
    TileInfo info = mapping.getTile(set.getTilebmpFile(), id);
    if (info != null) {
      TileSet newSet = setByName.get(info.file);
      tile = newSet.getTile(info.index);
    }
   
    return tile;
  }
View Full Code Here

Examples of tiled.core.TileSet

    }

    private TileSet unmarshalTilesetFile(InputStream in, String filename)
        throws Exception
    {
        TileSet set = null;
        Node tsNode;

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            //builder.setErrorHandler(new XMLErrorHandler());
            Document tsDoc = builder.parse(in, ".");

            String xmlPathSave = xmlPath;
            if (filename.indexOf(File.separatorChar) >= 0) {
                xmlPath = filename.substring(0,
                        filename.lastIndexOf(File.separatorChar) + 1);
            }

            NodeList tsNodeList = tsDoc.getElementsByTagName("tileset");

            // There can be only one tileset in a .tsx file.
            tsNode = tsNodeList.item(0);
            if (tsNode != null) {
                set = unmarshalTileset(tsNode);
                if (set.getSource() != null) {
                    System.out.println("Recursive external tilesets are not supported.");
                }
                set.setSource(filename);
            }

            xmlPath = xmlPathSave;
        } catch (SAXException e) {
            error = "Failed while loading " + filename + ": " +
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.