Skip to content

Commit d1ca039

Browse files
committed
[BUG] chart and pixelratio #1109
1 parent 4ebe755 commit d1ca039

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

examples/map/map.clustering.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515

1616
<!-- Openlayers -->
1717
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
18+
1819
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
20+
<!--
21+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@v10.2.0/dist/ol.js"></script>
22+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@v9.2.0/dist/ol.js"></script>
23+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@v8.1.0/dist/ol.js"></script>
24+
<script type="text/javascript" src="https://openlayers.org/en/v6.15.1/build/ol.js"></script>
25+
-->
1926

2027

2128
<!-- ol-ext -->
@@ -117,6 +124,7 @@ <h2>Select options:</h2>
117124
var data = [0,0,0,0];
118125
for (var i=0, f; f=features[i]; i++) data[f.get('type')]++;
119126
var style = styleCache[data.join(',')];
127+
style = false;
120128
if (!style) {
121129
var radius = Math.min(size+7, 20);
122130
style = styleCache[data.join(',')] = new ol.style.Style({
@@ -235,7 +243,6 @@ <h2>Select options:</h2>
235243
})
236244

237245
function testFontLoaded () {
238-
console.log('TEST', $(".maki-bus").width())
239246
// Loaded ?
240247
if ($(".maki-bus").width() > 60) {
241248
styleCache = {};

examples/style/map.style.chart.html

+24-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@
1616

1717
<!-- Openlayers -->
1818
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
19+
1920
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
21+
22+
<!--
23+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@v10.2.0/dist/ol.js"></script>
24+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@v9.2.0/dist/ol.js"></script>
25+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@v8.1.0/dist/ol.js"></script>
26+
<script type="text/javascript" src="https://openlayers.org/en/v6.15.1/build/ol.js"></script>
27+
-->
2028

2129

2230
<!-- ol-ext -->
@@ -83,8 +91,11 @@ <h2>Options:</h2>
8391
var styleCache = {};
8492

8593
function getFeatureStyle (feature, sel) {
86-
var k = $("#graph").val()+"-"+ $("#color").val()+"-"+(sel?"1-":"")+feature.get("data");
87-
var style = styleCache[k];
94+
var key = $("#graph").val()
95+
+"-"+ $("#color").val()
96+
+"-"+ (sel?"sel":"nsel")
97+
+"-"+ feature.get("data").join('-');
98+
var style = styleCache[key];
8899
if (!style) {
89100
var radius = 15;
90101
// area proportional to data size: s=PI*r^2
@@ -93,7 +104,7 @@ <h2>Options:</h2>
93104
}
94105
// Create chart style
95106
var c = $("#color").val();
96-
styleCache[k] = style = [
107+
styleCache[key] = style = [
97108
new ol.style.Style({
98109
image: new ol.style.Chart({
99110
type: $("#graph").val(),
@@ -113,14 +124,22 @@ <h2>Options:</h2>
113124
})
114125
}),
115126
/*
127+
new ol.style.Style({
128+
text: new ol.style.Text({
129+
text: key,//feature.get("data").join('-'),
130+
fill: new ol.style.Fill({
131+
color: '#000'
132+
})
133+
})
134+
}),
116135
new ol.style.Style({
117136
image: new ol.style.Circle({
118137
radius: 5,
119138
stroke: new ol.style.Stroke({ color: '#fff', width: 1.5 }),
120139
fill: new ol.style.Fill({ color: '#f00' })
121140
})
122141
})
123-
*/
142+
/**/
124143
];
125144
}
126145
style[0].getImage().setAnimation(animation);
@@ -189,7 +208,7 @@ <h2>Options:</h2>
189208
//map.renderSync();
190209
}
191210

192-
doAnimate();
211+
// doAnimate();
193212
</script>
194213

195214
</body>

src/style/Chart.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ var ol_style_Chart = class olstyleChart extends ol_style_RegularShape {
6464
if (!this._colors)
6565
this._colors = ol_style_Chart.colors.classic;
6666
}
67-
68-
this.renderChart_();
6967
}
7068
/**
7169
* Clones the style.
@@ -100,7 +98,6 @@ var ol_style_Chart = class olstyleChart extends ol_style_RegularShape {
10098
*/
10199
setData(data) {
102100
this._data = data;
103-
this.renderChart_();
104101
}
105102
/** Get symbol radius
106103
*/
@@ -114,7 +111,6 @@ var ol_style_Chart = class olstyleChart extends ol_style_RegularShape {
114111
setRadius(radius, ratio) {
115112
this._radius = radius;
116113
this.donuratio_ = ratio || this.donuratio_;
117-
this.renderChart_();
118114
}
119115
/** Set animation step
120116
* @param {false|number} false to stop animation or the step of the animation [0,1]
@@ -130,11 +126,12 @@ var ol_style_Chart = class olstyleChart extends ol_style_RegularShape {
130126
this._animation.animate = true;
131127
this._animation.step = step;
132128
}
133-
this.renderChart_();
134129
}
135130
/** @private
136131
*/
137-
renderChart_(pixelratio) {
132+
getImage(pixelratio) {
133+
pixelratio = pixelratio || 1;
134+
/*
138135
if (!pixelratio) {
139136
if (this.getPixelRatio) {
140137
pixelratio = window.devicePixelRatio;
@@ -146,6 +143,7 @@ var ol_style_Chart = class olstyleChart extends ol_style_RegularShape {
146143
}
147144
return;
148145
}
146+
*/
149147

150148
var strokeStyle;
151149
var strokeWidth = 0;
@@ -156,7 +154,7 @@ var ol_style_Chart = class olstyleChart extends ol_style_RegularShape {
156154
}
157155

158156
// no atlas manager is used, create a new canvas
159-
var canvas = this.getImage(pixelratio);
157+
var canvas = super.getImage(pixelratio);
160158

161159
// draw the circle on the canvas
162160
var context = (canvas.getContext('2d'));
@@ -266,6 +264,9 @@ var ol_style_Chart = class olstyleChart extends ol_style_RegularShape {
266264
anchor[0] = c - this._offset[0];
267265
anchor[1] = c - this._offset[1];
268266
}
267+
268+
// return image
269+
return canvas;
269270
}
270271
};
271272

0 commit comments

Comments
 (0)