mapinfo开发 >> MapXtreme for java基础简单例子代码
最后编辑时间:2021年07月16日 16:22:07【内容简介】该教程罗列了基础代码主要有:MapXtreme加载地图、MapXtreme获取当前地图对象、MapXtreme设置尺寸、MapXtreme距离等等。
package com.testmap; import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension; import javax.swing.JFrame; import com.mapinfo.beans.tools.MapToolBar;import com.mapinfo.beans.vmapj.VisualMapJ;import com.mapinfo.mapdefcontainer.FileMapDefContainer;import com.mapinfo.mapdefcontainer.MapDefContainer;import com.mapinfo.mapj.MapJ;import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;import com.mapinfo.unit.LinearUnit;import com.mapinfo.util.DoublePoint;import com.mapinfo.util.DoubleRect;import com.mapinfo.xmlprot.mxtj.ImageRequestComposer; public class demoMap extends JFrame { BorderLayout layout = new BorderLayout(); MapToolBar mbar = new MapToolBar(); VisualMapJ vj = new VisualMapJ(); public demoMap () { super(); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { // TODO Auto-generated method stub JFrame jf = new demoMap (); jf.setVisible(true); } public void jbInit() throws Exception{ vj.setShowToolTips(true); this.getContentPane().setLayout(layout); this.setSize(new Dimension(800,800)); this.getContentPane().add(mbar,layout.NORTH); this.getContentPane().add(vj,layout.CENTER); //加载地图数据 vj.getMapJ().loadGeoset("E://workspace//TestMap//bin//com//testmap//data//world.gst", "E://workspace//TestMap//bin//com//testmap//data//", null); //获取当前地图对象 MapJ mapobj= vj.getMapJ(); //设置地图缩放(Zoom) mapobj.setZoom(30000); //设置地图测距单位(千米) LinearUnit distUnit = LinearUnit.kilometer; mapobj.setDistanceUnits(distUnit); //设置软件屏幕尺寸 mapobj.setDeviceBounds(new DoubleRect(0,0,800,600)); //设置地图边界坐标 DoubleRect bounds = new DoubleRect(-180,-90,180,90); mapobj.setBounds(bounds); //设置地图边界二 给定地图的中心,宽度和高度 DoubleRect bounds = new DoubleRect(new DoublePoint(36,18),360,180); mapobj.setBounds(bounds); //1.保存为地图文件 MapDefContainer mdc = new FileMapDefContainer("E://workspace//TestMap//bin//com//testmap//data"); mapobj.saveMapDefinition(mdc,"worldmap"); //2.保存数据库表中 String driverName = "com.ibm.db2.jcc.DB2Driver"; //图层居中,看全图 //tableAlias 层别名 public void LayerCenter( string layerName) { MapInfo.Data.Table[] tables=new MapInfo.Data.Table[1]; tables[0] = MapInfo.Engine.Session.Current.Catalog.GetTable(layerName); if(tables[0]==null) return; if(mapControl1.Map.Layers[layerName]==null) return; if(mapControl1.Map.Layers[layerName].Enabled == false) mapControl1.Map.Layers[layerName].Enabled = true; MapInfo.Mapping.IMapLayerFilter iMapLayerFilter = MapInfo.Mapping.MapLayerFilterFactory.FilterByTable(tables); MapInfo.Mapping.MapLayerEnumerator mapLayerEnumerator = mapControl1.Map.Layers.GetMapLayerEnumerator(iMapLayerFilter); mapControl1.Map.SetView(mapLayerEnumerator); OnFeatureUnclick();} }} 分享到: 豆瓣 新浪微博 百度贴吧 QQ空间 QQ好友
复制链接分享给好友或者自己收藏!这里会及时更新中。。。

