2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-16 08:24:46 +00:00
|
|
|
/*@
|
|
|
|
Ox.MapImage <f:Ox.Element> MapImage Object
|
2012-05-22 13:14:40 +00:00
|
|
|
([options[, self]]) -> <o> MapImage Object
|
2011-05-16 08:24:46 +00:00
|
|
|
options <o> Options object
|
2011-05-16 10:49:48 +00:00
|
|
|
height <n|360> image height (px)
|
2012-04-01 21:05:53 +00:00
|
|
|
place <o|null> Object with south, west, north and east properties
|
2011-05-16 10:49:48 +00:00
|
|
|
type <s|satellite> map type ('hybrid', 'roadmap', 'satellite', 'terrain')
|
|
|
|
width <n|640> image width (px)
|
|
|
|
self <o> shared private variable
|
2011-05-16 08:24:46 +00:00
|
|
|
@*/
|
|
|
|
|
2011-04-22 22:03:10 +00:00
|
|
|
Ox.MapImage = function(options, self) {
|
|
|
|
|
|
|
|
var self = self || {},
|
2011-06-19 17:48:32 +00:00
|
|
|
that = Ox.Element('<img>', self)
|
2011-04-22 22:03:10 +00:00
|
|
|
.defaults({
|
2012-04-01 21:05:53 +00:00
|
|
|
backgroundColor: [0, 0, 0, 0],
|
|
|
|
borderColor: [0, 0, 0, 0],
|
|
|
|
borderWidth: 0,
|
2012-04-03 22:36:45 +00:00
|
|
|
height: 640,
|
|
|
|
markers: [],
|
2012-04-01 21:05:53 +00:00
|
|
|
place: null,
|
2011-04-22 22:03:10 +00:00
|
|
|
type: 'satellite',
|
|
|
|
width: 640
|
|
|
|
})
|
|
|
|
.options(options || {})
|
|
|
|
|
2012-04-01 21:05:53 +00:00
|
|
|
self.src = document.location.protocol
|
|
|
|
+ '//maps.google.com/maps/api/staticmap?sensor=false' +
|
|
|
|
'&size=' + self.options.width + 'x' + self.options.height +
|
|
|
|
'&maptype=' + self.options.type;
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-04-01 21:05:53 +00:00
|
|
|
if (self.options.place) {
|
|
|
|
self.src += '&path=fillcolor:' + formatColor(self.options.backgroundColor)
|
|
|
|
+ '|color:0x' + formatColor(self.options.borderColor)
|
|
|
|
+ '|weight:' + self.options.borderWidth + '|'
|
|
|
|
+ [
|
|
|
|
['south', 'west'],
|
|
|
|
['north', 'west'],
|
|
|
|
['north', 'east'],
|
|
|
|
['south', 'east'],
|
|
|
|
['south', 'west']
|
|
|
|
].map(function(keys) {
|
|
|
|
return [
|
|
|
|
self.options.place[keys[0]],
|
|
|
|
self.options.place[keys[1]]
|
|
|
|
].join(',');
|
|
|
|
}).join('|');
|
2011-04-22 22:03:10 +00:00
|
|
|
} else {
|
|
|
|
self.src += '¢er=0,0&zoom=2'
|
|
|
|
}
|
2012-04-03 22:36:45 +00:00
|
|
|
if (self.options.markers.length) {
|
|
|
|
self.src += '&markers='
|
|
|
|
+ self.options.markers.map(function(marker) {
|
|
|
|
return [marker.lat, marker.lng].join(',')
|
|
|
|
}).join('|');
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
that.attr({
|
|
|
|
src: self.src
|
|
|
|
});
|
|
|
|
|
2012-04-01 21:05:53 +00:00
|
|
|
function formatColor(color) {
|
|
|
|
return color.map(function(c) {
|
|
|
|
return Ox.pad(c.toString(16), 2);
|
|
|
|
}).join('')
|
|
|
|
}
|
|
|
|
|
2011-04-29 12:40:51 +00:00
|
|
|
self.setOption = function(key, value) {
|
2011-04-22 22:03:10 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
};
|