-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapUtils.js
68 lines (54 loc) · 2.69 KB
/
MapUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// This file is part of DQX - (C) Copyright 2014, Paul Vauterin, Ben Jeffery, Alistair Miles <[email protected]>
// This program is free software licensed under the GNU Affero General Public License.
// You can find a copy of this license in LICENSE in the top directory of the source code or at <http://opensource.org/licenses/AGPL-3.0>
define(["jquery", "DQX/DocEl", "DQX/Msg", "DQX/Utils", "DQX/Map", "DQX/SVG"],
function ($, DocEl, Msg, DQX, Map, SVG) {
var MapUtils = {};
MapUtils.PieChartLayouter = function (imap, ioffset) {
var that = {};
that._map = imap;
that._layoutCalculated = false;
that._offset = ioffset;
that._pies = [];
that._onClickCallBack = null;
that.setOnClickCallBack = function(handler) {
that._onClickCallBack = handler;
}
// position: coordinates of the center position (of type Map.Coord)
// pieChart: piechart data (of type SVG.PieChart)
that.addPieChart = function(position, pieChart, radius) {
that._layoutCalculated = false;
var pie = Map.Overlay.PieChart(that._map, null,
position,
radius, pieChart);
that._pies.push(pie);
// We hack ourselves in the middle of the rendering call, so that we get notified if the pie chart is about to be rendered
pie._render_orig_replacedlayouter = pie.render;
pie.render = function() {
that._updateOffsetsIfNeeded();
return pie._render_orig_replacedlayouter();
}
pie.onClick = function(obj,id) {
if (that._onClickCallBack!=null)
that._onClickCallBack(pieChart,id);
}
7
}
that._updateOffsetsIfNeeded = function() {
if (that._layoutCalculated) return;
if (that._offset>0) {
var graphics = Map.MapItemLayouter(that._map, '', that._offset);
$.each(that._pies, function(idx,pie) {
graphics.addItem(pie._centerCoordPieChart.longit, pie._centerCoordPieChart.lattit, pie.myRadius);
});
}
graphics.calculatePositions();
$.each(that._pies, function(idx,pie) {
pie.setCoord(Map.Coord(graphics.items[idx].longit2, graphics.items[idx].lattit2));
});
that._layoutCalculated = true;
}
return that;
}
return MapUtils;
});