GeoTools:如何设置显示范围(bounds)JMapFrame

时间:2014-09-17 13:22:53

标签: java bounds geotools

我想在JFrameMap上设置显示范围

List<SimpleFeature> features = new ArrayList<SimpleFeature>();

GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();

Point point1 = gf.createPoint(new Coordinate(2,3));
Point point2 = gf.createPoint(new Coordinate(4,2));

SimpleFeatureBuilder fb = new SimpleFeatureBuilder(TYPE);

SimpleFeature f;

fb.add(point1);
fb.add("TP-1");

f = fb.buildFeature(null);
features.add(f);

fb.add(point2);
fb.add("TP-2");

f = fb.buildFeature(null);
features.add(f);

SimpleFeatureCollection collection = new ListFeatureCollection(TYPE,features);

Style style = createPointStyle();

Layer layer1 = new FeatureLayer(collection, style);

layer1.setTitle("TEST Map Layer"); 

MapContent map = new MapContent();
map.setTitle("Floor Map");
map.addLayer(layer1);

JMapFrame.showMap(map);

它显示我的观点,但我不喜欢自动范围(边界)设置。 问题是我如何改变它?

1 个答案:

答案 0 :(得分:1)

您可以将视口范围设置为您喜欢的任何内容:

 JMapFrame frame = new JMapFrame(map);
 frame.getMapPane().getMapContent().getViewport().setBounds(envelope);

其中envelope是ReferencedEnvelope。