Skip to content

Commit 98bc9bd

Browse files
committed
[VER] 4.0.27
1 parent f46af6f commit 98bc9bd

File tree

3 files changed

+4
-288
lines changed

3 files changed

+4
-288
lines changed

dist/ol-ext.js

+1-285
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* ol-ext - A set of cool extensions for OpenLayers (ol) in node modules structure
33
* @description ol3,openlayers,popup,menu,symbol,renderer,filter,canvas,interaction,split,statistic,charts,pie,LayerSwitcher,toolbar,animation
4-
* @version v4.0.26
4+
* @version v4.0.27
55
* @author Jean-Marc Viglino
66
* @see https://github.com/Viglino/ol-ext#,
77
* @license BSD-3-Clause
@@ -41529,290 +41529,6 @@ ol.style.Chart = class olstyleChart extends ol.style.RegularShape {
4152941529
].join('-')
4153041530
return opt;
4153141531
}
41532-
/** @private
41533-
*/
41534-
getImage(pixelratio) {
41535-
var canvas = super.getImage(pixelratio);
41536-
if (this._done !== pixelratio) {
41537-
this.draw_(null, canvas.getContext('2d'), pixelratio)
41538-
}
41539-
return canvas;
41540-
}
41541-
/** @private
41542-
*/
41543-
draw_(renderOptions, context, pixelratio) {
41544-
pixelratio = pixelratio || 1;
41545-
console.log('draw', pixelratio)
41546-
this._done = pixelratio;
41547-
// Get canvas
41548-
//var canvas = super.getImage(pixelratio);
41549-
var canvas = context.canvas;
41550-
var strokeStyle;
41551-
var strokeWidth = 0;
41552-
if (this._stroke) {
41553-
strokeStyle = ol.color.asString(this._stroke.getColor());
41554-
strokeWidth = this._stroke.getWidth();
41555-
}
41556-
// draw the circle on the canvas
41557-
// var context = (canvas.getContext('2d'));
41558-
context.save();
41559-
// reset transform
41560-
context.setTransform(pixelratio, 0, 0, pixelratio, 0, 0);
41561-
context.clearRect(0, 0, canvas.width, canvas.height);
41562-
context.lineJoin = 'round';
41563-
var sum = 0;
41564-
var i, c;
41565-
for (i = 0; i < this._data.length; i++) {
41566-
sum += this._data[i];
41567-
}
41568-
// then move to (x, y)
41569-
context.translate(0, 0);
41570-
var step = this._animation.animate ? this._animation.step : 1;
41571-
//console.log(this._animation.step)
41572-
// Draw pie
41573-
switch (this._type) {
41574-
case "donut":
41575-
case "pie3D":
41576-
case "pie": {
41577-
var a, a0 = Math.PI * (step - 1.5);
41578-
c = canvas.width / 2 / pixelratio;
41579-
context.strokeStyle = strokeStyle;
41580-
context.lineWidth = strokeWidth;
41581-
context.save();
41582-
if (this._type == "pie3D") {
41583-
context.translate(0, c * 0.3);
41584-
context.scale(1, 0.7);
41585-
context.beginPath();
41586-
context.fillStyle = "#369";
41587-
context.arc(c, c * 1.4, this._radius * step, 0, 2 * Math.PI);
41588-
context.fill();
41589-
context.stroke();
41590-
}
41591-
if (this._type == "donut") {
41592-
context.save();
41593-
context.beginPath();
41594-
context.rect(0, 0, 2 * c, 2 * c);
41595-
context.arc(c, c, this._radius * step * this._donutratio, 0, 2 * Math.PI);
41596-
context.clip("evenodd");
41597-
}
41598-
for (i = 0; i < this._data.length; i++) {
41599-
context.beginPath();
41600-
context.moveTo(c, c);
41601-
context.fillStyle = this._colors[i % this._colors.length];
41602-
a = a0 + 2 * Math.PI * this._data[i] / sum * step;
41603-
context.arc(c, c, this._radius * step, a0, a);
41604-
context.closePath();
41605-
context.fill();
41606-
context.stroke();
41607-
a0 = a;
41608-
}
41609-
if (this._type == "donut") {
41610-
context.restore();
41611-
context.beginPath();
41612-
context.strokeStyle = strokeStyle;
41613-
context.lineWidth = strokeWidth;
41614-
context.arc(c, c, this._radius * step * this._donutratio, Math.PI * (step - 1.5), a0);
41615-
context.stroke();
41616-
}
41617-
context.restore();
41618-
break;
41619-
}
41620-
case "bar":
41621-
default: {
41622-
var max = 0;
41623-
if (this._max) {
41624-
max = this._max;
41625-
} else {
41626-
for (i = 0; i < this._data.length; i++) {
41627-
if (max < this._data[i])
41628-
max = this._data[i];
41629-
}
41630-
}
41631-
var s = Math.min(5, 2 * this._radius / this._data.length);
41632-
c = canvas.width / 2 / pixelratio;
41633-
var b = canvas.width / pixelratio - strokeWidth;
41634-
var x, x0 = c - this._data.length * s / 2;
41635-
context.strokeStyle = strokeStyle;
41636-
context.lineWidth = strokeWidth;
41637-
for (i = 0; i < this._data.length; i++) {
41638-
context.beginPath();
41639-
context.fillStyle = this._colors[i % this._colors.length];
41640-
x = x0 + s;
41641-
var h = this._data[i] / max * 2 * this._radius * step;
41642-
context.rect(x0, b - h, s, h);
41643-
//console.log ( x0+", "+(b-this._data[i]/max*2*this._radius)+", "+x+", "+b);
41644-
context.closePath();
41645-
context.fill();
41646-
context.stroke();
41647-
x0 = x;
41648-
}
41649-
}
41650-
}
41651-
context.restore();
41652-
// Set Anchor
41653-
if (!this.setDisplacement) {
41654-
var anchor = this.getAnchor();
41655-
anchor[0] = c - this._offset[0];
41656-
anchor[1] = c - this._offset[1];
41657-
}
41658-
// return image
41659-
return canvas;
41660-
}
41661-
};
41662-
/** Default color set: classic, dark, pale, pastel, neon
41663-
*/
41664-
ol.style.Chart.colors = {
41665-
"classic": ["#ffa500","blue","red","green","cyan","magenta","yellow","#0f0"],
41666-
"dark": ["#960","#003","#900","#060","#099","#909","#990","#090"],
41667-
"pale": ["#fd0","#369","#f64","#3b7","#880","#b5d","#666"],
41668-
"pastel": ["#fb4","#79c","#f66","#7d7","#acc","#fdd","#ff9","#b9b"],
41669-
"neon": ["#ff0","#0ff","#0f0","#f0f","#f00","#00f"]
41670-
};
41671-
41672-
/* Copyright (c) 2015 Jean-Marc VIGLINO,
41673-
released under the CeCILL-B license (French BSD license)
41674-
(http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt).
41675-
*
41676-
* Add a chart style to display charts (pies or bars) on a map
41677-
*/
41678-
/**
41679-
* @classdesc
41680-
* Set chart style for vector features.
41681-
*
41682-
* @constructor
41683-
* @param {} options
41684-
* @param {String} options.type Chart type: pie,pie3D, donut or bar
41685-
* @param {number} options.radius Chart radius/size, default 20
41686-
* @param {number} options.rotation Rotation in radians (positive rotation clockwise). Default is 0.
41687-
* @param {string} [options.declutterMode] Declutter mode "declutter" | "obstacle" | "none" | undefined
41688-
* @param {bool} options.snapToPixel use integral numbers of pixels, default true
41689-
* @param {_ol_style_Stroke_} options.stroke stroke style
41690-
* @param {String|Array<ol.color>} options.colors predefined color set "classic","dark","pale","pastel","neon" / array of color string, default classic
41691-
* @param {Array<number>} options.displacement
41692-
* @param {number} options.offsetX X offset in px (deprecated, use displacement)
41693-
* @param {number} options.offsetY Y offset in px (deprecated, use displacement)
41694-
* @param {number} options.animation step in an animation sequence [0,1]
41695-
* @param {number} options.max maximum value for bar chart
41696-
* @see [Statistic charts example](../../examples/style/map.style.chart.html)
41697-
* @extends {ol.style.RegularShape}
41698-
* @implements {ol.structs.IHasChecksum}
41699-
* @api
41700-
*/
41701-
ol.style.Chart = class olstyleChart extends ol.style.RegularShape {
41702-
constructor(opt_options) {
41703-
var options = opt_options || {};
41704-
var strokeWidth = 0;
41705-
if (opt_options.stroke)
41706-
strokeWidth = opt_options.stroke.getWidth();
41707-
super({
41708-
radius: options.radius + strokeWidth,
41709-
fill: new ol.style.Fill({ color: [0, 0, 0] }),
41710-
rotation: options.rotation,
41711-
displacement: options.displacement,
41712-
snapToPixel: options.snapToPixel,
41713-
declutterMode: options.declutterMode,
41714-
});
41715-
this.setScale(options.scale || 1);
41716-
this._stroke = options.stroke;
41717-
this._radius = options.radius || 20;
41718-
this._donutratio = options.donutRatio || 0.5;
41719-
this._type = options.type;
41720-
this._offset = [options.offsetX ? options.offsetX : 0, options.offsetY ? options.offsetY : 0];
41721-
this._animation = (typeof (options.animation) == 'number') ? { animate: true, step: options.animation } : this._animation = { animate: false, step: 1 };
41722-
this._max = options.max;
41723-
// Not yet drawn
41724-
this._done = false
41725-
this._data = options.data;
41726-
if (options.colors instanceof Array) {
41727-
this._colors = options.colors;
41728-
} else {
41729-
this._colors = ol.style.Chart.colors[options.colors];
41730-
if (!this._colors)
41731-
this._colors = ol.style.Chart.colors.classic;
41732-
}
41733-
this.render()
41734-
}
41735-
/**
41736-
* Clones the style.
41737-
* @return {ol.style.Chart}
41738-
*/
41739-
clone() {
41740-
var s = new ol.style.Chart({
41741-
type: this._type,
41742-
radius: this._radius,
41743-
rotation: this.getRotation(),
41744-
scale: this.getScale(),
41745-
data: this.getData(),
41746-
snapToPixel: this.getSnapToPixel ? this.getSnapToPixel() : false,
41747-
stroke: this._stroke,
41748-
colors: this._colors,
41749-
offsetX: this._offset[0],
41750-
offsetY: this._offset[1],
41751-
animation: this._animation,
41752-
declutterMode: this.getDeclutterMode ? this.getDeclutterMode() : null,
41753-
});
41754-
s.setScale(this.getScale());
41755-
s.setOpacity(this.getOpacity());
41756-
return s;
41757-
}
41758-
/** Get data associatied with the chart
41759-
*/
41760-
getData() {
41761-
return this._data;
41762-
}
41763-
/** Set data associatied with the chart
41764-
* @param {Array<number>}
41765-
*/
41766-
setData(data) {
41767-
this._data = data;
41768-
this._done = false
41769-
}
41770-
/** Get symbol radius
41771-
*/
41772-
getRadius() {
41773-
return this._radius;
41774-
}
41775-
/** Set symbol radius
41776-
* @param {number} symbol radius
41777-
* @param {number} donut ratio
41778-
*/
41779-
setRadius(radius, ratio) {
41780-
this._radius = radius;
41781-
this.donuratio_ = ratio || this.donuratio_;
41782-
this._done = false
41783-
}
41784-
/** Set animation step
41785-
* @param {false|number} false to stop animation or the step of the animation [0,1]
41786-
*/
41787-
setAnimation(step) {
41788-
if (step === false) {
41789-
if (this._animation.animate == false)
41790-
return;
41791-
this._animation.animate = false;
41792-
} else {
41793-
if (this._animation.step == step)
41794-
return;
41795-
this._animation.animate = true;
41796-
this._animation.step = step;
41797-
}
41798-
this._done = false
41799-
}
41800-
/**
41801-
* @return {RenderOptions} The render options
41802-
*/
41803-
createRenderOptions() {
41804-
var opt = super.createRenderOptions();
41805-
opt.chartOptions = [
41806-
'chart',
41807-
Object.values(this._animation||{}).join(','),
41808-
this._type,
41809-
(this._data || []).join(','),
41810-
(this._colors || []).join(','),
41811-
this._donutratio,
41812-
this._max,
41813-
].join('-')
41814-
return opt;
41815-
}
4181641532
/** @private
4181741533
*/
4181841534
getImage(pixelratio) {

dist/ol-ext.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ol-ext",
3-
"version": "4.0.26",
3+
"version": "4.0.27",
44
"description": "A set of cool extensions for OpenLayers (ol) in node modules structure",
55
"main": "dist/ol-ext.js",
66
"style": "dist/ol-ext.css",

0 commit comments

Comments
 (0)