Skip to content

Commit 1668b52

Browse files
committed
update
1 parent d32ec41 commit 1668b52

16 files changed

Lines changed: 262 additions & 297 deletions

dist/Mapv.js

Lines changed: 128 additions & 146 deletions
Large diffs are not rendered by default.

dist/Mapv.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ $.ajax({
321321

322322
var layer = new Mapv.Layer({
323323
zIndex: 2,
324+
mapv: mapv,
324325
data: [{
325326
lng: 116.39507,
326327
lat: 39.929101
@@ -348,15 +349,14 @@ $.ajax({
348349
}
349350
}
350351
});
351-
mapv.addLayer(layer);
352-
352+
353353
var layer = new Mapv.Layer({
354354
zIndex: 1,
355355
data: data,
356356
drawType: 'heatmap',
357357
drawOptions: drawOptions
358358
});
359-
mapv.addLayer(layer);
359+
layer.setMapv(mapv);
360360

361361
}
362362
});

src/Drawer/BubbleDrawer.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ function BubbleDrawer() {
1010

1111
util.inherits(BubbleDrawer, Drawer);
1212

13-
BubbleDrawer.prototype.drawMap = function (mapv, ctx) {
13+
BubbleDrawer.prototype.drawMap = function () {
1414

15-
var data = this._layer.getData();
15+
var data = this.getLayer().getData();
16+
17+
var ctx = this.getCtx();
1618

1719
ctx.save();
1820

19-
var drawOptions = this.drawOptions;
21+
var drawOptions = this.getDrawOptions();
2022

2123
if (drawOptions.globalCompositeOperation) {
2224
ctx.globalCompositeOperation = drawOptions.globalCompositeOperation;
@@ -62,13 +64,13 @@ BubbleDrawer.prototype.getRadius = function (val) {
6264
};
6365

6466
BubbleDrawer.prototype.drawDataRange = function () {
65-
var canvas = this.mapv.getDataRangeCtrol().getContainer();
67+
var canvas = this.getMapv().getDataRangeCtrol().getContainer();
6668
canvas.width = 100;
6769
canvas.height = 190;
6870
canvas.style.width = '100px';
6971
canvas.style.height = '190px';
7072
var ctx = canvas.getContext('2d');
71-
ctx.fillStyle = this.drawOptions.fillStyle || 'rgba(50, 50, 200, 0.8)';
73+
ctx.fillStyle = this.getDrawOptions().fillStyle || 'rgba(50, 50, 200, 0.8)';
7274
var splitList = this.splitList;
7375

7476
for (var i = 0; i < splitList.length; i++) {

src/Drawer/CategoryDrawer.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ function CategoryDrawer() {
1111

1212
util.inherits(CategoryDrawer, Drawer);
1313

14-
CategoryDrawer.prototype.drawMap = function (mapv, ctx) {
14+
CategoryDrawer.prototype.drawMap = function () {
1515

16-
var data = this._layer.getData();
16+
var data = this.getLayer().getData();
17+
var ctx = this.getCtx();
1718

1819

19-
var drawOptions = this.drawOptions;
20+
var drawOptions = this.getDrawOptions();
2021

2122
ctx.strokeStyle = drawOptions.strokeStyle;
2223

@@ -50,7 +51,7 @@ CategoryDrawer.prototype.generalSplitList = function () {
5051
};
5152

5253
CategoryDrawer.prototype.drawDataRange = function () {
53-
var canvas = this.mapv.getDataRangeCtrol().getContainer();
54+
var canvas = this.getMapv().getDataRangeCtrol().getContainer();
5455
canvas.width = 80;
5556
canvas.height = 190;
5657
canvas.style.width = "80px";

src/Drawer/ChoroplethDrawer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ function ChoroplethDrawer() {
1010

1111
util.inherits(ChoroplethDrawer, Drawer);
1212

13-
ChoroplethDrawer.prototype.drawMap = function (mapv, ctx) {
13+
ChoroplethDrawer.prototype.drawMap = function () {
1414

15-
var data = this._layer.getData();
15+
var data = this.getLayer().getData();
16+
var ctx = this.getCtx();
1617

17-
18-
var drawOptions = this.drawOptions;
18+
var drawOptions = this.getDrawOptions();
1919

2020
ctx.strokeStyle = drawOptions.strokeStyle;
2121

@@ -36,8 +36,8 @@ ChoroplethDrawer.prototype.drawMap = function (mapv, ctx) {
3636
};
3737

3838
ChoroplethDrawer.prototype.drawDataRange = function () {
39-
var canvas = this.mapv.getDataRangeCtrol().getContainer();
40-
var drawOptions = this.drawOptions;
39+
var canvas = this.getMapv().getDataRangeCtrol().getContainer();
40+
var drawOptions = this.getDrawOptions();
4141
canvas.width = 100;
4242
canvas.height = 190;
4343
canvas.style.width = '100px';

src/Drawer/ClusterDrawer.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ function ClusterDrawer() {
1414

1515
util.inherits(ClusterDrawer, Drawer);
1616

17-
ClusterDrawer.prototype.drawMap = function (mapv, ctx) {
17+
ClusterDrawer.prototype.drawMap = function () {
1818
// console.log('ClusterDrawer');
1919
window.console.time('computerMapData');
20+
var ctx = this.getCtx();
2021
// TODO: ser workder
2122
max = min = undefined;
2223

23-
// var data = mapv.geoData.getData();
24-
var data = this._layer.getData();
25-
console.log(data)
24+
var data = this.getLayer().getData();
2625

27-
var map = mapv.getMap();
26+
var map = this.getMapv().getMap();
2827
var zoom = map.getZoom();
2928
var zoomUnit = this.zoomUnit = Math.pow(2, 18 - zoom);
3029

@@ -150,9 +149,8 @@ ClusterDrawer.prototype.drawMap = function (mapv, ctx) {
150149
ctx.restore();
151150
// }
152151
}
153-
// this.drawDataRange(mapv._dataRangeCtrol.getContainer());
152+
154153
window.console.timeEnd('drawMap');
155-
// console.timeEnd('drawMap')
156154
};
157155

158156
// ClusterDrawer.prototype.drawDataRange = function (canvas, data, drawOptions) {
@@ -165,7 +163,7 @@ ClusterDrawer.prototype.drawMap = function (mapv, ctx) {
165163
ClusterDrawer.prototype.formatParam = function () {
166164

167165
// console.log('AAA')
168-
var options = this.drawOptions;
166+
var options = this.getDrawOptions();
169167
// console.log(options)
170168
var fillColors = this.fillColors = [
171169
[73, 174, 34],

src/Drawer/DensityDrawer.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ var max;
1111
function DensityDrawer() {
1212
this.Scale;
1313
this.masker = {};
14-
this.mapv = null;
15-
this.ctx = null;
1614
Drawer.apply(this, arguments);
1715
}
1816

@@ -32,17 +30,15 @@ DensityDrawer.prototype.scale = function (scale) {
3230
this.Scale = scale;
3331
};
3432

35-
DensityDrawer.prototype.drawMap = function (mapv, ctx) {
33+
DensityDrawer.prototype.drawMap = function () {
3634

3735
var self = this;
38-
mapv = this.mapv = this.mapv || mapv;
39-
ctx = this.ctx = this.ctx || ctx;
36+
var ctx = this.getCtx();
4037

4138
// TODO: use workder
42-
// var data = mapv.geoData.getData();
43-
var data = this._layer.getData();
39+
var data = this.getLayer().getData();
4440

45-
var map = mapv.getMap();
41+
var map = this.getMapv().getMap();
4642
var zoom = map.getZoom();
4743
var zoomUnit = this.zoomUnit = Math.pow(2, 18 - zoom);
4844

@@ -65,7 +61,7 @@ DensityDrawer.prototype.drawMap = function (mapv, ctx) {
6561
};
6662

6763
var gridsObj = {};
68-
if (this.drawOptions.gridType === 'honeycomb') {
64+
if (this.getDrawOptions().gridType === 'honeycomb') {
6965
gridsObj = honeycombGrid(obj);
7066
} else {
7167
gridsObj = recGrids(obj);
@@ -90,7 +86,7 @@ DensityDrawer.prototype.drawMap = function (mapv, ctx) {
9086
};
9187

9288
var gridsObj = {};
93-
if (this.drawOptions.gridType === 'honeycomb') {
89+
if (this.getDrawOptions().gridType === 'honeycomb') {
9490
drawHoneycomb(obj);
9591
} else {
9692
drawRec(obj);
@@ -212,7 +208,7 @@ function drawRec(obj) {
212208
ctx.fillRect(x, y, gridStep - 1, gridStep - 1);
213209

214210

215-
if (self.drawOptions.showNum) {
211+
if (self.getDrawOptions().showNum) {
216212

217213
ctx.save();
218214
// ctx.fillStyle = 'black';
@@ -340,7 +336,7 @@ function drawHoneycomb(obj) {
340336
draw(x, y, gridsW - 1, 'rgba(0,0,0,0.2)', ctx);
341337
}
342338

343-
if (obj.sup.drawOptions.showNum && !isTooSmall && !isTooBig) {
339+
if (obj.sup.getDrawOptions().showNum && !isTooSmall && !isTooBig) {
344340
ctx.save();
345341
ctx.textBaseline = 'middle';
346342
ctx.textAlign = 'center';
@@ -372,7 +368,7 @@ function draw(x, y, gridStep, color, ctx) {
372368
*/
373369
function formatParam() {
374370

375-
var options = this.drawOptions;
371+
var options = this.getDrawOptions();
376372
// console.log(options)
377373
var fillColors = this.fillColors = [
378374
[73, 174, 34],

src/Drawer/Drawer.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,38 @@
77
function Drawer(layer) {
88
Class.call(this);
99

10-
this._layer = layer;
1110
this.mapv = layer._mapv;
12-
this.drawOptions = {};
11+
this.initOptions({
12+
layer: layer,
13+
ctx: null,
14+
mapv: null,
15+
drawOptions: {
16+
radius: 2
17+
}
18+
});
19+
20+
this.bindTo('ctx', layer)
21+
this.bindTo('mapv', layer)
1322
}
1423

1524
util.inherits(Drawer, Class);
1625

17-
18-
Drawer.prototype.defaultDrawOptions = {
19-
radius: 2
20-
};
21-
2226
Drawer.prototype.drawMap = function () {};
2327

2428
// we need defined drawDataRange so that in Mapv.js
2529
// we can shwo or remove range cans by drawer.drawDataRange
2630
// Drawer.prototype.drawDataRange = function () {};
2731

28-
Drawer.prototype.setDrawOptions = function (drawOptions) {
29-
var defaultObj = util.copy(this.defaultDrawOptions);
30-
this.drawOptions = util.extend(defaultObj, drawOptions);
31-
if (this.drawOptions.splitList) {
32-
this.splitList = this.drawOptions.splitList;
32+
Drawer.prototype.drawOptions_changed = function () {
33+
var drawOptions = this.getDrawOptions();
34+
if (drawOptions.splitList) {
35+
this.splitList = drawOptions.splitList;
3336
} else {
3437
this.generalSplitList();
3538
}
3639

3740
this.drawDataRange && this.drawDataRange();
3841

39-
// console.log('set-----',this.drawOptions);
40-
};
41-
42-
Drawer.prototype.getDrawOptions = function () {
43-
// console.log('get-----',this.drawOptions);
44-
return this.drawOptions;
45-
};
46-
47-
Drawer.prototype.clearDrawOptions = function (drawOptions) {
48-
this.drawOptions = {};
4942
};
5043

5144
Drawer.prototype.colors = [
@@ -60,7 +53,7 @@ Drawer.prototype.colors = [
6053
];
6154

6255
Drawer.prototype.generalSplitList = function () {
63-
var dataRange = this._layer.getDataRange();
56+
var dataRange = this.getLayer().getDataRange();
6457
var splitNum = Math.ceil((dataRange.max - dataRange.min) / 7);
6558
var index = dataRange.min;
6659
this.splitList = [];

0 commit comments

Comments
 (0)