Skip to content

Commit

Permalink
Reformat code using Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
simon04 committed May 11, 2017
1 parent b0a4db0 commit aba961e
Show file tree
Hide file tree
Showing 37 changed files with 6,088 additions and 4,421 deletions.
37 changes: 22 additions & 15 deletions data/get_preset_translations.js
@@ -1,22 +1,29 @@
/* Downloads preset translations from iD editor github repo */

var request = require('request'),
fs = require('fs');
var request = require("request"), fs = require("fs");

var api = 'https://github.com/openstreetmap/iD/raw/master/dist/locales/';
var outdir = './data/';
var localesdir = './locales/';
var api = "https://github.com/openstreetmap/iD/raw/master/dist/locales/";
var outdir = "./data/";
var localesdir = "./locales/";

var locales = fs.readdirSync(localesdir).filter(function(filename) { return filename.match(/\.json$/); });
var locales = fs.readdirSync(localesdir).filter(function(filename) {
return filename.match(/\.json$/);
});

locales.forEach(function(locale) {
locale = locale.replace('.json', '');
request(api + locale + '.json', function(err, resp, body) {
console.log(locale);
if (err) return;
try { var data = JSON.parse(body); } catch (e) { return; }
data = data.presets.presets;
fs.writeFileSync(outdir + 'iD_presets_' + locale + '.json', JSON.stringify(data, null, 2));
});
locale = locale.replace(".json", "");
request(api + locale + ".json", function(err, resp, body) {
console.log(locale);
if (err) return;
try {
var data = JSON.parse(body);
} catch (e) {
return;
}
data = data.presets.presets;
fs.writeFileSync(
outdir + "iD_presets_" + locale + ".json",
JSON.stringify(data, null, 2)
);
});
});

46 changes: 21 additions & 25 deletions js/GeoJsonNoVanish.js
@@ -1,11 +1,11 @@
import L from 'leaflet';
import L from "leaflet";

L.GeoJsonNoVanish = L.GeoJSON.extend({
initialize: function (geojson, options) {
initialize: function(geojson, options) {
this.options = {
threshold: 10
};
L.GeoJSON.prototype.initialize.call(this,geojson,options);
L.GeoJSON.prototype.initialize.call(this, geojson, options);
},
onAdd: function(map) {
this._map = map;
Expand All @@ -20,63 +20,59 @@ L.GeoJsonNoVanish = L.GeoJSON.extend({
this.eachLayer(map.removeLayer, map);
this._map = null;
},
_onZoomEnd: function() { // todo: name
_onZoomEnd: function() {
// todo: name
// todo: possible optimizations: zoomOut = skip already compressed objects (and vice versa)
var is_max_zoom = this._map.getZoom() == this._map.getMaxZoom();
this.eachLayer(function(o) {
if (!o.feature || !o.feature.geometry)
return; // skip invalid layers
if (o.feature.geometry.type == "Point" && !o.obj)
return; // skip node features
if (!o.feature || !o.feature.geometry) return; // skip invalid layers
if (o.feature.geometry.type == "Point" && !o.obj) return; // skip node features
var crs = this._map.options.crs;
if (o.obj) { // already compressed feature
if (o.obj) {
// already compressed feature
var bounds = o.obj.getBounds();
var p1 = crs.latLngToPoint(bounds.getSouthWest(), o._map.getZoom());
var p2 = crs.latLngToPoint(bounds.getNorthEast(), o._map.getZoom());
var d = Math.sqrt(Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2));
var d = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
if (d > this.options.threshold || is_max_zoom) {
delete o.obj.placeholder;
this.addLayer(o.obj);
this.removeLayer(o);
}
return;
}
if (is_max_zoom)
return; // do not compress objects at max zoom
if (this.options.compress &&
!this.options.compress(o.feature))
return;
if (is_max_zoom) return; // do not compress objects at max zoom
if (this.options.compress && !this.options.compress(o.feature)) return;
var bounds = o.getBounds();
var p1 = crs.latLngToPoint(bounds.getSouthWest(), o._map.getZoom());
var p2 = crs.latLngToPoint(bounds.getNorthEast(), o._map.getZoom());
var d = Math.sqrt(Math.pow(p1.x-p2.x,2)+Math.pow(p1.y-p2.y,2));
if (d > this.options.threshold)
return;
var d = Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
if (d > this.options.threshold) return;
/*var c = this.options.pointToLayer ?
this.options.pointToLayer(o.feature, bounds.getCenter()) :
new L.Marker(bounds.getCenter());*/
var center = bounds.getCenter();
var f = L.extend({},o.feature);
var f = L.extend({}, o.feature);
f.is_placeholder = true;
f.geometry = {
"type": "Point",
"coordinates": [center.lng, center.lat],
type: "Point",
coordinates: [center.lng, center.lat]
};
var c = L.GeoJSON.geometryToLayer(f, this.options.pointToLayer);
o.placeholder = c;
c.feature = f;
this.resetStyle(c);
c.obj = o;
//c.addEventListener("click dblclick mousedown mouseover mouseout contextmenu", function(e) {
c.on("click",function(e) {
this.obj.fireEvent(e.type,e);
c.on("click", function(e) {
this.obj.fireEvent(e.type, e);
});
this.addLayer(c);
this.removeLayer(o);
},this);
}, this);
}
});
L.geoJsonNoVanish = function (geojson, options) {
L.geoJsonNoVanish = function(geojson, options) {
return new L.GeoJsonNoVanish(geojson, options);
};

Expand Down
42 changes: 21 additions & 21 deletions js/OSM4Leaflet.js
@@ -1,36 +1,36 @@
import L from 'leaflet';
import osmtogeojson from 'osmtogeojson';
import L from "leaflet";
import osmtogeojson from "osmtogeojson";

L.OSM4Leaflet = L.Class.extend({
initialize: function (data, options) {
initialize: function(data, options) {
this.options = {
data_mode: "xml",
baseLayerClass: L.GeoJSON,
baseLayerOptions: {}
};
L.Util.setOptions(this,options);
L.Util.setOptions(this, options);

this._baseLayer = new this.options.baseLayerClass(null, this.options.baseLayerOptions);
this._baseLayer = new this.options.baseLayerClass(
null,
this.options.baseLayerOptions
);
this._resultData = null;
// if data
if (data)
this.addData(data);
if (data) this.addData(data);
},
addData: function(data, onDone) {
var obj = this;
setTimeout(function(){
// 1. convert to GeoJSON
var geojson = osmtogeojson(data, {flatProperties: false});
obj._resultData = geojson;
if (obj.options.afterParse)
obj.options.afterParse();
setTimeout(function(){
// 2. add to baseLayer
obj._baseLayer.addData(geojson);
if (onDone)
onDone();
},1); //end setTimeout
},1); //end setTimeout
setTimeout(function() {
// 1. convert to GeoJSON
var geojson = osmtogeojson(data, {flatProperties: false});
obj._resultData = geojson;
if (obj.options.afterParse) obj.options.afterParse();
setTimeout(function() {
// 2. add to baseLayer
obj._baseLayer.addData(geojson);
if (onDone) onDone();
}, 1); //end setTimeout
}, 1); //end setTimeout
},
getGeoJSON: function() {
return this._resultData;
Expand All @@ -46,7 +46,7 @@ setTimeout(function(){
}
});

L.osm4Leaflet = function (data, options) {
L.osm4Leaflet = function(data, options) {
return new L.OSM4Leaflet(data, options);
};

Expand Down

0 comments on commit aba961e

Please sign in to comment.