[#141,view/map][s]: support for location objects with form {lon: ..., lat: ...}.
This commit is contained in:
parent
86fbe6d191
commit
170f10268c
@ -347,13 +347,19 @@ my.Map = Backbone.View.extend({
|
||||
if (typeof(value) === 'string'){
|
||||
// We *may* have a GeoJSON string representation
|
||||
try {
|
||||
return $.parseJSON(value);
|
||||
value = $.parseJSON(value);
|
||||
} catch(e) {
|
||||
}
|
||||
} else {
|
||||
// We assume that the contents of the field are a valid GeoJSON object
|
||||
return value;
|
||||
}
|
||||
if (value && value.lat) {
|
||||
// not yet geojson so convert
|
||||
value = {
|
||||
"type": "Point",
|
||||
"coordinates": [value.lon || value.lng, value.lat]
|
||||
};
|
||||
}
|
||||
// We now assume that contents of the field are a valid GeoJSON object
|
||||
return value;
|
||||
} else if (this.state.get('lonField') && this.state.get('latField')){
|
||||
// We'll create a GeoJSON like point object from the two lat/lon fields
|
||||
var lon = doc.get(this.state.get('lonField'));
|
||||
|
||||
@ -90,6 +90,23 @@ test('GeoJSON geom field', function () {
|
||||
view.remove();
|
||||
});
|
||||
|
||||
test('geom field non-GeoJSON', function () {
|
||||
var data = [{
|
||||
location: { lon: 47, lat: 53},
|
||||
title: 'abc'
|
||||
}];
|
||||
var dataset = recline.Backend.Memory.createDataset(data);
|
||||
var view = new recline.View.Map({
|
||||
model: dataset
|
||||
});
|
||||
|
||||
//Fire query, otherwise the map won't be initialized
|
||||
dataset.query();
|
||||
|
||||
// Check that all features were created
|
||||
equal(_getFeaturesCount(view.features), 1);
|
||||
});
|
||||
|
||||
test('Popup', function () {
|
||||
var dataset = GeoJSONFixture.getDataset();
|
||||
var view = new recline.View.Map({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user