[Gvsig_english] [gvSIG-devel] Herencia de Flayers
Flavio Pompermaier
fla83tn at gmail.com
Fri May 13 11:03:14 CEST 2011
Hi Juan Lucas,
with your suggestion I managed correctly my custom Flayers. The problem was
on reopening projects and I discovered that also topology extension is
affected by this error.
However, in order to extend Flayers the trick is to override the
setParentLayer(), the getXMLEntity() and the setXMLEntity() methods..
obviously this could be avoided if the check in the Flayers was
if (layer instanceof FLayers)
instead of
if (clase.isAssignableFrom(FLayers.class))
This is my code, I hope it could help someone else:
@Override
public void setParentLayer(FLayers lyr) {
super.setParentLayer(lyr);
if (lyr == null) {
return;
}
setMapContext(lyr.getMapContext());
lyr.addLayerCollectionListener(this);
}
@Override
public XMLEntity getXMLEntity() throws XMLException {
XMLEntity xml = new XMLEntity();
xml.putProperty("className", this.getClass().getName());
xml.putProperty("active", isActive());
xml.putProperty("name", getName());
xml.putProperty("minScale", getMinScale());
xml.putProperty("maxScale", getMaxScale());
xml.putProperty("visible", isVisible());
if (getProjection() != null) {
xml.putProperty("proj", getProjection().getAbrev());
}
xml.putProperty("transparency", getTransparency());
// --------------------
xml.putProperty("numLayers", getLayersCount());
String[] s = new String[getLayersCount()];
for (int i = 0; i < getLayersCount(); i++) {
s[i] = getLayer(i).getName();
}
xml.putProperty("LayerNames", s);
for (int i = 0; i < getLayersCount(); i++) {
xml.addChild(getLayer(i).getXMLEntity());
}
xml.putProperty("myCustomProperty", "test");
return xml;
}
public void setXMLEntity(XMLEntity xml) throws XMLException {
setActive(xml.getBooleanProperty("active"));
setName(xml.getStringProperty("name"));
setMinScale(xml.getDoubleProperty("minScale"));
setMaxScale(xml.getDoubleProperty("maxScale"));
setVisible(xml.getBooleanProperty("visible"));
if (xml.contains("proj")) {
setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
}
if (xml.contains("transparency")) {
setTransparency(xml.getIntProperty("transparency"));
}
// ------------
int numLayers = xml.getIntProperty("numLayers");
String[] s = xml.getStringArrayProperty("LayerNames");
for (int i = 0; i < numLayers; i++) {
FLayer layer = null;
try {
String className =
xml.getChild(i).getStringProperty("className");
Class<?> clase = Class.forName(className);
layer = (FLayer) clase.newInstance();
layer.setName(s[i]);
layer.setXMLEntity(xml.getChild(i));
layer.load();
logger.debug("Layer: " + layer.getName() + " has been
loaded.");
}
catch (Exception e) {
logger.error("While loading layer: " + s[i] + " (visible =
false)", e);
//layer.setVisible(false);
}
addLayer(layer);
}
String myCustomProp= xml.getStringProperty("myCustomProperty");
}
Best regards,
Flavio
2011/5/11 Flavio Pompermaier <fla83tn at gmail.com>
> I'll keep you up to date after my tests! Thanks for all
>
> 2011/5/11 Juan Lucas Dominguez Rubio <jldominguez at prodevelop.es>
>
>> Hello, yes that's it. It keeps its own reference to Mapcontext. Does
>> that work for you?
>>
>> If I had to do it again, I would probably promote a change in libFMap
>> though.
>>
>> Regards,
>> Juan Lucas Domínguez Rubio
>> ---
>> Prodevelop SL, Valencia (España)
>> Tlf.: 96.351.06.12 -- Fax: 96.351.09.68
>> http://www.prodevelop.es
>> ---
>>
>> ------------------------------
>> *De:* gvsig-desktop-devel-bounces at lists.forge.osor.eu en nombre de Flavio
>> Pompermaier
>> *Enviado el:* mar 10/05/2011 18:26
>>
>> *Para:* gvSIG developers mailing list
>> *CC:* Users and Developers mailing list
>> *Asunto:* Re: [gvSIG-devel] Herencia de Flayers
>>
>> The problem is actually in the opening of the gvSIG project (gvp).
>> If a class extends FLayers, then it will not have its MapContext during
>> the set setXMLEntity(XMLEntity xml)!
>> There's no way to retrieve it..I wasn't able to test the class you
>> suggested me and I don't know if it solves the problem..maybe it goes around
>> the problem overriding the setParentLayer() method (pasted below)??
>>
>> public void setParentLayer(FLayers lyr) {
>> super.setParentLayer(lyr);
>>
>> if (lyr == null) {
>> return;
>> }
>>
>> myFMap = lyr.getMapContext();
>>
>> if (lyr instanceof LayerCollection) {
>> LayerCollection lyrcol = (LayerCollection) lyr;
>> lyrcol.addLayerCollectionListener(this);
>> }
>> }
>>
>> Thanks for the reply,
>> Flavio
>>
>> 2011/5/10 Juan Lucas Dominguez Rubio <jldominguez at prodevelop.es>
>>
>>> Hola, Flavio:
>>>
>>> Creo que yo encontré este problema cuando hice la capa para servidores
>>> ArcIMS vectorial porque es posible tener varias capas ArcIMS vectorial en
>>> una petición y el resultado era una colección (FLayers). Después de
>>> investigar un poco pude resolverlo pero no recuerdo los detalles. La clase
>>> es esta:
>>>
>>>
>>> https://svn.forge.osor.eu/svn/gvsig-desktop/branches/gvSIG_1.11.0_Mejoras_gvSIG-EIEL/extensions/extArcims/src/es/prodevelop/cit/gvsig/arcims/fmap/layers/FFeatureLyrArcIMSCollection.java
>>>
>>> ¿Quizá es un ejemplo para ti?
>>> ¿En qué momento encuentras el problema concretamente?
>>> ¿Es cuando has salvado el proyecto y quieres abrirlo de nuevo?
>>>
>>> En este momento existen pocos servidores ArcIMS y ninguno tiene capas
>>> vectoriales (solo raster) por lo tanto no puedo ejecutar un ejemplo con mi
>>> código.
>>>
>>> Saludos,
>>> Juan Lucas Domínguez Rubio
>>> ---
>>> Prodevelop SL, Valencia (España)
>>> Tlf.: 96.351.06.12 -- Fax: 96.351.09.68
>>> http://www.prodevelop.es
>>> ---
>>>
>>> ------------------------------
>>> *De:* gvsig-desktop-devel-bounces at lists.forge.osor.eu en nombre de
>>> Flavio Pompermaier
>>> *Enviado el:* mar 10/05/2011 17:04
>>> *Para:* gvSIG developers mailing list; Users and Developers mailing list
>>> *Asunto:* [gvSIG-devel] Herencia de Flayers
>>>
>>> Hola a todos,
>>> salutimi disculpas por mi español...
>>> Quería saber si hay una manera de extender la clase FLayer (para crear grupo
>>> de capas a medida).
>>> Creo que es 'un error en el siguiente control:
>>> clase.isAssignableFrom(FLayers.class).
>>> Específicamente, en FLayers está escrito:
>>>
>>> Class clase = LayerFactory.getLayerClassForLayerClassName(className);
>>> layer = (FLayer) clase.newInstance();
>>> if (clase.isAssignableFrom(FLayers.class)) {
>>> ((FLayers)layer).setMapContext(getMapContext());
>>> ((FLayers)layer).setParentLayer(this);
>>> // layer = new FLayers(getMapContext(),this);
>>> layer.setXMLEntity(xml);
>>> } else {
>>> // Capas Nuevas (externas)
>>> layer.setName(name);
>>> layer.setXMLEntity(xml);
>>> layer.load();
>>> }
>>>
>>> En el caso de Capas Nuevas (externas), no hay manera de establecer el
>>> MapContext en el mi custom FLayers, a menos que corregir el código de la
>>> siguiente manera:
>>>
>>> if (layer instanceof FLayers) {
>>> .....
>>> }
>>>
>>> Algo mal?
>>>
>>> Saludos,
>>> Flavio
>>>
>>> _______________________________________________
>>> gvSIG-desktop-devel mailing list
>>> gvSIG-desktop-devel at lists.forge.osor.eu
>>> https://lists.forge.osor.eu/listinfo/gvsig-desktop-devel
>>>
>>>
>>
>> _______________________________________________
>> Gvsig_internacional mailing list
>> Gvsig_internacional at listserv.gva.es
>> http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.gva.es/pipermail/gvsig_internacional/attachments/20110513/a047ede8/attachment.htm
More information about the Gvsig_internacional
mailing list