Skip to content

Commit

Permalink
Fix projection so the map is where the point is
Browse files Browse the repository at this point in the history
Also remove gj redundancy
  • Loading branch information
bhousel committed Jul 8, 2018
1 parent ef77121 commit de12396
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 95 deletions.
4 changes: 2 additions & 2 deletions modules/svg/gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ export function svgGpx(projection, context, dispatch) {

drawGpx.files = function(fileList) {
if (!fileList.length) return this;
var f = fileList[0],
reader = new FileReader();
var f = fileList[0];
var reader = new FileReader();

reader.onload = (function(file) {
_src = file.name;
Expand Down
2 changes: 1 addition & 1 deletion test/data/gpxtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"id": 316973311
}
]
};
}
140 changes: 48 additions & 92 deletions test/spec/svg/gpx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,41 @@ describe('iD.svgGpx', function () {
var context;
var surface;
var dispatch = d3.dispatch('change');
var projection = d3.geoProjection(function(x, y) { return [x, -y]; })
.translate([0, 0])
var projection = iD.geoRawMercator()
.translate([6934098.868981334, 4092682.5519805425])
.scale(iD.geoZoomToScale(17))
.clipExtent([[0, 0], [Infinity, Infinity]]);
.clipExtent([[0, 0], [1000, 1000]]);

var gj = {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'id': 316973311,
'geometry': {
'type': 'Point',
'coordinates': [
-74.38928604125977,
40.150275473401365
]
},
'properties': {
'abbr': 'N.J.',
'area': 19717.8,
'name': 'New Jersey',
'name_en': 'New Jersey',
'osm_id': 316973311
}
}
]
};

beforeEach(function () {
context = iD.coreContext();
d3.select(document.createElement('div'))
.attr('id', 'map')
.call(context.map().centerZoom([0, 0], 17));
.call(context.map().centerZoom([-74.389286, 40.1502754], 17));

surface = context.surface();
});

Expand All @@ -22,39 +47,15 @@ describe('iD.svgGpx', function () {

var layers = surface.selectAll('g.layer-gpx').nodes();
expect(layers.length).to.eql(1);
expect(d3.select(layers[0]).classed('layer-gpx')).to.be.true;
});

it('draws geojson', function () {
var gj = {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-74.38928604125977,
40.150275473401365
]
},
'properties': {
'abbr': 'N.J.',
'area': 19717.8,
'name': 'New Jersey',
'name_en': 'New Jersey',
'osm_id': 316973311
},
'id': 316973311
}
]
};
var render = iD.svgGpx(projection, context, dispatch).geojson(gj);
surface.call(render);

var elements = surface.selectAll('path.gpx').nodes();
expect(elements.length).to.eql(1);
expect(d3.select(elements[0]).classed('gpx')).to.be.true;
var path = surface.selectAll('path.gpx');
expect(path.nodes().length).to.eql(1);
expect(path.attr('d')).to.match(/^M.*z$/);
});

describe('#files', function() {
Expand All @@ -63,94 +64,49 @@ describe('iD.svgGpx', function () {
var render = iD.svgGpx(projection, context, dispatch).files(files);
surface.call(render);

var elements = surface.selectAll('path.gpx').nodes();
expect(elements.length).to.eql(1);
expect(d3.select(elements[0]).classed('gpx')).to.be.true;
var path = surface.selectAll('path.gpx');
expect(path.nodes().length).to.eql(1);
expect(path.attr('d')).to.match(/^M.*z$/);
});

it('handles geojson files', function () {
var files = '../../data/gpxtest.json';
var render = iD.svgGpx(projection, context, dispatch).files(files);
surface.call(render);

var elements = surface.selectAll('path.gpx').nodes();
expect(elements.length).to.eql(1);
expect(d3.select(elements[0]).classed('gpx')).to.be.true;
var path = surface.selectAll('path.gpx');
expect(path.nodes().length).to.eql(1);
expect(path.attr('d')).to.match(/^M.*z$/);
});

it('handles kml files', function () {
var files = '../../data/gpxtest.kml';
var render = iD.svgGpx(projection, context, dispatch).files(files);
surface.call(render);

var elements = surface.selectAll('path.gpx').nodes();
expect(elements.length).to.eql(1);
expect(d3.select(elements[0]).classed('gpx')).to.be.true;
var path = surface.selectAll('path.gpx');
expect(path.nodes().length).to.eql(1);
expect(path.attr('d')).to.match(/^M.*z$/);
});
});


describe('#showLabels', function() {
it('shows labels by default', function () {
var gj = {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-74.38928604125977,
40.150275473401365
]
},
'properties': {
'abbr': 'N.J.',
'area': 19717.8,
'name': 'New Jersey',
'name_en': 'New Jersey',
'osm_id': 316973311
},
'id': 316973311
}
]
};
var render = iD.svgGpx(projection, context, dispatch).geojson(gj);
surface.call(render);
var elements = surface.selectAll('text.gpxlabel').nodes();
//expect(elements.length).to.eql(1);
//expect(d3.select(elements[0]).classed('text.gpxlabel')).to.be.true;

var halo = surface.selectAll('text.gpxlabel-halo').nodes();
//expect(halo.length).to.eql(1);
//expect(d3.select(elements[0]).classed('text.gpxlabel-halo')).to.be.true;
var label = surface.selectAll('text.gpxlabel');
expect(label.nodes().length).to.eql(1);
expect(label.text()).to.eql('New Jersey');

var halo = surface.selectAll('text.gpxlabel-halo');
expect(halo.nodes().length).to.eql(1);
expect(halo.text()).to.eql('New Jersey');
});


it('hides labels with showLabels(false)', function () {
var gj = {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [
-74.38928604125977,
40.150275473401365
]
},
'properties': {
'abbr': 'N.J.',
'area': 19717.8,
'name': 'New Jersey',
'name_en': 'New Jersey',
'osm_id': 316973311
},
'id': 316973311
}
]
};
var render = iD.svgGpx(projection, context, dispatch).geojson(gj).showLabels(false);
surface.call(render);

Expand Down

0 comments on commit de12396

Please sign in to comment.