/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
* 2010-05-05 Jed Young Creation
*/
package chunmap.view;
import chunmap.data.feature.Feature;
import chunmap.model.elem.Envelope;
import chunmap.view.layer.LayerCollection;
import chunmap.view.render.Painter;
import chunmap.view.render.Symbol;
/**
* 地图
*
* @author chunquedong
*
*/
public class Map implements Renderer{
public static int Buffer = 3;
private LayerCollection layers;//图层集合
private View view;// 视图
private Painter painter;// 画图者
public Map(View view, Painter painter) {
this.view = view;
this.painter = painter;
layers = new LayerCollection();
}
public Map(int width, int height)
{
view = new ViewPort(width, height,Buffer);
painter = new Painter(width + Buffer, height + Buffer);
layers = new LayerCollection();
}
public View getView() {
return view;
}
public Painter getPainter() {
return painter;
}
public void fullView() {
view.setViewEnvelop(layers.getEnvelop());
}
public void resetSize(int width, int height)
{
view.resetSize(width, height);
painter.reset(width + Buffer, height + Buffer);
}
public LayerCollection getLayerCollection(){
return layers;
}
public void setLayerCollection(LayerCollection layers){
this.layers=layers;
}
public void render(){
painter.clear();
layers.render(this);
}
// -----------------------------------------------------------渲染回调
@Override
public void draw(Feature data,Symbol symbol,int i) {
if (!Thread.interrupted()) {
if (data == null)return;
//if (!renderableFilter(data))return;
Symbol fsymbol=data.getSymbol();
if(fsymbol!=null){
fsymbol.tryDraw(painter.getGraphics(), data, view);
}else{
symbol.tryDraw(painter.getGraphics(), data, view);
}
}
}
@Override
public double getScale() {
return view.getScale();
}
@Override
public int getHeight() {
return view.getHeight();
}
@Override
public int getWidth() {
return view.getWidth();
}
@Override
public Envelope getViewEnvelop() {
return view.getViewEnvelop();
}
@Override
public Envelope getFilterEnvelop() {
return view.getBufferEnvelop();
}
}