[#141,view/map][s]: support for all of elasticsearch geo_point / location objects - fixes #141.
* [lon, lat] * "lat,lon" * Bonus (non-ES): "(lat,lon)" Also (accidentally included): * upgrade to qunit 1.5.0 (much better stack traces!)
This commit is contained in:
@@ -227,24 +227,42 @@ my.Map = Backbone.View.extend({
|
|||||||
// Private: Return a GeoJSON geomtry extracted from the record fields
|
// Private: Return a GeoJSON geomtry extracted from the record fields
|
||||||
//
|
//
|
||||||
_getGeometryFromRecord: function(doc){
|
_getGeometryFromRecord: function(doc){
|
||||||
if (this._geomReady()){
|
|
||||||
if (this.state.get('geomField')){
|
if (this.state.get('geomField')){
|
||||||
var value = doc.get(this.state.get('geomField'));
|
var value = doc.get(this.state.get('geomField'));
|
||||||
if (typeof(value) === 'string'){
|
if (typeof(value) === 'string'){
|
||||||
// We *may* have a GeoJSON string representation
|
// We *may* have a GeoJSON string representation
|
||||||
try {
|
try {
|
||||||
value = $.parseJSON(value);
|
value = $.parseJSON(value);
|
||||||
} catch(e) {
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof(value) === 'string') {
|
||||||
|
value = value.replace('(', '').replace(')', '');
|
||||||
|
var parts = value.split(',');
|
||||||
|
var lat = parseFloat(parts[0]);
|
||||||
|
var lon = parseFloat(parts[1]);
|
||||||
|
if (!isNaN(lon) && !isNaN(parseFloat(lat))) {
|
||||||
|
return {
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [lon, lat]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
if (value && value.lat) {
|
} else if (value && value.slice) {
|
||||||
// not yet geojson so convert
|
// [ lon, lat ]
|
||||||
value = {
|
return {
|
||||||
|
"type": "Point",
|
||||||
|
"coordinates": [value[0], value[1]]
|
||||||
|
};
|
||||||
|
} else if (value && value.lat) {
|
||||||
|
// of form { lat: ..., lon: ...}
|
||||||
|
return {
|
||||||
"type": "Point",
|
"type": "Point",
|
||||||
"coordinates": [value.lon || value.lng, value.lat]
|
"coordinates": [value.lon || value.lng, value.lat]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// We now assume that contents of the field are a valid GeoJSON object
|
// We o/w assume that contents of the field are a valid GeoJSON object
|
||||||
return value;
|
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
|
||||||
@@ -258,7 +276,6 @@ my.Map = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Private: Check if there is a field with GeoJSON geometries or alternatively,
|
// Private: Check if there is a field with GeoJSON geometries or alternatively,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* QUnit - A JavaScript Unit Testing Framework
|
* QUnit v1.6.0 - A JavaScript Unit Testing Framework
|
||||||
*
|
*
|
||||||
* http://docs.jquery.com/QUnit
|
* http://docs.jquery.com/QUnit
|
||||||
*
|
*
|
||||||
* Copyright (c) 2011 John Resig, Jörn Zaefferer
|
* Copyright (c) 2012 John Resig, Jörn Zaefferer
|
||||||
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
||||||
* or GPL (GPL-LICENSE.txt) licenses.
|
* or GPL (GPL-LICENSE.txt) licenses.
|
||||||
*/
|
*/
|
||||||
@@ -54,6 +54,11 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#qunit-header label {
|
||||||
|
display: inline-block;
|
||||||
|
padding-left: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
#qunit-banner {
|
#qunit-banner {
|
||||||
height: 5px;
|
height: 5px;
|
||||||
}
|
}
|
||||||
@@ -186,6 +191,7 @@
|
|||||||
color: #710909;
|
color: #710909;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-left: 26px solid #EE5757;
|
border-left: 26px solid #EE5757;
|
||||||
|
white-space: pre;
|
||||||
}
|
}
|
||||||
|
|
||||||
#qunit-tests > li:last-child {
|
#qunit-tests > li:last-child {
|
||||||
@@ -215,6 +221,9 @@
|
|||||||
|
|
||||||
border-bottom: 1px solid white;
|
border-bottom: 1px solid white;
|
||||||
}
|
}
|
||||||
|
#qunit-testresult .module-name {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
/** Fixture */
|
/** Fixture */
|
||||||
|
|
||||||
@@ -222,4 +231,6 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: -10000px;
|
top: -10000px;
|
||||||
left: -10000px;
|
left: -10000px;
|
||||||
|
width: 1000px;
|
||||||
|
height: 1000px;
|
||||||
}
|
}
|
||||||
|
|||||||
1089
test/qunit/qunit.js
1089
test/qunit/qunit.js
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,7 @@ test('initialize', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('dates in graph view', function () {
|
test('dates in graph view', function () {
|
||||||
|
expect(0);
|
||||||
var dataset = Fixture.getDataset();
|
var dataset = Fixture.getDataset();
|
||||||
var view = new recline.View.Graph({
|
var view = new recline.View.Graph({
|
||||||
model: dataset,
|
model: dataset,
|
||||||
|
|||||||
@@ -105,21 +105,25 @@ test('GeoJSON geom field', function () {
|
|||||||
view.remove();
|
view.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('geom field non-GeoJSON', function () {
|
test('_getGeometryFromRecord non-GeoJSON', function () {
|
||||||
var data = [{
|
var test = [
|
||||||
location: { lon: 47, lat: 53},
|
[{ lon: 47, lat: 53}, [47,53]],
|
||||||
title: 'abc'
|
["53.3,47.32", [47.32, 53.3]],
|
||||||
}];
|
["53.3, 47.32", [47.32, 53.3]],
|
||||||
var dataset = recline.Backend.Memory.createDataset(data);
|
["(53.3,47.32)", [47.32, 53.3]],
|
||||||
|
[[53.3,47.32], [53.3, 47.32]]
|
||||||
|
];
|
||||||
var view = new recline.View.Map({
|
var view = new recline.View.Map({
|
||||||
model: dataset
|
model: recline.Backend.Memory.createDataset([{a: 1}]),
|
||||||
|
state: {
|
||||||
|
geomField: 'location'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_.each(test, function(item) {
|
||||||
|
var record = new recline.Model.Record({location: item[0]});
|
||||||
|
var out = view._getGeometryFromRecord(record);
|
||||||
|
deepEqual(out.coordinates, item[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
//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 () {
|
||||||
|
|||||||
Reference in New Issue
Block a user