From a35edd8815b4e274a7a1be181c540fead3fe9379 Mon Sep 17 00:00:00 2001 From: Suz Date: Wed, 18 Dec 2013 17:59:39 -0800 Subject: [PATCH 1/3] added test data for Edmonton and Rio de Janerio in DMS format --- test/view.map.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/view.map.test.js b/test/view.map.test.js index e3af2581..57688f6d 100644 --- a/test/view.map.test.js +++ b/test/view.map.test.js @@ -113,7 +113,10 @@ test('_getGeometryFromRecord non-GeoJSON', function () { ["53.3,47.32", [47.32, 53.3]], ["53.3, 47.32", [47.32, 53.3]], ["(53.3,47.32)", [47.32, 53.3]], - [[53.3,47.32], [53.3, 47.32]] + [[53.3,47.32], [53.3, 47.32]], + ["53.3 N, 113.5 W", [53.3, -113.5]], + ["53° 18' N, 113° 30' W", [53.3, -113.5]] + ["22°54′30″S 43°11′47″W", [-22.983, -43.3139]] ]; var view = new recline.View.Map({ model: new recline.Model.Dataset({ @@ -219,7 +222,7 @@ test('geoJsonLayerOptions', function () { model: dataset }); $('.fixtures').append(view.el); - view.geoJsonLayerOptions.point + view.geoJsonLayerOptions.point view.geoJsonLayerOptions.pointToLayer = function(feature, latlng) { var marker = new L.CircleMarker(latlng, { radius: 8 } ); marker.bindPopup(feature.properties.popupContent); From 27627c45d942691b2906d1e6f17ae16463c74213 Mon Sep 17 00:00:00 2001 From: Suz Date: Fri, 20 Dec 2013 17:01:18 -0800 Subject: [PATCH 2/3] Corrected syntax of new mapping test cases --- test/view.map.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/view.map.test.js b/test/view.map.test.js index 57688f6d..d867410f 100644 --- a/test/view.map.test.js +++ b/test/view.map.test.js @@ -110,13 +110,14 @@ test('GeoJSON geom field', function () { test('_getGeometryFromRecord non-GeoJSON', function () { var test = [ [{ lon: 47, lat: 53}, [47,53]], + [{ lon: -47, lat: 53}, [-47,53]], ["53.3,47.32", [47.32, 53.3]], ["53.3, 47.32", [47.32, 53.3]], ["(53.3,47.32)", [47.32, 53.3]], [[53.3,47.32], [53.3, 47.32]], - ["53.3 N, 113.5 W", [53.3, -113.5]], - ["53° 18' N, 113° 30' W", [53.3, -113.5]] - ["22°54′30″S 43°11′47″W", [-22.983, -43.3139]] + ["53.3 N, 113.5 W", [-113.5, 53.3]], + ["53° 18' N, 113° 30' W", [-113.5, 53.3 ]], + ["22°45′90″S, 43°15′45″W", [-43.2625, -22.775]] ]; var view = new recline.View.Map({ model: new recline.Model.Dataset({ From b744c88eb04700d2f29014b0093a1c9fe108c291 Mon Sep 17 00:00:00 2001 From: Suz Date: Fri, 20 Dec 2013 17:27:10 -0800 Subject: [PATCH 3/3] fix issue 380 -- added function to parse DMS formatted map data (36d 56m 29s S) --- src/view.map.js | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/view.map.js b/src/view.map.js index b4014123..a7af1fcf 100644 --- a/src/view.map.js +++ b/src/view.map.js @@ -10,7 +10,7 @@ this.recline.View = this.recline.View || {}; // This view allows to plot gereferenced records on a map. The location // information can be provided in 2 ways: // -// 1. Via a single field. This field must be either a geo_point or +// 1. Via a single field. This field must be either a geo_point or // [GeoJSON](http://geojson.org) object // 2. Via two fields with latitude and longitude coordinates. // @@ -326,6 +326,32 @@ my.Map = Backbone.View.extend({ }, + // Private: convert DMS coordinates to decimal + // + // north and east are positive, south and west are negative + // + _parseCoordinateString: function(coord){ + if (typeof(coord) != 'string') { + return(parseFloat(coord)); + } + var dms = coord.split(/[^\.\d\w]+/); + console.log(dms); + var deg = 0; var m = 0; + var toDeg = [1, 60, 3600]; // conversion factors for Deg, min, sec + var i; + for (i = 0; i < dms.length; ++i) { + if (isNaN(parseFloat(dms[i]))) { + continue; + } + deg += parseFloat(dms[i]) / toDeg[m]; + m += 1; + } + if (coord.match(/[SW]/)) { + deg = -1*deg; + } + return(deg); + }, + // Private: Return a GeoJSON geomtry extracted from the record fields // _getGeometryFromRecord: function(doc){ @@ -337,12 +363,12 @@ my.Map = Backbone.View.extend({ value = $.parseJSON(value); } catch(e) {} } - if (typeof(value) === 'string') { value = value.replace('(', '').replace(')', ''); var parts = value.split(','); - var lat = parseFloat(parts[0]); - var lon = parseFloat(parts[1]); + var lat = this._parseCoordinateString(parts[0]); + var lon = this._parseCoordinateString(parts[1]); + if (!isNaN(lon) && !isNaN(parseFloat(lat))) { return { "type": "Point", @@ -370,6 +396,9 @@ my.Map = Backbone.View.extend({ // We'll create a GeoJSON like point object from the two lat/lon fields var lon = doc.get(this.state.get('lonField')); var lat = doc.get(this.state.get('latField')); + lon = this._parseCoordinateString(lon); + lat = this._parseCoordinateString(lat); + if (!isNaN(parseFloat(lon)) && !isNaN(parseFloat(lat))) { return { type: 'Point',