diff --git a/lib/index.js b/lib/index.js index 99c1573..d4a8aed 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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)); @@ -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); } diff --git a/lib/process-ml-data.js b/lib/process-ml-data.js new file mode 100644 index 0000000..6d632d7 --- /dev/null +++ b/lib/process-ml-data.js @@ -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; +} diff --git a/package.json b/package.json index 9263df0..97b2e5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "maplarge-google", - "version": "1.0.0-alpha.1", + "version": "1.0.0-alpha.2", "description": "", "main": "lib", "repository": {