Skip to content

Commit

Permalink
parse click event data
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Jan 5, 2016
1 parent e7ca521 commit d52d5b5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Utfgrid from './utfgrid';
import SphericalMercator from 'sphericalmercator';
import replaceImg from './replace-img';
import sortLayers from './sort-layers';
import processMlData from './process-ml-data';
const merc = new SphericalMercator();
const CIRCUMFERENCE = 6371009;
const metersPerPixel = (lat, z) => Math.abs(CIRCUMFERENCE * Math.cos(lat / 180) / Math.pow(2, z + 4));
Expand Down Expand Up @@ -553,7 +554,12 @@ export default class Layer extends EE.EventEmitter {
if (!this.utfGrid) {
this.utfGrid = this.getGrid();
}
this.utfGrid.on('click', this.click);
this.utfGrid.on('click', data => {
this.click({
latLng: data.latLng,
data: processMlData(this.fields, data.data)
});
});
this.utfGrid.setMap(this.map);
}

Expand Down
16 changes: 16 additions & 0 deletions lib/process-ml-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function processMlData(fields, data) {
if (!data) {
return null;
}

var items = data[2].split('`~!');
var out = {};
var i = -1;
var len = fields.length;

while (++i < len) {
out[fields[i]] = items[i];
}

return out;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maplarge-google",
"version": "1.0.0-alpha.1",
"version": "1.0.0-alpha.2",
"description": "",
"main": "lib",
"repository": {
Expand Down

0 comments on commit d52d5b5

Please sign in to comment.