⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studyrangedlabel.java

📁 CreateMyFirstMap
💻 JAVA
字号:
package secondstudy;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.unit.Distance;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.unit.LinearUnit;
import com.mapinfo.mapj.FeatureLayer;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Image;
import java.awt.Graphics;
import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
import java.awt.Color;
import java.awt.BorderLayout;
import com.mapinfo.mapj.LabelProperties;
import com.mapinfo.labeltheme.LabelThemeList;
import com.mapinfo.labeltheme.RangedLabelTheme;
import java.util.List;
import java.util.ArrayList;
import com.mapinfo.dp.ColumnStatistics;
import com.mapinfo.dp.util.Bucketer;
import com.mapinfo.dp.util.LinearRenditionSpreader;
import com.mapinfo.graphics.Rendition;
import com.mapinfo.graphics.RenditionImpl;
public class StudyRangedLabel  extends JFrame
{//学校怎么使用RangedLabelTheme
  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 StudyRangedLabel()
  {
  }
public void implRangedLabel()
  {
    MapJ mapj=new MapJ();
    DoublePoint centerPoint=new DoublePoint(-108.8,42.5);
    LinearUnit unit=LinearUnit.kilometer ;
    mapj.setDistanceUnits(unit) ;
    mapj.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
    FeatureLayer featureLayer=null;
    DoubleRect bounds=null;
    LabelProperties labelProperties=null;
    LabelThemeList labelThemeList=null;
    try
    {
      mapj.setCenter(centerPoint) ;
      mapj.loadMapDefinition(mdfFilePath + "\\" + mdfFileName);
      featureLayer=(FeatureLayer)mapj.getLayers() .get(0) ;
      DoubleRect rect=featureLayer.getBounds() ;
      double width=rect.xmax -rect.xmin ;
      double height=rect.ymax -rect.ymin ;
      bounds=new DoubleRect(centerPoint,width/4,height/4);
      mapj.setBounds(bounds) ;
      //
      labelThemeList=featureLayer.getLabelThemeList() ;
      ColumnStatistics columnStatistics=featureLayer.fetchColumnStatistics(TARGET_COLUMN_NAME);
      List breakPoints=Bucketer.computeDistribution(NUMBER_OF_BREAKPOINTS,columnStatistics,Bucketer.DISTRIBUTION_TYPE_EQUAL_COUNT );

     /* for(int i=0;i<breakPoints.size() ;i++)
      {
        Object obj=breakPoints.get(i) ;
        String str=obj.toString() ;
        str="wait";
      }*/
     //
     Rendition rendStart=new RenditionImpl();
     rendStart.setValue(Rendition.FONT_FAMILY ,"Arial");
     rendStart.setValue(Rendition.FONT_SIZE ,12) ;
     rendStart.setValue(Rendition.FONT_WEIGHT ,1) ;
     rendStart.setValue(Rendition.SYMBOL_FOREGROUND ,Color.black ) ;
     Rendition rendEnd=new RenditionImpl();
     rendEnd.setValue(Rendition.FONT_FAMILY ,"Arial");
     rendEnd.setValue(Rendition.FONT_SIZE ,31) ;
     rendEnd.setValue(Rendition.FONT_WEIGHT ,1) ;
     rendEnd.setValue(Rendition.SYMBOL_FOREGROUND ,Color.red  ) ;
     List renditionSeries=(List)LinearRenditionSpreader.spread(NUMBER_OF_BREAKPOINTS,rendStart,rendEnd);
    /* for(int j=0;j<labelProps.size() ;j++)
     {
       Rendition rend=(Rendition)labelProps.get(j) ;
       Object obj=rend.getValue(Rendition.FONT_SIZE ) ;
       String str=obj.toString() ;
       str="wait";
     }*/
    List labelPropSeries=new ArrayList();
    for(int jj=0;jj<renditionSeries.size() ;jj++)
    {
      Rendition rend=(Rendition)renditionSeries.get(jj) ;
      labelProperties=new LabelProperties();
      labelProperties.setRendition(rend) ;
      labelPropSeries.add(labelProperties) ;

    }
     RangedLabelTheme labelTheme=new RangedLabelTheme(TARGET_COLUMN_NAME,breakPoints,
         labelPropSeries,"Icando");
     labelThemeList.add(labelTheme) ;
      //
      featureLayer.setAutoLabel(true) ;
      MapXtremeImageRenderer render=new MapXtremeImageRenderer(mapxtremeURL);
      ImageRequestComposer imageRC=ImageRequestComposer.create(mapj,256,Color.white ,"image/png");
      render.render(imageRC) ;
      Image image=render.toImage() ;
      DrawImage drawImage=new DrawImage(image);
      drawImage.repaint() ;
      this.getContentPane().add(drawImage,BorderLayout.CENTER );
      this.setSize(800,600) ;
      this.setVisible(true) ;
      this.show() ;
    }catch(Exception e)
    {
      System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
    }
  }//end this function
  public static void main(String[] args)
  {
    StudyRangedLabel srl=new StudyRangedLabel();
    srl.implRangedLabel() ;
  }
public class DrawImage extends JPanel
  {
    private Image m_img;
    public DrawImage(Image img)
    {
      m_img=img;
    }
    public void paint(Graphics g)
    {
      g.drawImage(m_img,0,0,this) ;
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -