-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add feature grid based on ag-grid
- Loading branch information
Showing
5 changed files
with
1,457 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
This example demonstrates the usage of the AgFeatureGrid: | ||
|
||
```jsx | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const OlMap = require('ol/map').default; | ||
const OlView = require('ol/view').default; | ||
const OlLayerTile = require('ol/layer/tile').default; | ||
const OlSourceOsm = require('ol/source/osm').default; | ||
const OlProj = require('ol/proj').default; | ||
const OlFormatGeoJson = require('ol/format/geojson').default; | ||
|
||
const federalStates = require('../../../assets/federal-states-ger.json'); | ||
|
||
const format = new OlFormatGeoJson(); | ||
const features = format.readFeatures(federalStates); | ||
|
||
class NameColumnRenderer extends React.Component { | ||
render() { | ||
const { | ||
value | ||
} = this.props; | ||
return <a href={`https://en.wikipedia.org/wiki/${value}`}>{value}</a>; | ||
} | ||
} | ||
|
||
NameColumnRenderer.propTypes = { | ||
value: PropTypes.any | ||
}; | ||
|
||
class MathRoundRenderer extends React.Component { | ||
render() { | ||
const { | ||
value | ||
} = this.props; | ||
return Math.round(value); | ||
} | ||
} | ||
|
||
MathRoundRenderer.propTypes = { | ||
value: PropTypes.any | ||
}; | ||
|
||
class AgFeatureGridExample extends React.Component { | ||
|
||
constructor(props) { | ||
|
||
super(props); | ||
|
||
this.mapDivId = `map-${Math.random()}`; | ||
|
||
this.map = new OlMap({ | ||
layers: [ | ||
new OlLayerTile({ | ||
name: 'OSM', | ||
source: new OlSourceOsm() | ||
}) | ||
], | ||
view: new OlView({ | ||
center: OlProj.fromLonLat([37.40570, 8.81566]), | ||
zoom: 4 | ||
}) | ||
}); | ||
} | ||
|
||
componentDidMount() { | ||
this.map.setTarget(this.mapDivId); | ||
} | ||
|
||
render() { | ||
return( | ||
<div> | ||
<AgFeatureGrid | ||
features={features} | ||
map={this.map} | ||
enableSorting={true} | ||
enableFilter={true} | ||
enableColResize={true} | ||
attributeBlacklist={['gml_id', 'USE', 'RS', 'RS_ALT']} | ||
columnDefs={{ | ||
'GEN': { | ||
headerName: 'Name', | ||
cellRenderer: 'nameColumnRenderer' | ||
}, | ||
'SHAPE_LENG': { | ||
headerName: 'Length', | ||
cellRenderer: 'mathRoundRenderer' | ||
}, | ||
'SHAPE_AREA': { | ||
headerName: 'Area', | ||
cellRenderer: 'mathRoundRenderer' | ||
} | ||
}} | ||
zoomToExtent={true} | ||
selectable={true} | ||
frameworkComponents={{ | ||
nameColumnRenderer: NameColumnRenderer, | ||
mathRoundRenderer: MathRoundRenderer | ||
}} | ||
/> | ||
<div | ||
id={this.mapDivId} | ||
style={{ | ||
height: '400px' | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
<AgFeatureGridExample /> | ||
``` |
Oops, something went wrong.