2011-07-29 18:48:43 +00:00
|
|
|
// vim: et:ts=4:sw=4:sts=4:ft=javascript
|
2011-04-27 19:24:33 +00:00
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
/*@
|
|
|
|
Ox.MapMarkerImage <f:google.maps.MarkerImage> MapMarkerImage Object
|
|
|
|
(options) -> <f> google.maps.MarkerImage
|
|
|
|
options <o> Options object
|
|
|
|
color <a|[255, 0, 0]> marker color
|
|
|
|
mode <s|normal> can be: normal, selected, editing
|
|
|
|
size <n|16> size
|
|
|
|
type <s|place> can be: place, result, rectangle
|
|
|
|
@*/
|
|
|
|
|
2011-04-27 19:24:33 +00:00
|
|
|
Ox.MapMarkerImage = (function() {
|
|
|
|
|
|
|
|
var cache = {};
|
|
|
|
|
|
|
|
return function(options) {
|
|
|
|
|
|
|
|
options = Ox.extend({
|
|
|
|
color: [255, 0, 0],
|
|
|
|
mode: 'normal', // normal, selected, editing
|
|
|
|
size: 16,
|
|
|
|
type: 'place', // place, result, rectangle
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
var index = [
|
|
|
|
options.type, options.mode, options.size, options.color.join(',')
|
|
|
|
].join(';');
|
|
|
|
|
|
|
|
if (!cache[index]) {
|
|
|
|
var color = options.type == 'place' ?
|
2011-05-22 13:14:42 +00:00
|
|
|
Ox.merge(Ox.clone(options.color), [0.5]) :
|
|
|
|
options.type == 'result' ? [128, 128, 128, 0.5] : [0, 0, 0, 0],
|
2011-04-27 19:24:33 +00:00
|
|
|
border = options.mode == 'normal' ? [0, 0, 0] :
|
|
|
|
options.mode == 'selected' ? [255, 255, 255] : [128, 128, 255],
|
|
|
|
c = Ox.canvas(options.size, options.size),
|
|
|
|
image,
|
|
|
|
r = options.size / 2;
|
|
|
|
c.context.fillStyle = 'rgba(' + color.join(', ') + ')';
|
|
|
|
c.context.arc(r, r, r - 2, 0, 360);
|
|
|
|
c.context.fill();
|
|
|
|
c.context.beginPath();
|
|
|
|
c.context.lineWidth = 2;
|
|
|
|
c.context.strokeStyle = 'rgb(' + border.join(', ') + ')';
|
|
|
|
c.context.arc(r, r, r - 1, 0, 360);
|
|
|
|
c.context.stroke();
|
|
|
|
cache[index] = new google.maps.MarkerImage(
|
|
|
|
c.canvas.toDataURL(),
|
|
|
|
new google.maps.Size(options.size, options.size),
|
|
|
|
new google.maps.Point(0, 0),
|
|
|
|
new google.maps.Point(r, r)
|
|
|
|
);
|
|
|
|
//Ox.print(options, 'index', index)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cache[index];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-05-16 10:49:48 +00:00
|
|
|
}());
|