Original User: jjoalland13 You can detect the spatial reference before you add the tpk to the map.
final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada_myScheme.tpk");
tl.initializeAsync();
tl.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
System.out.println("init" + tl.getDefaultSpatialReference().getText());
//add it to the map if you are happy with the spatial reference
map.getLayers().add(tl);
}
});
When I try your solution with asynchronous initialize, I still can't get the Spatial Reference of the TPK before adding it to the map... tl.getDefaultSpatialReference is always Null !for exemple, my following code (using tl.initializeAsync(); ) :@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
count++;
ArcGISLocalTiledLayer layer = (ArcGISLocalTiledLayer) e.getLayer();
if (layer.getStatus() == LayerStatus.INITIALIZED) {
System.out.println(String.format(count + "-LayerInitializeCompleteEvent- Layer '%s' is initialized !", layer.getName()));
if (layer.getSpatialReference() != null) {
System.out.println(count + " layer spatial ref : " + layer.getSpatialReference().getText());
}
else {
System.out.println(count + " layer spatial ref IS NULL !!!");
}
//add it to the map if you are happy with the spatial reference
map.getLayers().add(layer);
} else {
System.out.println(String.format(count + "-LayerInitializeCompleteEvent- ERROR: Layer '%s' has status : '%s'", layer.getName(), layer.getStatus())); }
}
produce following output result when I click load 2 TPK from same spatial ref :Java version : 1.7.0_07 (Oracle Corporation) x86
Rendering engine : DirectX
1-LayerInitializeCompleteEvent- Layer 'C:\temp\Canada.tpk' is initialized !
1 layer spatial ref IS NULL !!!
-MapEventListenerAdapter- Map is ready !
2-LayerInitializeCompleteEvent- Layer 'C:\temp\Canada_cities.tpk' is initialized !
2 layer spatial ref IS NULL !!!