use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class OwcXmlIO method readEntry.
private static MapItem readEntry(final EntryType entry) throws JAXBException, FactoryException, DataStoreException {
final List<Object> entryContent = entry.getAuthorOrCategoryOrContent();
String layerName = "";
String layerTitle = "";
String layerAbstract = "";
boolean visible = true;
boolean selectable = true;
double layerOpacity = 1.0;
MapItem mapItem = null;
MutableStyle baseStyle = null;
MutableStyle selectionStyle = null;
final List<MapItem> children = new ArrayList<>();
for (Object o : entryContent) {
QName name = null;
if (o instanceof JAXBElement) {
final JAXBElement jax = (JAXBElement) o;
name = jax.getName();
o = jax.getValue();
if (GEOTK_FACTORY._Visible_QNAME.equals(name)) {
visible = (Boolean) o;
} else if (GEOTK_FACTORY._Selectable_QNAME.equals(name)) {
selectable = (Boolean) o;
} else if (GEOTK_FACTORY._Opacity_QNAME.equals(name)) {
layerOpacity = (Double) o;
}
}
if (o instanceof OfferingType) {
final OfferingType offering = (OfferingType) o;
for (OwcExtension ext : getExtensions()) {
if (ext.getCode().equals(offering.getCode())) {
mapItem = ext.createLayer(offering);
break;
}
}
// search for styles
baseStyle = readStyle(offering, true);
selectionStyle = readStyle(offering, false);
} else if (o instanceof ContentType) {
// decode children
final ContentType content = (ContentType) o;
final List<Object> contentContent = content.getContent();
for (Object co : contentContent) {
if (co instanceof JAXBElement) {
co = ((JAXBElement) o).getValue();
}
if (co instanceof EntryType) {
children.add(readEntry((EntryType) co));
}
}
} else if (o instanceof IdType) {
final IdType idType = (IdType) o;
final String value = idType.getValue();
layerName = value;
} else if (o instanceof TextType) {
final TextType tt = (TextType) o;
if (ATOM_FACTORY._EntryTypeTitle_QNAME.equals(name)) {
if (!tt.getContent().isEmpty()) {
layerTitle = (String) tt.getContent().get(0);
}
} else if (ATOM_FACTORY._EntryTypeSummary_QNAME.equals(name)) {
if (!tt.getContent().isEmpty()) {
layerAbstract = (String) tt.getContent().get(0);
}
}
}
}
if (mapItem == null) {
mapItem = MapBuilder.createItem();
} else if (mapItem instanceof MapLayer) {
if (baseStyle != null) {
((MapLayer) mapItem).setStyle(baseStyle);
}
((MapLayer) mapItem).setOpacity(layerOpacity);
}
mapItem.setIdentifier(layerName);
mapItem.setTitle(layerTitle);
mapItem.setAbstract(layerAbstract);
mapItem.setVisible(visible);
if (mapItem instanceof MapLayers) {
((MapLayers) mapItem).getComponents().addAll(children);
} else if (!children.isEmpty()) {
throw new IllegalArgumentException("MapLayer can not have children layers.");
}
return mapItem;
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class WMCUtilities method getMapContext.
/**
* This method will get WMC informations to create a new valid
* {@link MapContext}.
*
* @param source : An {@link InputSream}, the WMC as an xml.
* @return A map context containing informations given by a wmc document.
* @throws JAXBException if the xml cannot be read.
*/
public static MapLayers getMapContext(InputStream source) throws JAXBException {
final MarshallerPool pool = getMarshallerPool();
final Unmarshaller um = pool.acquireUnmarshaller();
Object o = um.unmarshal(source);
if (o instanceof JAXBElement) {
o = ((JAXBElement) o).getValue();
}
// Get needed markups
ViewContextType root = (ViewContextType) o;
final MapLayers context = getMapContext(root);
pool.recycle(um);
return context;
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class WMCUtilitiesTest method testGetMapContext.
/**
* Test of getMapContext method, of class WMCUtilities.
*/
@Test
public void testGetMapContext() throws Exception {
MapLayers context = WMCUtilities.getMapContext(this.getClass().getResourceAsStream("testWMC_wms.xml"));
assertNotNull(context);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class WMTSClientDemo method main.
public static void main(String[] args) throws Exception {
Demos.init();
final MapLayers context = createContext();
// FXMapFrame.show(context);
}
use of org.apache.sis.portrayal.MapLayers in project geotoolkit by Geomatys.
the class WMTSClientDemo method createContext.
public static MapLayers createContext() throws Exception {
final MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
final WebMapTileClient server = new WebMapTileClient(new URL("http://localhost:8080/constellation/WS/wmts/test"), WMTSVersion.v100);
for (final Resource ref : DataStores.flatten(server, false)) {
final GenericName n = ref.getIdentifier().get();
System.out.println(n);
final MapLayer layer = MapBuilder.createCoverageLayer(ref, new DefaultStyleFactory().style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER));
TiledResource model = (TiledResource) ref;
System.out.println(model);
layer.setTitle(n.tip().toString());
context.getComponents().add(layer);
}
return context;
}
Aggregations