[#141,view/map][s]: support for location objects with form {lon: ..., lat: ...}.
This commit is contained in:
@@ -347,13 +347,19 @@ my.Map = Backbone.View.extend({
|
|||||||
if (typeof(value) === 'string'){
|
if (typeof(value) === 'string'){
|
||||||
// We *may* have a GeoJSON string representation
|
// We *may* have a GeoJSON string representation
|
||||||
try {
|
try {
|
||||||
return $.parseJSON(value);
|
value = $.parseJSON(value);
|
||||||
} catch(e) {
|
} 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')){
|
} else if (this.state.get('lonField') && this.state.get('latField')){
|
||||||
// We'll create a GeoJSON like point object from the two lat/lon fields
|
// We'll create a GeoJSON like point object from the two lat/lon fields
|
||||||
var lon = doc.get(this.state.get('lonField'));
|
var lon = doc.get(this.state.get('lonField'));
|
||||||
|
|||||||
@@ -90,6 +90,23 @@ test('GeoJSON geom field', function () {
|
|||||||
view.remove();
|
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 () {
|
test('Popup', function () {
|
||||||
var dataset = GeoJSONFixture.getDataset();
|
var dataset = GeoJSONFixture.getDataset();
|
||||||
var view = new recline.View.Map({
|
var view = new recline.View.Map({
|
||||||
|
|||||||
Reference in New Issue
Block a user