Skip to content

Instantly share code, notes, and snippets.

@chilijung
Created November 25, 2015 14:48
Show Gist options
  • Save chilijung/25094c4ac4116f31fb38 to your computer and use it in GitHub Desktop.
Save chilijung/25094c4ac4116f31fb38 to your computer and use it in GitHub Desktop.
// seperate data to polygon, line, point and sent to different groups
if(data.type === 'FeatureCollection') {
var polygonData = [],
lineData = [],
pointData = [];
// loop through features
data.features.forEach(function(d) {
d.properties.react_d3_map__id = Math.floor(Math.random() * 100000)
if(d.geometry.type === 'Polygon' || d.geometry.type === 'MultiPolygon') {
// polygon
polygonData.push(d);
}else if (d.geometry.type === 'LineString' || d.geometry.type === 'MultiLineString') {
// line
lineData.push(d);
}else if (d.geometry.type === 'Point' || d.geometry.type === 'MultiPoint') {
// point
pointData.push(d);
}
})
}else if(data.type === 'Feature') {
var polygonData, lineData, pointData;
data.properties.react_d3_map__id = Math.floor(Math.random() * 100000)
if(data.geometry.type === 'Polygon' || data.geometry.type === 'MultiPolygon') {
// polygon
polygonData = data;
}else if (data.geometry.type === 'LineString' || data.geometry.type === 'MultiLineString') {
// line
lineData = data;
}else if (data.geometry.type === 'Point' || data.geometry.type === 'MultiPoint') {
// point
pointData = data;
}
}
this.state = {
polygonData: polygonData,
lineData: lineData,
pointData: pointData
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment