oxjs/source/UI/js/Map/MapImage.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

2011-11-05 16:46:53 +00:00
'use strict';
2011-05-16 08:24:46 +00:00
/*@
2012-05-31 10:32:54 +00:00
Ox.MapImage <f> 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
([options[, self]]) -> <o:Ox.Element> MapImage Object
2011-05-16 08:24:46 +00:00
@*/
2011-04-22 22:03:10 +00:00
Ox.MapImage = function(options, self) {
var self = self || {},
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
})
2012-05-28 19:35:41 +00:00
.options(options || {});
2011-04-22 22:03:10 +00:00
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 += '&center=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), 'left', 2, '0');
2012-04-01 21:05:53 +00:00
}).join('')
}
2011-04-22 22:03:10 +00:00
return that;
};