1
0
Fork 0
forked from 0x2620/oxjs

add place controls to map

This commit is contained in:
rlx 2011-10-30 21:05:32 +00:00
commit 3c8430979b
5 changed files with 117 additions and 31 deletions

View file

@ -331,7 +331,7 @@ Ox.Map = function(options, self) {
}
self.$controls = {
'center': Ox.Button({
center: Ox.Button({
title: 'center',
type: 'image'
})
@ -344,7 +344,7 @@ Ox.Map = function(options, self) {
zoomToPlace();
}
}),
'east': Ox.Button({
east: Ox.Button({
title: 'right',
type: 'image'
})
@ -357,7 +357,7 @@ Ox.Map = function(options, self) {
pan(2, 0);
}
}),
'north': Ox.Button({
north: Ox.Button({
title: 'up',
type: 'image'
})
@ -370,7 +370,7 @@ Ox.Map = function(options, self) {
pan(0, -2);
}
}),
'south': Ox.Button({
south: Ox.Button({
title: 'down',
type: 'image'
})
@ -383,7 +383,7 @@ Ox.Map = function(options, self) {
pan(0, 2);
}
}),
'west': Ox.Button({
west: Ox.Button({
title: 'left',
type: 'image'
})
@ -396,16 +396,45 @@ Ox.Map = function(options, self) {
pan(-2, 0);
}
}),
'scale': Ox.Label({
textAlign: 'center',
title: '...' // fixme ???
scale: Ox.Label({
textAlign: 'center'
})
.addClass('OxMapControl')
.addClass('OxMapControl OxMapScale')
};
!self.options.showControls && Ox.forEach(self.$controls, function($control) {
$control.css({opacity: 0}).hide();
});
self.$placeControls = {
flag: Ox.Element()
.addClass('OxPlaceControl OxPlaceFlag'),
name: Ox.Label({
textAlign: 'center'
})
.addClass('OxPlaceControl OxPlaceName')
.bindEvent({
singleclick: function() {
panToPlace();
},
doubleclick: function() {
zoomToPlace();
}
}),
deselectButton: Ox.Button({
title: 'close',
type: 'image',
})
.addClass('OxPlaceControl OxPlaceDeselectButton')
.bindEvent({
click: function() {
selectPlace(null);
}
})
}
Ox.forEach(self.$placeControls, function($placeControl) {
$placeControl.css({opacity: 0}).hide();
});
if (!self.isAsync) {
self.options.places.forEach(function(place) {
if (Ox.isUndefined(place.id)) {
@ -808,6 +837,9 @@ Ox.Map = function(options, self) {
// fixme: can add earlier, use don't replace map contents option
Ox.forEach(self.$controls, function($control) {
$control.appendTo(self.$map);
});
Ox.forEach(self.$placeControls, function($placeControl) {
$placeControl.appendTo(self.$map);
});
}
}
@ -1117,12 +1149,32 @@ Ox.Map = function(options, self) {
function select() {
place && place.select();
self.options.selected = id;
setPlaceControls(place);
setStatus();
that.triggerEvent('selectplace', place);
// FIXME: all these events should rather pass {place: place}
}
};
function setPlaceControls(place) {
var $placeControls = that.$element.find('.OxPlaceControl'),
isVisible = self.$placeControls.name.is(':visible');
if (place) {
self.$placeControls.flag.empty().append(
$('<img>')
.attr({
src: Ox.getImageByGeoname('icon', 16, place.geoname)
})
).show();
self.$placeControls.name.options({title: place.name})
!isVisible && $placeControls.show().animate({opacity: 1}, 250);
} else {
isVisible && $placeControls.animate({opacity: 0}, 250, function() {
$placeControls.hide();
});
}
}
function setScale() {
var metersPerPixel = getMetersPerPixel();
Ox.forEach(self.scaleMeters, function(meters) {