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

📄 renderclass.java

📁 CreateMyFirstMap
💻 JAVA
字号:
package myfirstmap;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
import java.awt.Color;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.unit.LinearUnit;
import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;
import java.util.HashMap;
import java.util.Map;
import com.mapinfo.xmlprot.mxtj.SvgConditions;
import com.mapinfo.dp.annotation.AnnotationDataProvider;
import com.mapinfo.dp.annotation.AnnotationDataProviderHelper;
import com.mapinfo.dp.annotation.AnnotationTableDescHelper;
import com.mapinfo.dp.util.LocalDataProviderRef;
import com.mapinfo.mapj.Layer;
import com.mapinfo.graphics.Rendition;
import com.mapinfo.graphics.RenditionImpl;
public class RenderClass
{

public RenderClass()
{
}
public void StudyRenderNameAndMDF()
{
/*In this example, a base map has been created and saved as a named resource. Another map
containing multiple layers has been created and saved as a map definition file. The MDF will be
loaded into the MapJ object. When the ImageRequestComposer object is created, the named
resource will be overlaid by the number of layers specified by the integer value passed in the
constructor.*/
MapJ mapj=new MapJ();
String namedMapURL="file:///E:\\MapInfo\\mapxtreme\\MapXtreme-4.7.0\\Tomcat-4.1\\webapps\\mapxtreme47\\resources\\layers\\world";
String namedMapName="ZPADMINISTRATIVE3";
int overlayIndex=1;//mdf中的地图将有多少层来覆盖现在添加进去的命名地图,这个多少层由overlayIndex决定
String mimeType="image/png";
String mdfFilePath="E:\\MapInfo\\study\\mapmdf\\pointline.mdf";
String mapxtremeURL="http://901-32:8083/mapxtreme47/mapxtreme";
try
{
 mapj.loadMapDefinition(mdfFilePath);
 DoublePoint point=new DoublePoint(108.9608,34.2729);
   DoubleRect bounds=new DoubleRect(point,0.31,0.21);
   mapj.setBounds(bounds) ;
   //set distance unit
   LinearUnit unit=LinearUnit.kilometer ;
   mapj.setDistanceUnits(unit) ;

 mapj.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
}catch(java.io.IOException  ioe)
{
 System.out.println("get a "+ioe.getClass() +"\nwith message "+ioe.getMessage() ) ;
}
ImageRequestComposer imageRC=ImageRequestComposer.create(namedMapURL,namedMapName,mapj,overlayIndex,
                                ImageRequestComposer.MAX_COLORS_TRUECOLOR ,
                                Color.white,mimeType);
  //ImageRequestComposer imageRC2=ImageRequestComposer.create(mapj,256,Color.white ,"image/png");
MapXtremeImageRenderer render=new MapXtremeImageRenderer(mapxtremeURL);
try
{
  render.render(imageRC);
  render.toFile("e:\\mapinfo\\study\\mapimage\\studyRenderNamedAndMDF_1.png") ;
}catch(Exception e)
{
  System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
  e.printStackTrace() ;
}
}
public void studySVG()
{
  Map eventMap = new HashMap();
  eventMap.put("onmouseover", "OnMouseOver_Event");
 SvgConditions svgConditions=new SvgConditions(eventMap);
 String mapxtremeURL="http://901-32:8083/mapxtreme47/mapxtreme";
 String mdfFilePath="E:\\MapInfo\\study\\mapmdf\\pointline.mdf";
 MapJ mapj=new MapJ();

 DoublePoint point=new DoublePoint(108.9608,34.2729);
   DoubleRect bounds=new DoubleRect(point,0.31,0.21);
   mapj.setBounds(bounds) ;
   //set distance unit
   LinearUnit unit=LinearUnit.kilometer ;
   mapj.setDistanceUnits(unit) ;
   try
   {
     mapj.loadMapDefinition(mdfFilePath);
   }catch(java.io.IOException  ioe)
   {
     System.out.println("get a "+ioe.getClass() +"\nwith message "+ioe.getMessage() ) ;
   }
 mapj.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
 ImageRequestComposer imageRC=ImageRequestComposer.create(mapj,256,Color.white ,"image/wbmp");
 imageRC.setSvgConditions(svgConditions) ;
 MapXtremeImageRenderer render=new MapXtremeImageRenderer(mapxtremeURL);
try
 {
   render.render(imageRC);
   render.toFile("e:\\mapinfo\\study\\mapimage\\wbmp_1.wbmp") ;
 }catch(java.lang.Exception  e)
 {
   System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
 }
}
public void studyAnimateLayer()
{
 AnnotationTableDescHelper atdh = new AnnotationTableDescHelper("Animation_Layer");
AnnotationDataProviderHelper adph = new AnnotationDataProviderHelper();
   LocalDataProviderRef ldpr=null;
 try
 {
   ldpr = new LocalDataProviderRef(adph);
 }catch(Exception e)
 {
   e.printStackTrace() ;
   return;
 }
 MapJ mapj=new MapJ();

 DoublePoint point=new DoublePoint(108.9608,34.2729);
   DoubleRect bounds=new DoubleRect(point,0.31,0.21);
   mapj.setBounds(bounds) ;
   //set distance unit
   LinearUnit unit=LinearUnit.kilometer ;
   mapj.setDistanceUnits(unit) ;
    String mdfFilePath="E:\\MapInfo\\study\\mapmdf\\pointline.mdf";
   try
    {
      mapj.loadMapDefinition(mdfFilePath);
    }catch(java.io.IOException ioe)
    {
      ioe.printStackTrace() ;
      return;
    }
    try
    {
      Layer animate_layer = (Layer) mapj.getLayers().insertLayer(ldpr, atdh, 0,
          "Animation_Layer");
      // Create the rendition for the point
  Rendition r = RenditionImpl.getDefaultRendition();
  r.setValue(Rendition.SYMBOL_MODE, Rendition.SymbolMode.IMAGE);
  r.setValue(Rendition.SYMBOL_URL, "file:///e:/mapinfo/study/gif/car.gif");

    }catch(Exception e2)
    {
      System.out.println("get a "+e2.getClass() +"\nwith message "+e2.getMessage() +"\nwith cause "+e2.getCause() ) ;
      e2.printStackTrace() ;
      //return;
    }
   }
public void studyProgress()
{
 // create a MIME that tells the MapXtremeImageRenderer
// to render the map to PNG every three quarters of a second.
String progressiveMime ="multipart/image;imagetype=image/png;interval=750";
// standard ImageRequestComposer using MapJ
 MapJ mapj=new MapJ();
 DoublePoint point=new DoublePoint(108.9608,34.2729);
 DoubleRect bound=new DoubleRect(point,0.31,0.21);
 mapj.setBounds(bound) ;
 LinearUnit unit=LinearUnit.kilometer ;
 mapj.setDistanceUnits(unit) ;
 mapj.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
ImageRequestComposer imageRC = ImageRequestComposer.create(mapj, 256, Color.WHITE, progressiveMime);
// create MapXtremeImageRenderer
 String mapxtremeURL="http://901-32:8083/mapxtreme47/mapxtreme";
MapXtremeImageRenderer render = new MapXtremeImageRenderer(mapxtremeURL);
// while we are not rendering
try
 {
   render.render(imageRC);
   render.toFile("e:\\mapinfo\\study\\png\\progress.png") ;
 }catch(Exception e)
 {
   System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
 }

// get an image from the MapXtreme Servlet

// do something with the image



}
}

⌨️ 快捷键说明

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