Search in sources :

Example 1 with MapService

use of com.revolsys.record.io.format.esri.rest.map.MapService in project com.revolsys.open by revolsys.

the class ArcGisRestServerTileCacheLayer method getOverlappingMapTiles.

@Override
public List<ArcGisRestServerTileCacheMapTile> getOverlappingMapTiles(final Viewport2D viewport) {
    final List<ArcGisRestServerTileCacheMapTile> tiles = new ArrayList<>();
    final MapService mapService = getMapService();
    if (mapService != null) {
        if (!isHasError()) {
            try {
                final double metresPerPixel = viewport.getMetresPerPixel();
                final int zoomLevel = mapService.getZoomLevel(metresPerPixel);
                final double resolution = getResolution(viewport);
                if (resolution > 0) {
                    final BoundingBox viewBoundingBox = viewport.getBoundingBox();
                    final BoundingBox maxBoundingBox = getBoundingBox();
                    final BoundingBox boundingBox = viewBoundingBox.convert(this.geometryFactory).intersection(maxBoundingBox);
                    final double minX = boundingBox.getMinX();
                    final double minY = boundingBox.getMinY();
                    final double maxX = boundingBox.getMaxX();
                    final double maxY = boundingBox.getMaxY();
                    // Tiles start at the North-West corner of the map
                    final int minTileX = mapService.getTileX(zoomLevel, minX);
                    final int minTileY = mapService.getTileY(zoomLevel, maxY);
                    final int maxTileX = mapService.getTileX(zoomLevel, maxX);
                    final int maxTileY = mapService.getTileY(zoomLevel, minY);
                    for (int tileY = minTileY; tileY <= maxTileY; tileY++) {
                        for (int tileX = minTileX; tileX <= maxTileX; tileX++) {
                            final ArcGisRestServerTileCacheMapTile tile = new ArcGisRestServerTileCacheMapTile(this, mapService, zoomLevel, resolution, tileX, tileY);
                            tiles.add(tile);
                        }
                    }
                }
            } catch (final Throwable e) {
                setError(e);
            }
        }
    }
    return tiles;
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) MapService(com.revolsys.record.io.format.esri.rest.map.MapService)

Example 2 with MapService

use of com.revolsys.record.io.format.esri.rest.map.MapService in project com.revolsys.open by revolsys.

the class ArcGisRestServerTileCacheLayer method getResolution.

@Override
public double getResolution(final Viewport2D viewport) {
    final MapService mapService = getMapService();
    if (mapService == null) {
        return 0;
    } else {
        final double metresPerPixel = viewport.getMetresPerPixel();
        final int zoomLevel = mapService.getZoomLevel(metresPerPixel);
        return mapService.getResolution(zoomLevel);
    }
}
Also used : MapService(com.revolsys.record.io.format.esri.rest.map.MapService)

Example 3 with MapService

use of com.revolsys.record.io.format.esri.rest.map.MapService in project com.revolsys.open by revolsys.

the class ArcGisRestServerTileCacheLayer method initializeDo.

@Override
protected boolean initializeDo() {
    synchronized (this.initSync) {
        if (this.mapService == null) {
            try {
                if (Property.hasValue(this.connectionName)) {
                    final WebService<?> webService = WebServiceConnectionManager.getWebService(this.connectionName);
                    if (webService instanceof ArcGisRestCatalog) {
                        final ArcGisRestCatalog catalog = (ArcGisRestCatalog) webService;
                        final WebServiceResource service = catalog.getWebServiceResource(this.servicePath);
                        if (service instanceof MapService) {
                            this.mapService = (MapService) service;
                        } else {
                            Logs.error(this, getPath() + ": Web service " + this.connectionName + " is not a ArcGIS service");
                            return false;
                        }
                    } else {
                        Logs.error(this, getPath() + ": Web service " + this.connectionName + " " + this.servicePath + " is not a ArcGIS Map service");
                        return false;
                    }
                } else {
                    // TODO username/password
                    this.mapService = MapService.getMapService(this.url);
                }
                if (this.mapService == null) {
                    Logs.error(this, "Unable to connect to ArcGIS rest server");
                    return false;
                } else {
                    final TileInfo tileInfo = this.mapService.getTileInfo();
                    if (tileInfo == null) {
                        Logs.info(this, this.url + " does not contain a tileInfo definition.");
                        return false;
                    } else {
                        this.geometryFactory = tileInfo.getGeometryFactory();
                        final BoundingBox boundingBox = this.mapService.getFullExtent();
                        setBoundingBox(boundingBox);
                        return true;
                    }
                }
            } catch (final WrappedException e) {
                final Throwable cause = Exceptions.unwrap(e);
                if (cause instanceof UnknownHostException) {
                    // cause.getMessage());
                    return setNotExists("Unknown host: " + cause.getMessage());
                } else {
                    throw e;
                }
            }
        } else {
            return true;
        }
    }
}
Also used : ArcGisRestCatalog(com.revolsys.record.io.format.esri.rest.ArcGisRestCatalog) TileInfo(com.revolsys.record.io.format.esri.rest.map.TileInfo) WrappedException(com.revolsys.util.WrappedException) UnknownHostException(java.net.UnknownHostException) WebServiceResource(com.revolsys.webservice.WebServiceResource) BoundingBox(com.revolsys.geometry.model.BoundingBox) MapService(com.revolsys.record.io.format.esri.rest.map.MapService)

Aggregations

MapService (com.revolsys.record.io.format.esri.rest.map.MapService)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)2 ArcGisRestCatalog (com.revolsys.record.io.format.esri.rest.ArcGisRestCatalog)1 TileInfo (com.revolsys.record.io.format.esri.rest.map.TileInfo)1 WrappedException (com.revolsys.util.WrappedException)1 WebServiceResource (com.revolsys.webservice.WebServiceResource)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1