Re: [Gvsig_desarrolladores] Como cargar y dibujar etiquetas por código?

Namberwuan namberwuan en hotmail.com
Jue Nov 6 10:29:48 CET 2008


Sumergiendome en FThemeManagerWindow y FPanelLegendLabels he conseguido hacer
una funcion que muestra los label, la dejo aqui por si a alguien le puede
servir de ayuda en otro momento.
Es una funcion que le pasas la capa, el campo que de de etiquetar, el
angulo, el color y si se debe dejar visible el elemento de la capa.



	private void setLabels(FLayer lyr, String field, String angle,float
fontSize,boolean visible, Color color) {
		ClassifiableVectorial aux = (ClassifiableVectorial) lyr;
		Legend renderer=null;
		Font labelFont = new Font("SansSerif", Font.PLAIN, 9);
		FSymbol m_FSymbol;
		
		try {
			renderer = (Legend) aux.getLegend().cloneLegend();
		} catch (XMLException e) {
			
			e.printStackTrace();
		}

		VectorialLegend l=(VectorialLegend)renderer;
		
		m_FSymbol = (FSymbol) l.getDefaultSymbol();
        m_FSymbol.setFont(labelFont);
        l.setLabelField(field);
        l.setLabelHeightField(null);
        l.setLabelRotationField(angle);  
        m_FSymbol.setFontColor(color);
        
        m_FSymbol.setFontSize(fontSize); 
        m_FSymbol.setFontSizeInPixels(false);
        
        m_FSymbol.setShapeVisible(visible);
        l.setDefaultSymbol(m_FSymbol);
        
        try {
			aux.setLegend(l);
		} catch (FieldNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DriverException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		lyr.getMapContext().callLegendChanged(); 
}



Namberwuan wrote:
> 
> Hola, mi intención es la de cargar una capa por código, pero que muestre
> el valor de las etiquetas, 
> Como podria hacerlo???
> 
> 
> FLayer capa= LayerFactory.createLayer("capa.shp",
>         	    (VectorialFileDriver)   LayerFactory.getDM().getDriver("gvSIG
> shp driver"),
>         	    new File(ruta),
>         	    CRSFactory.getCRS("EPSG:23030"));
> 		
> /////
> que deberia venir aqui?
> //////////
> 
> 		
> 		
> 		
> 		 
> 		 mapContext.getLayers().addLayer(capa);
> 
> Gracias.
> 

-- 
View this message in context: http://www.nabble.com/Como-cargar-y-dibujar-etiquetas-por-c%C3%B3digo--tp20340468p20357718.html
Sent from the gvSIG desarrolladores mailing list archive at Nabble.com.




Más información sobre la lista de distribución gvSIG_desarrolladores