Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Commit

Permalink
Fix marker placement bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ejb committed Jul 17, 2015
1 parent 391b0b7 commit 0c57fe1
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ Tests are carried out with [QUnit](http://qunitjs.com). To run tests, either ope

## Changelog

v1.1.1 (July 17, 2015)

- Fixed marker position bug

v1.1.0 (July 17, 2015)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pinpoint",
"version": "1.1.0",
"version": "1.1.1",
"authors": [
"ejb <[email protected]>"
],
Expand Down
12 changes: 7 additions & 5 deletions dist/pinpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ Pinpoint.prototype.addMarker = function(mopts, index){
// L.marker([50.505, 30.57]).addTo(map);

var miList = this.element.querySelectorAll('.marker-inner');
mi = miList[miList.length-1];
mi.style.marginLeft = -mi.outerWidth/2;
setTimeout((function(){
mi.style.marginLeft = -mi.outerWidth/2;
}).bind(this),100);
for (var i = 0; i < miList.length; i++) {
var mi = miList[i];
mi.style.marginLeft = (-mi.offsetWidth/2)+'px';
setTimeout((function(){
mi.style.marginLeft = (-mi.offsetWidth/2)+'px';
}).bind(this),100);
}

if (this.opts.markerdragend) {
icon.on('dragend', this.opts.markerdragend);
Expand Down
2 changes: 1 addition & 1 deletion dist/pinpoint.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/js/pinpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,13 @@ Pinpoint.prototype.addMarker = function(mopts, index){
// L.marker([50.505, 30.57]).addTo(map);

var miList = this.element.querySelectorAll('.marker-inner');
mi = miList[miList.length-1];
mi.style.marginLeft = -mi.outerWidth/2;
setTimeout((function(){
mi.style.marginLeft = -mi.outerWidth/2;
}).bind(this),100);
for (var i = 0; i < miList.length; i++) {
var mi = miList[i];
mi.style.marginLeft = (-mi.offsetWidth/2)+'px';
setTimeout((function(){
mi.style.marginLeft = (-mi.offsetWidth/2)+'px';
}).bind(this),100);
}

if (this.opts.markerdragend) {
icon.on('dragend', this.opts.markerdragend);
Expand Down
28 changes: 28 additions & 0 deletions test/pinpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,31 @@ QUnit.test( "Dynamic height", function( assert ) {
},200);
});

QUnit.test( "Marker placement", function( assert ) {
var data = {
"lat": 51.5049378,
"lon": - 0.0870377,
"zoom": 4,
"aspect-ratio": "tall",
"hed": "Hi",
"dek": "You",
"markers": [{
"lat": 51.5049378,
"lon": - 0.0870377,
"label": ""
}]
};
data.el = '.test-map';

var p = new Pinpoint(data);
assert.ok( ($('.marker-inner').offset().left / $('.map-inner').width()) < 0.5 );
p.remove();

data.markers[0].label = 'callout';
var p = new Pinpoint(data);
assert.ok( ($('.marker-inner').offset().left / $('.map-inner').width()) < 0.5 );
p.remove();

});


0 comments on commit 0c57fe1

Please sign in to comment.