From e059cb057a73fd7361a4897761f14ee29d5c2199 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Tue, 13 Dec 2016 11:08:17 +0100 Subject: [PATCH] Ensure openlayers mapinfo state is immediately updated as soon as component mounted --- web/client/components/map/openlayers/Map.jsx | 40 ++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/web/client/components/map/openlayers/Map.jsx b/web/client/components/map/openlayers/Map.jsx index 00e6baff176..8a2468a9b4c 100644 --- a/web/client/components/map/openlayers/Map.jsx +++ b/web/client/components/map/openlayers/Map.jsx @@ -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(); @@ -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(); @@ -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);