Skip to content

Commit

Permalink
Ensure openlayers mapinfo state is immediately updated as soon as com…
Browse files Browse the repository at this point in the history
…ponent mounted
  • Loading branch information
manisandro committed Dec 13, 2016
1 parent e937622 commit e059cb0
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions web/client/components/map/openlayers/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,7 @@ var OpenlayersMap = React.createClass({
target: this.props.id,
view: this.createView(center, Math.round(this.props.zoom), this.props.projection, this.props.mapOptions && this.props.mapOptions.view)
});
map.on('moveend', () => {
let view = map.getView();
let c = this.normalizeCenter(view.getCenter());
let bbox = view.calculateExtent(map.getSize());
let size = {
width: map.getSize()[0],
height: map.getSize()[1]
};
this.props.onMapViewChanges({x: c[0] || 0.0, y: c[1] || 0.0, crs: 'EPSG:4326'}, view.getZoom(), {
bounds: {
minx: bbox[0],
miny: bbox[1],
maxx: bbox[2],
maxy: bbox[3]
},
crs: view.getProjection().getCode(),
rotation: view.getRotation()
}, size, this.props.id, this.props.projection);
});
map.on('moveend', this.updateMapInfoState);
map.on('singleclick', (event) => {
if (this.props.onClick) {
let pos = event.coordinate.slice();
Expand Down Expand Up @@ -167,6 +149,7 @@ var OpenlayersMap = React.createClass({
});

this.map = map;
this.updateMapInfoState();
this.setMousePointer(this.props.mousePointer);
// NOTE: this re-call render function after div creation to have the map initialized.
this.forceUpdate();
Expand All @@ -175,6 +158,25 @@ var OpenlayersMap = React.createClass({
this.registerHooks();
}
},
updateMapInfoState() {
let view = this.map.getView();
let c = this.normalizeCenter(view.getCenter());
let bbox = view.calculateExtent(this.map.getSize());
let size = {
width: this.map.getSize()[0],
height: this.map.getSize()[1]
};
this.props.onMapViewChanges({x: c[0] || 0.0, y: c[1] || 0.0, crs: 'EPSG:4326'}, view.getZoom(), {
bounds: {
minx: bbox[0],
miny: bbox[1],
maxx: bbox[2],
maxy: bbox[3]
},
crs: view.getProjection().getCode(),
rotation: view.getRotation()
}, size, this.props.id, this.props.projection);
},
componentWillReceiveProps(newProps) {
if (newProps.mousePointer !== this.props.mousePointer) {
this.setMousePointer(newProps.mousePointer);
Expand Down

0 comments on commit e059cb0

Please sign in to comment.