more useful version of Ox.MapImage
This commit is contained in:
parent
6a39bdd3bd
commit
fbc15dcadf
1 changed files with 31 additions and 33 deletions
|
@ -9,8 +9,7 @@ Ox.MapImage <f:Ox.Element> MapImage Object
|
||||||
(options, self) -> <f> MapImage Object
|
(options, self) -> <f> MapImage Object
|
||||||
options <o> Options object
|
options <o> Options object
|
||||||
height <n|360> image height (px)
|
height <n|360> image height (px)
|
||||||
places <a|o|[]> array of either names (''), points ([0, 0]),
|
place <o|null> Object with south, west, north and east properties
|
||||||
or objects ({name, point, highlight})
|
|
||||||
type <s|satellite> map type ('hybrid', 'roadmap', 'satellite', 'terrain')
|
type <s|satellite> map type ('hybrid', 'roadmap', 'satellite', 'terrain')
|
||||||
width <n|640> image width (px)
|
width <n|640> image width (px)
|
||||||
self <o> shared private variable
|
self <o> shared private variable
|
||||||
|
@ -21,44 +20,37 @@ Ox.MapImage = function(options, self) {
|
||||||
var self = self || {},
|
var self = self || {},
|
||||||
that = Ox.Element('<img>', self)
|
that = Ox.Element('<img>', self)
|
||||||
.defaults({
|
.defaults({
|
||||||
|
backgroundColor: [0, 0, 0, 0],
|
||||||
|
borderColor: [0, 0, 0, 0],
|
||||||
|
borderWidth: 0,
|
||||||
height: 360,
|
height: 360,
|
||||||
markerColorHighlight: 'yellow',
|
place: null,
|
||||||
markerColorNormal: 'blue',
|
|
||||||
places: [],
|
|
||||||
type: 'satellite',
|
type: 'satellite',
|
||||||
width: 640
|
width: 640
|
||||||
})
|
})
|
||||||
.options(options || {})
|
.options(options || {})
|
||||||
|
|
||||||
Ox.extend(self, {
|
self.src = document.location.protocol
|
||||||
markers: {
|
+ '//maps.google.com/maps/api/staticmap?sensor=false' +
|
||||||
highlight: [],
|
'&size=' + self.options.width + 'x' + self.options.height +
|
||||||
normal: []
|
'&maptype=' + self.options.type;
|
||||||
},
|
|
||||||
src: document.location.protocol + '//maps.google.com/maps/api/staticmap?sensor=false' +
|
|
||||||
'&size=' + self.options.width + 'x' + self.options.height +
|
|
||||||
'&maptype=' + self.options.type
|
|
||||||
});
|
|
||||||
|
|
||||||
if (self.options.places.length) {
|
if (self.options.place) {
|
||||||
self.options.places.forEach(function(place) {
|
self.src += '&path=fillcolor:' + formatColor(self.options.backgroundColor)
|
||||||
if (Ox.isString(place)) {
|
+ '|color:0x' + formatColor(self.options.borderColor)
|
||||||
self.markers.normal.push(place);
|
+ '|weight:' + self.options.borderWidth + '|'
|
||||||
} else if (Ox.isArray(place)) {
|
+ [
|
||||||
self.markers.normal.push(place.join(','));
|
['south', 'west'],
|
||||||
} else {
|
['north', 'west'],
|
||||||
self.markers[place.highlight ? 'highlight' : 'normal']
|
['north', 'east'],
|
||||||
.push('point' in place ? place.point.join(',') : place.name)
|
['south', 'east'],
|
||||||
}
|
['south', 'west']
|
||||||
});
|
].map(function(keys) {
|
||||||
Ox.forEach(self.markers, function(markers, k) {
|
return [
|
||||||
if (markers.length) {
|
self.options.place[keys[0]],
|
||||||
self.src += '&markers=icon:' + 'http://dev.pan.do:8000' +
|
self.options.place[keys[1]]
|
||||||
Ox.UI.PATH + 'png/marker' +
|
].join(',');
|
||||||
Ox.toTitleCase(self.options['markerColor' + Ox.toTitleCase(k)]) +
|
}).join('|');
|
||||||
'.png|' + markers.join('|')
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
self.src += '¢er=0,0&zoom=2'
|
self.src += '¢er=0,0&zoom=2'
|
||||||
}
|
}
|
||||||
|
@ -67,6 +59,12 @@ Ox.MapImage = function(options, self) {
|
||||||
src: self.src
|
src: self.src
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function formatColor(color) {
|
||||||
|
return color.map(function(c) {
|
||||||
|
return Ox.pad(c.toString(16), 2);
|
||||||
|
}).join('')
|
||||||
|
}
|
||||||
|
|
||||||
self.setOption = function(key, value) {
|
self.setOption = function(key, value) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue