#include "mapitemgeopolyline.h"

#include "osm_math_p.h"


MapItemGeoPolyline::MapItemGeoPolyline(const QPolygonF & p) {
	ignore_scale = true;
	setPolyline(p);
}


void MapItemGeoPolyline::setPolyline(const QPolygonF & p) {
	pol = p;
	updatePolygon();
}


void MapItemGeoPolyline::draw(QPainter * p) {
	p->setPen(pen());
	QPolygonF dp(norm_polygon);
	QPointF pos_offset = mapToView(norm_pos);
	for (auto & i: dp)
		i = mapToView(i) - pos_offset;
	p->drawPolyline(dp);
	setBoundingRect(dp.boundingRect());
}


void MapItemGeoPolyline::updatePolygon() {
	norm_polygon.resize(pol.size());
	for (int i = 0; i < pol.size(); ++i)
		norm_polygon[i] = OSM::geo2xy(pol[i]);
	updateParent();
}
