?? studyrangedlabeltheme.java~19~
字號:
package myfirstmap;
import com.mapinfo.mapj.FeatureLayer;
import com.mapinfo.labeltheme.RangedLabelTheme;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.unit.LinearUnit;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.mapj.Layers;
import com.mapinfo.labeltheme.LabelThemeList;
import com.mapinfo.dp.ColumnStatistics;
import java.util.List;
import com.mapinfo.dp.util.Bucketer;
import com.mapinfo.graphics.Rendition;
import com.mapinfo.graphics.RenditionImpl;
import java.awt.Color;
import com.mapinfo.dp.util.LinearRenditionSpreader;
import java.util.ArrayList;
import com.mapinfo.mapj.LabelProperties;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;
import com.mapinfo.mapj.DataLayer;
import com.mapinfo.dp.Attribute;
public class StudyRangedLabelTheme
{
private String mdfFilePath="e:\\MapInfo\\study\\mapmdf";
private String mdfFileName="states.mdf";
private String mapxtremeURL="http://901-32:8083/mapxtreme47/mapxtreme";
String TARGET_COLUMN_NAME = "POP_1990";
int NUMBER_OF_BREAKPOINTS = 10;
String TARGET_LAYER_NAME = "STATES";
public StudyRangedLabelTheme()
{
}
public void studyRangedLabelTheme()
{
MapJ mapj=new MapJ();
double zoom = 10000.0;
DataLayer dataLayer=null;
DoublePoint centerPoint=new DoublePoint(-108.8,42.5);
LinearUnit unit=LinearUnit.kilometer ;
DoubleRect bound=new DoubleRect(0,0,800,600);
Layers layers=null;
FeatureLayer featureLayer=null;
try
{
mapj.loadMapDefinition(mdfFilePath + "\\" + mdfFileName);
mapj.setDistanceUnits(unit);
layers = mapj.getLayers();
dataLayer = (DataLayer) layers.get(0);
DoubleRect rect = dataLayer.getBounds();
double width = (rect.xmax - rect.xmin) / 4;
double height = (rect.ymax - rect.ymin) / 4;
mapj.setBounds(new DoubleRect(centerPoint, width, height));
mapj.setDeviceBounds(bound);
}catch(Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
}
//
// obtain a reference to the target layer
// name of the target layer whose labels' appearance will be altered by the RangedLabelTheme
if ((featureLayer = (FeatureLayer)mapj.getLayers().getLayer(TARGET_LAYER_NAME)) != null)
{//begin outer if
// obtain the target layer's LabelThemeList, and add a new RangedLabelTheme theme to it
LabelThemeList labelThemeList = null;
if ((labelThemeList = featureLayer.getLabelThemeList()) != null)
{//begin inner if
/* generate a column statistics object for a specific column within our
target table name of a column in the target layer's underlying table, which the created
RangedLabelTheme will be based upon.
*/
try {
ColumnStatistics columnStatistics = featureLayer.fetchColumnStatistics( TARGET_COLUMN_NAME);
//just study ColumnStatistics class
/*int count=columnStatistics.getCount() ;
Attribute attmax= columnStatistics.getMax() ;
double dmax=attmax.getDouble() ;
Attribute attmin= columnStatistics.getMin() ;
double dmin=attmin.getDouble() ;
double mean= columnStatistics.getMean() ;
double devi= columnStatistics.getStandardDeviation() ;*/
/*
generate a List of breakpoints, such that each breakpoints
represents a specific numeric range into which the records of our
table will be logically grouped.
*/
//number of breakpoint ranges to create for the RangedLabelTheme
List breakPointSeries = (List) Bucketer.computeDistribution(NUMBER_OF_BREAKPOINTS,
columnStatistics, Bucketer.DISTRIBUTION_TYPE_EQUAL_COUNT);
/*DISTRIBUTION_TYPE_EQUAL_COUNT:
Has the same number of records in each range. If you want the Bucketer to group 100 records
into 4 ranges using equal count, it computes the ranges so that approximately 25 records
fall into each range, depending on the rounding factor you set.
*/
/* create two(2) rendition objects that will act as the end-points
for a range of renditions object that are to be created
*/
int bpSize=breakPointSeries.size() ;
for(int ii=0;ii<breakPointSeries.size() ;ii++)
{/*<=800000:8 <=1100000:2 <=1600000:6 <=2600000:5
<=3500000:6 <=4000000:2 <=5100000:7 <=5500000:7
<=7700000:5 <=29800000:9
from this group I find this ranged group is not so good
*/
}
Object obj=breakPointSeries.get(ii);
String str=obj.toString() ;
str="wait";
}
Rendition rendStart = new RenditionImpl();
rendStart.setValue(Rendition.FONT_FAMILY, "Arial");
rendStart.setValue(Rendition.FONT_WEIGHT, 1); // NOTE: 2 == bold
rendStart.setValue(Rendition.FONT_SIZE, 12);
rendStart.setValue(Rendition.SYMBOL_FOREGROUND, Color.red);
Rendition rendEnd = new RenditionImpl();
rendEnd.setValue(Rendition.FONT_FAMILY, "Arial");
rendEnd.setValue(Rendition.FONT_WEIGHT, 2); // NOTE: 2 == bold
rendEnd.setValue(Rendition.FONT_SIZE, 44);
rendEnd.setValue(Rendition.SYMBOL_FOREGROUND, Color.blue);
/* using the two(2) rendition objects, create a series of rendition
objects that represent a gradation from the start rendition to the
end rendition
*/
List renditionSeries = (List) LinearRenditionSpreader.spread(NUMBER_OF_BREAKPOINTS,
rendStart, rendEnd);
/* create an ArrayList of LabelProperties objects, such that each
LabelProperties object within this vector is assigned a rendition
object from our above created series of rendition objects
*/
List labelPropertiesSeries = new ArrayList();
LabelProperties labelProperties = null;
for (int i = 0; i < NUMBER_OF_BREAKPOINTS; i++)
{
labelProperties = new LabelProperties();
labelProperties.setRendition( (Rendition) renditionSeries.get(i));
labelProperties.setLabelColumn(TARGET_COLUMN_NAME);
labelPropertiesSeries.add(labelProperties);
}
/* create a new RangedLabelTheme object and add it to ourconcerned
layer's LabelThemeList object. Create a simple description for the
RangedLabelTheme.
*/
String THEME_DESCRIPTION_NAME = "test_for_ranged_label_theme";
RangedLabelTheme rangedLabelTheme = new RangedLabelTheme(
TARGET_COLUMN_NAME, // java.lang.String
breakPointSeries, // java.util.List
labelPropertiesSeries, // java.util.List
THEME_DESCRIPTION_NAME // java.lang.String
);
labelThemeList.add(rangedLabelTheme);
//
featureLayer.setAutoLabel(true) ;
ImageRequestComposer imageRC=ImageRequestComposer.create(mapj,256,Color.white ,"image/png");
MapXtremeImageRenderer render=new MapXtremeImageRenderer(mapxtremeURL);
render.render(imageRC) ;
render.toFile("E:\\MapInfo\\study\\png\\rangedlabeltheme.png") ;
}catch(Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
}//end try
}//end inner if
}//end outer if
}//end function
}//end this class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -