improving listmap

This commit is contained in:
rolux 2011-05-22 14:39:57 +02:00
parent c86c7d598d
commit 5915acd72c
12 changed files with 152 additions and 39 deletions

View file

@ -9,7 +9,7 @@ Ox.load('Geo', function() {
var listmap = new Ox.ListMap({ var listmap = new Ox.ListMap({
height: window.innerHeight, height: window.innerHeight,
places: data.map(function(city) { places: data.map(function(city, id) {
var countryCode = city.country_code == 'XK' ? 'RS-KO' : city.country_code, var countryCode = city.country_code == 'XK' ? 'RS-KO' : city.country_code,
marker = city.population > 20000000 ? {size: 24, color: [255, 0, 0]} : marker = city.population > 20000000 ? {size: 24, color: [255, 0, 0]} :
city.population > 10000000 ? {size: 22, color: [255, 32, 0]} : city.population > 10000000 ? {size: 22, color: [255, 32, 0]} :
@ -28,6 +28,7 @@ Ox.load('Geo', function() {
editable: true, editable: true,
flag: countryCode, flag: countryCode,
geoname: city.name + ', ' + Ox.getCountryByCode(countryCode).name, geoname: city.name + ', ' + Ox.getCountryByCode(countryCode).name,
id: id,
markerColor: marker.color, markerColor: marker.color,
markerSize: marker.size, markerSize: marker.size,
name: city.name, name: city.name,

View file

@ -266,8 +266,8 @@ Document
-webkit-user-select: text; -webkit-user-select: text;
} }
.OxDocument div { .OxDocument div {
border-style: solid;
border-width: 0; border-width: 0;
border-style: solid;
//font-size: 12px; //font-size: 12px;
line-height: 15px; line-height: 15px;
-moz-user-select: text; -moz-user-select: text;
@ -421,6 +421,8 @@ OxButton
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
*/ */
.OxButton { .OxButton {
border-width: 1px;
border-style: solid;
text-align: center; text-align: center;
} }
.OxButton.OxSymbol, .OxButton.OxSymbol,
@ -534,6 +536,8 @@ div.OxCheckbox {
-webkit-border-radius: 8px; -webkit-border-radius: 8px;
} }
input.OxCheckbox { input.OxCheckbox {
border-width: 1px;
border-style: solid;
-moz-border-radius: 8px; -moz-border-radius: 8px;
-webkit-border-radius: 8px; -webkit-border-radius: 8px;
} }
@ -553,6 +557,7 @@ input.OxCheckbox {
OxInput OxInput
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
*/ */
div.OxInput { div.OxInput {
height: 16px; height: 16px;
} }
@ -573,6 +578,8 @@ div.OxInput > .OxInputLabel {
cursor: default; cursor: default;
} }
input.OxInput { input.OxInput {
border-width: 1px;
border-style: solid;
float: left; float: left;
} }
/* /*
@ -593,7 +600,8 @@ OxLabel
*/ */
.OxLabel { .OxLabel {
height: 14px; height: 14px;
border: 1px; border-width: 1px;
border-style: solid;
padding: 0 6px 0 6px; padding: 0 6px 0 6px;
text-overflow: ellipsis; text-overflow: ellipsis;
cursor: default; cursor: default;
@ -648,6 +656,8 @@ OxRange
} }
.OxRange > .OxTrack { .OxRange > .OxTrack {
float: right; float: right;
border-width: 1px;
border-style: solid;
height: 14px; height: 14px;
-moz-border-radius: 8px; -moz-border-radius: 8px;
-webkit-border-radius: 8px; -webkit-border-radius: 8px;
@ -693,8 +703,10 @@ OxRange
OxSelect OxSelect
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
*/ */
.OxSelect.OxMedium { .OxSelect {
height: 14px; height: 14px;
border-width: 1px;
border-style: solid;
-moz-border-radius: 8px; -moz-border-radius: 8px;
-webkit-border-radius: 8px; -webkit-border-radius: 8px;
} }
@ -706,6 +718,7 @@ OxSelect
float: left; float: left;
height: 14px; height: 14px;
padding-left: 6px; padding-left: 6px;
border-width: 1px;
text-align: left; text-align: left;
text-overflow: ellipsis; text-overflow: ellipsis;
cursor: default; cursor: default;
@ -997,6 +1010,7 @@ Lists
width: 11px; width: 11px;
height: 16px; height: 16px;
border-width: 0 1px 0 0; border-width: 0 1px 0 0;
border-style: solid;
background: rgba(0, 0, 0, 0); background: rgba(0, 0, 0, 0);
font-size: 11px; font-size: 11px;
text-align: center; text-align: center;
@ -1092,15 +1106,19 @@ Maps
border-radius: 0; border-radius: 0;
} }
.OxMapButton { input[type=image].OxMapButton {
position: absolute; position: absolute;
width: 12px; width: 10px;
height: 12px; height: 10px;
border: 2px solid rgb(255, 255, 255); padding: 1px;
background: rgba(0, 0, 0, 0.5); border-width: 2px;
} }
.OxMapLabel { .OxMapLabel {
position: absolute; position: absolute;
height: 12px;
padding: 0 5px 0 5px;
font-size: 10px;
border-width: 2px;
} }
/* /*

View file

@ -131,7 +131,12 @@ Ox.ArrayInput = function(options, self) {
} }
self.setOption = function(key, value) { self.setOption = function(key, value) {
if (key == 'width') { if (key == 'value') {
return Ox.map(self.$input, function($input) {
var value = $input.value();
return value === '' ? null : value;
});
} else if (key == 'width') {
setWidths(); setWidths();
} }
} }

View file

@ -65,7 +65,7 @@ Ox.Form = function(options, self) {
}); });
}); });
function getItemPositionById(id) { function getItemIndexById(id) {
return self.itemIds.indexOf(id); return self.itemIds.indexOf(id);
} }
@ -121,8 +121,10 @@ Ox.Form = function(options, self) {
//Ox.print('VALUES', values) //Ox.print('VALUES', values)
return values; return values;
} else { } else {
Ox.each(arguments[0], function(val, key) { Ox.forEach(arguments[0], function(value, key) {
var index = getItemIndexById(key);
index > -1 && Ox.print(key, value)
index > -1 && self.options.items[index].options({value: value});
}); });
return that; return that;
} }

View file

@ -789,8 +789,10 @@ Ox.Input = function(options, self) {
} else if (key == 'placeholder') { } else if (key == 'placeholder') {
setPlaceholder(); setPlaceholder();
} else if (key == 'value') { } else if (key == 'value') {
val = self.$input.val(); // fixme: ?? if (self.options.type == 'float' && self.options.decimals) {
self.$input.val(value); self.options.value = self.options.value.toFixed(self.options.decimals);
}
self.$input.val(self.options.value);
setPlaceholder(); setPlaceholder();
} else if (key == 'width') { } else if (key == 'width') {
that.css({width: self.options.width + 'px'}); that.css({width: self.options.width + 'px'});

View file

@ -26,7 +26,7 @@ Ox.Select = function(options, self) {
// fixme: selected item needs attribute "checked", not "selected" ... that's strange // fixme: selected item needs attribute "checked", not "selected" ... that's strange
var self = self || {}, var self = self || {},
that = new Ox.Element({ that = new Ox.Element({
tooltip: options.tooltip || {} tooltip: options.tooltip || ''
}, self) // fixme: do we use 'div', or {}, or '', by default? }, self) // fixme: do we use 'div', or {}, or '', by default?
.defaults({ .defaults({
id: '', id: '',

View file

@ -275,22 +275,32 @@ Ox.ListMap = function(options, self) {
values: [], values: [],
width: 240 width: 240
}), }),
], ['Latitude', 'Longitude', 'South', 'West', 'North', 'East'].map(function(v) { ], ['South', 'West', 'North', 'East', 'Latitude', 'Longitude'].map(function(v) {
var key = ( var id = (
v == 'Latitude' ? 'lat' : v == 'Longitude' ? 'lng' : v v == 'Latitude' ? 'lat' : v == 'Longitude' ? 'lng' : v
).toLowerCase(), ).toLowerCase(),
max = ['Latitude', 'South', 'North'].indexOf(v) > -1 ? Ox.MAX_LATITUDE : 180; max = ['Latitude', 'South', 'North'].indexOf(v) > -1 ? Ox.MAX_LATITUDE : 180;
return Ox.Input({ return Ox.Input({
decimals: 8, decimals: 8,
disabled: ['Latitude', 'Longitude'].indexOf(v) > -1,
id: id,
label: v, label: v,
labelWidth: 80, labelWidth: 80,
min: -max, min: -max,
max: max, max: max,
type: 'float', type: 'float',
value: self.options.places[0][key].toFixed(8),
width: 240 width: 240
}); });
})); }), [
Ox.Input({
disabled: true,
id: 'size',
label: 'Size',
labelWidth: 80,
textAlign: 'right',
width: 240
})
]);
self.$placeForm = Ox.Form({ self.$placeForm = Ox.Form({
items: self.$placeFormItems, items: self.$placeFormItems,
@ -348,7 +358,7 @@ Ox.ListMap = function(options, self) {
findPlaceholder: 'Find on Map', findPlaceholder: 'Find on Map',
height: self.options.height, height: self.options.height,
places: places, places: places,
//statusbar: true, statusbar: true,
toolbar: true, toolbar: true,
width: self.options.width - 514,//self.mapResize[1], width: self.options.width - 514,//self.mapResize[1],
zoombar: true zoombar: true
@ -357,6 +367,11 @@ Ox.ListMap = function(options, self) {
addplace: function(event, data) { addplace: function(event, data) {
that.triggerEvent('addplace', data); that.triggerEvent('addplace', data);
}, },
changeplace: function(event, data) {
self.$placeForm.values(Ox.map(data, function(val, key) {
return key == 'size' ? Ox.formatArea(val) : val;
}));
},
geocode: function(event, data) { geocode: function(event, data) {
that.triggerEvent('geocode', data); that.triggerEvent('geocode', data);
}, },
@ -409,7 +424,17 @@ Ox.ListMap = function(options, self) {
} }
], ],
orientation: 'vertical' orientation: 'vertical'
})
.bindEvent({
// fixme: pass width through form
resize: function(foo, size) {
self.$placeFormItems.forEach(function($item) {
$item.options({width: size - 16});
});
}
}), }),
resizable: true,
resize: [128, 256, 384],
size: 256 size: 256
} }
], ],
@ -445,6 +470,9 @@ Ox.ListMap = function(options, self) {
data.id && data.id[0] != '_' && self.$list.options({ data.id && data.id[0] != '_' && self.$list.options({
selected: data.id ? [data.id] : [] selected: data.id ? [data.id] : []
}); });
self.$placeForm.values(Ox.map(data, function(val, key) {
return key == 'size' ? Ox.formatArea(val) : val;
}));
} }
function toFixed(val) { function toFixed(val) {

View file

@ -15,7 +15,6 @@ Ox.Map <function> Basic map object
clickable <b|false> If true, clicking on the map finds a place clickable <b|false> If true, clicking on the map finds a place
editable <b|false> If true, places are editable editable <b|false> If true, places are editable
findPlaceholder <s|"Find"> Placeholder text for the find input element findPlaceholder <s|"Find"> Placeholder text for the find input element
labels <b|false> If true, show labels on the map
markers <n|100> Maximum number of markers to be displayed markers <n|100> Maximum number of markers to be displayed
places <[o]|[]> Array of place objects places <[o]|[]> Array of place objects
countryCode <s> ISO 3166 country code countryCode <s> ISO 3166 country code
@ -32,6 +31,8 @@ Ox.Map <function> Basic map object
type <s> Type (like "city" or "country") type <s> Type (like "city" or "country")
west <n> Longitude of the western boundary in degrees west <n> Longitude of the western boundary in degrees
selected <s|""> Id of the selected place selected <s|""> Id of the selected place
showControls <b|false> If true, show controls
showLabels <b|false> If true, show labels on the map
statusbar <b|false> If true, the map has a statusbar statusbar <b|false> If true, the map has a statusbar
toolbar <b|false> If true, the map has a toolbar toolbar <b|false> If true, the map has a toolbar
self <o|{}> Shared private variable self <o|{}> Shared private variable
@ -93,10 +94,11 @@ Ox.Map = function(options, self) {
clickable: false, clickable: false,
editable: false, editable: false,
findPlaceholder: 'Find', findPlaceholder: 'Find',
labels: false,
markers: 100, markers: 100,
places: [], places: [],
selected: null, selected: null,
showControls: false,
showLabels: false,
statusbar: false, statusbar: false,
toolbar: false, toolbar: false,
zoombar: false zoombar: false
@ -194,6 +196,21 @@ Ox.Map = function(options, self) {
size: 24 size: 24
}) })
.appendTo(that); .appendTo(that);
self.$select = Ox.Select({
items: [
{id: 'new Place', title: 'New Place...', keyboard: 'n'},
{},
{id: 'toggleLabels', title: 'Show Labels', keyboard: 'l', checked: self.options.showLabels},
{id: 'toggleControls', title: 'Show Controls', keyboard: 'c', checked: self.options.showControls},
],
min: 0,
max: 2,
title: 'Options...',
width: 96
})
.css({float: 'left', margin: '4px'})
.appendTo(self.$toolbar);
/*
self.$labelsButton = new Ox.Checkbox({ self.$labelsButton = new Ox.Checkbox({
title: 'Labels', title: 'Labels',
width: 64 width: 64
@ -203,6 +220,7 @@ Ox.Map = function(options, self) {
change: toggleLabels change: toggleLabels
}) })
.appendTo(self.$toolbar) .appendTo(self.$toolbar)
*/
self.$findInput = new Ox.Input({ self.$findInput = new Ox.Input({
clear: true, clear: true,
placeholder: self.options.findPlaceholder, placeholder: self.options.findPlaceholder,
@ -314,16 +332,18 @@ Ox.Map = function(options, self) {
top: '24px', top: '24px',
}) })
}; };
Ox.forEach(self.$navigationButtons, function($button) {
$button.attr({
src: $button.attr('src').replace('/classic/', '/modern/')
});
});
self.$scaleLabel = new Ox.Label({ self.$scaleLabel = new Ox.Label({
textAlign: 'center', textAlign: 'center',
title: '...' title: '...'
}) })
.addClass('OxMapLabel') .addClass('OxMapLabel')
.css({ .css({right: '4px', top: '4px'});
right: '4px',
top: '4px'
});
if (!window.googleCallback) { if (!window.googleCallback) {
window.googleCallback = function() { window.googleCallback = function() {
@ -490,7 +510,7 @@ Ox.Map = function(options, self) {
} }
function getMapType() { function getMapType() {
return self.options.labels ? 'HYBRID' : 'SATELLITE' return self.options.showLabels ? 'HYBRID' : 'SATELLITE'
} }
function getMaxZoom(point, callback) { function getMaxZoom(point, callback) {
@ -892,7 +912,7 @@ Ox.Map = function(options, self) {
} }
function toggleLabels() { function toggleLabels() {
self.options.labels = !self.options.labels self.options.showLabels = !self.options.showLabels
Ox.print('toggle', getMapType()) Ox.print('toggle', getMapType())
self.map.setMapTypeId(google.maps.MapTypeId[getMapType()]); self.map.setMapTypeId(google.maps.MapTypeId[getMapType()]);
/* /*

View file

@ -186,6 +186,7 @@ Ox.MapPlace = function(options) {
@*/ @*/
that.update = function() { that.update = function() {
update(); update();
that.map.triggerEvent('changeplace', that);
return that; return that;
}; };

View file

@ -86,12 +86,12 @@ Forms
.OxThemeClassic textarea, .OxThemeClassic textarea,
.OxThemeClassic .OxLabel, .OxThemeClassic .OxLabel,
.OxThemeClassic .OxTrack { .OxThemeClassic .OxTrack {
border: 1px solid rgb(176, 176, 176); border-color: rgb(176, 176, 176);
//border: 1px solid rgb(160, 160, 160); //border: 1px solid rgb(160, 160, 160);
color: rgb(64, 64, 64); color: rgb(64, 64, 64);
} }
.OxThemeClassic .OxSelect { .OxThemeClassic .OxSelect {
border: 1px solid rgb(176, 176, 176); border-color: rgb(176, 176, 176);
} }
.OxThemeClassic .OxSelect > .OxTitle { .OxThemeClassic .OxSelect > .OxTitle {
color: rgb(64, 64, 64); color: rgb(64, 64, 64);
@ -290,6 +290,23 @@ Lists
background: rgb(232, 232, 232); background: rgb(232, 232, 232);
} }
/*
================================================================================
Maps
================================================================================
*/
.OxThemeClassic .OxMapButton {
border-color: rgb(255, 255, 255);
background: rgba(0, 0, 0, 0.5);
}
.OxThemeClassic .OxMapLabel {
border-color: rgb(255, 255, 255);
background: rgba(0, 0, 0, 0.5);
color: rgb(255, 255, 255);
}
/* /*
================================================================================ ================================================================================
Menus Menus

View file

@ -117,11 +117,11 @@ Forms
.OxThemeModern .OxLabel, .OxThemeModern .OxLabel,
.OxThemeModern .OxTrack { .OxThemeModern .OxTrack {
//border: 1px solid rgb(80, 80, 80); //border: 1px solid rgb(80, 80, 80);
border: 1px solid rgb(48, 48, 48); border-color: rgb(48, 48, 48);
color: rgb(192, 192, 192); color: rgb(192, 192, 192);
} }
.OxThemeModern .OxSelect { .OxThemeModern .OxSelect {
border: 1px solid rgb(48, 48, 48); border-color: rgb(48, 48, 48);
} }
.OxThemeModern .OxSelect > .OxTitle { .OxThemeModern .OxSelect > .OxTitle {
color: rgb(192, 192, 192); color: rgb(192, 192, 192);
@ -192,7 +192,7 @@ Forms
color: rgb(96, 96, 96) color: rgb(96, 96, 96)
} }
.OxThemeModern .OxLabel { .OxThemeModern .OxLabel {
border: 1px solid rgb(48, 48, 48); border-color: rgb(48, 48, 48);
background: rgb(80, 80, 80); background: rgb(80, 80, 80);
color: rgb(192, 192, 192); color: rgb(192, 192, 192);
} }
@ -297,6 +297,22 @@ Lists
} }
/*
================================================================================
Maps
================================================================================
*/
.OxThemeModern .OxMapButton {
border-color: rgb(255, 255, 255);
background: rgba(0, 0, 0, 0.5);
}
.OxThemeModern .OxMapLabel {
border-color: rgb(255, 255, 255);
background: rgba(0, 0, 0, 0.5);
color: rgb(255, 255, 255);
}
/* /*
================================================================================ ================================================================================
Menus Menus

View file

@ -2043,7 +2043,9 @@ Ox.formatArea <f> Formats a number of meters as square kilometers
@*/ @*/
Ox.formatArea = function(num, dec) { Ox.formatArea = function(num, dec) {
return Ox.formatNumber(Ox.round(num / 1000000, dec)) + ' km\u00B2'; var km = num >= 1000000;
return Ox.formatNumber((km ? num / 1000000 : num).toPrecision(8)) +
' ' + (km ? 'k' : '') + 'm\u00B2';
} }
/*@ /*@
@ -2271,14 +2273,15 @@ Ox.formatNumber <f> Formats a number with thousands separators
"123,456,789.000" "123,456,789.000"
> Ox.formatNumber(-2000000 / 3, 3) > Ox.formatNumber(-2000000 / 3, 3)
"-666,666.667" "-666,666.667"
> Ox.formatNumber(666666.666) > Ox.formatNumber(666666.666, 0)
"666,667" "666,667"
@*/ @*/
Ox.formatNumber = function(num, dec) { Ox.formatNumber = function(num, dec) {
// fixme: specify decimal and thousands separators // fixme: specify decimal and thousands separators
var str = Math.abs(num).toFixed(dec || 0), var arr = [],
spl = str.split('.'), abs = Math.abs(num),
arr = []; str = Ox.isUndefined(dec) ? abs.toString() : abs.toFixed(dec),
spl = str.split('.');
while (spl[0]) { while (spl[0]) {
arr.unshift(spl[0].substr(-3)); arr.unshift(spl[0].substr(-3));
spl[0] = spl[0].substr(0, spl[0].length - 3); spl[0] = spl[0].substr(0, spl[0].length - 3);