LayerFactory { protected LevelSetConfig getLevelSetConfigFromWmsCapabilities(List<WmsLayer> layerCapabilities) { LevelSetConfig levelSetConfig = new LevelSetConfig(); double minScaleDenominator = Double.MAX_VALUE; double minScaleHint = Double.MAX_VALUE; Sector sector = new Sector(); for (WmsLayer layerCapability : layerCapabilities) { Double layerMinScaleDenominator = layerCapability.getMinScaleDenominator(); if (layerMinScaleDenominator != null) { minScaleDenominator = Math.min(minScaleDenominator, layerMinScaleDenominator); } Double layerMinScaleHint = layerCapability.getScaleHint().getMin(); if (layerMinScaleHint != null) { minScaleHint = Math.min(minScaleHint, layerMinScaleHint); } Sector layerSector = layerCapability.getGeographicBoundingBox(); if (layerSector != null) { sector.union(layerSector); } } if (!sector.isEmpty()) { levelSetConfig.sector.set(sector); } else { throw new RuntimeException( Logger.makeMessage("LayerFactory", "getLevelSetConfigFromWmsCapabilities", "Geographic Bounding Box Not Defined")); } if (minScaleDenominator != Double.MAX_VALUE) { double minMetersPerPixel = minScaleDenominator * 0.00028; double minRadiansPerPixel = minMetersPerPixel / WorldWind.WGS84_SEMI_MAJOR_AXIS; levelSetConfig.numLevels = levelSetConfig.numLevelsForMinResolution(minRadiansPerPixel); } else if (minScaleHint != Double.MAX_VALUE) { double minMetersPerPixel = minScaleHint; double minRadiansPerPixel = minMetersPerPixel / WorldWind.WGS84_SEMI_MAJOR_AXIS; levelSetConfig.numLevels = levelSetConfig.numLevelsForMinResolution(minRadiansPerPixel); } else { levelSetConfig.numLevels = DEFAULT_WMS_NUM_LEVELS; } return levelSetConfig; } LayerFactory(); Layer createFromGeoPackage(String pathName, Callback callback); Layer createFromWms(String serviceAddress, String layerName, Callback callback); Layer createFromWms(String serviceAddress, List<String> layerNames, Callback callback); Layer createFromWmsLayerCapabilities(WmsLayer layerCapabilities, Callback callback); Layer createFromWmsLayerCapabilities(List<WmsLayer> layerCapabilities, Callback callback); Layer createFromWmts(String serviceAddress, String layerIdentifier, Callback callback); Layer createFromWmtsLayer(WmtsLayer wmtsLayer, Callback callback);  }
@Test public void testGetLevelSetConfigFromWmsCapabilities_Nominal() throws Exception { WmsCapabilities wmsCapabilities = getBoilerPlateWmsCapabilities(); WmsLayer wmsLayer = wmsCapabilities.getNamedLayer(DEFAULT_LAYER_NAME); List<WmsLayer> layerCapabilities = Arrays.asList(wmsLayer); LayerFactory layerFactory = new LayerFactory(); LevelSetConfig levelSetConfig = layerFactory.getLevelSetConfigFromWmsCapabilities(layerCapabilities); assertEquals("Bounding Box", new Sector().setFullSphere(), levelSetConfig.sector); assertEquals("Number of Levels", 47, levelSetConfig.numLevels); }
@Test public void testGetLevelSetConfigFromWmsCapabilities_CoarseScaleDenominator() throws Exception { WmsCapabilities wmsCapabilities = getBoilerPlateWmsCapabilities(); WmsLayer wmsLayer = wmsCapabilities.getNamedLayer(DEFAULT_LAYER_NAME); PowerMockito.when(wmsLayer.getMinScaleDenominator()).thenReturn(1e13); List<WmsLayer> layerCapabilities = Arrays.asList(wmsLayer); LayerFactory layerFactory = new LayerFactory(); LevelSetConfig levelSetConfig = layerFactory.getLevelSetConfigFromWmsCapabilities(layerCapabilities); assertEquals("Number of Levels", 1, levelSetConfig.numLevels); }
@Test public void testGetLevelSetConfigFromWmsCapabilities_NullScaleDenominator() throws Exception { WmsCapabilities wmsCapabilities = getBoilerPlateWmsCapabilities(); WmsLayer wmsLayer = wmsCapabilities.getNamedLayer(DEFAULT_LAYER_NAME); PowerMockito.when(wmsLayer.getMinScaleDenominator()).thenReturn(null); PowerMockito.when(wmsLayer.getScaleHint().getMin()).thenReturn(null); List<WmsLayer> layerCapabilities = Arrays.asList(wmsLayer); LayerFactory layerFactory = new LayerFactory(); LevelSetConfig levelSetConfig = layerFactory.getLevelSetConfigFromWmsCapabilities(layerCapabilities); assertEquals("Number of Levels", 20, levelSetConfig.numLevels); }
@Test public void testGetLevelSetConfigFromWmsCapabilities_CoarseScaleHint() throws Exception { WmsCapabilities wmsCapabilities = getBoilerPlateWmsCapabilities(); WmsLayer wmsLayer = wmsCapabilities.getNamedLayer(DEFAULT_LAYER_NAME); PowerMockito.when(wmsLayer.getMinScaleDenominator()).thenReturn(null); PowerMockito.when(wmsLayer.getScaleHint().getMin()).thenReturn(1336.34670162102); List<WmsLayer> layerCapabilities = Arrays.asList(wmsLayer); LayerFactory layerFactory = new LayerFactory(); LevelSetConfig levelSetConfig = layerFactory.getLevelSetConfigFromWmsCapabilities(layerCapabilities); assertEquals("Number of Levels", 5, levelSetConfig.numLevels); }