diff --git a/ddmMapView.cpp b/ddmMapView.cpp index 1dc6411..350988a 100644 --- a/ddmMapView.cpp +++ b/ddmMapView.cpp @@ -219,6 +219,22 @@ void ddmMapView::fitCounty( int county_id ) } } +/** + * Центрирует и масштабирует текущее выделение на карте + * + * Устанавливает центр карты и масштаб таким образом, чтобы все выделенные графства попали в отображаемую область. + * + * @author Марунин А.В. + * @since 2.7 + */ +void ddmMapView::fitSelection() +{ + if ( this->mapReady() ) + { + this->evaluateJavaScript( QString( "window.ddmMap.fitSelection();" ) ); + } +} + /** * * diff --git a/ddmMapView.h b/ddmMapView.h index 70e5b74..3581598 100644 --- a/ddmMapView.h +++ b/ddmMapView.h @@ -38,6 +38,7 @@ class ddmMapView : public QWebView void setMarker( const QVariantMap& point ); void fitCounty( int county_id ); + void fitSelection(); bool mapReady() const; diff --git a/ddmVersion.h b/ddmVersion.h index 45f9fef..51fca10 100644 --- a/ddmVersion.h +++ b/ddmVersion.h @@ -3,6 +3,6 @@ #define DDM_MAJOR_VERSION 2 #define DDM_MINOR_VERSION 7 -#define DDM_BUILD_NUMBER 333 +#define DDM_BUILD_NUMBER 336 #endif // DDM_VERSION_H diff --git a/js/ddm.js b/js/ddm.js index d822a0a..035b1c2 100644 --- a/js/ddm.js +++ b/js/ddm.js @@ -8,6 +8,7 @@ marker: false, counties: {}, selection: [], + bounds: false, initialize: function() { // console.log( 'ddmMap.initialize' ); @@ -48,6 +49,8 @@ ddmMapView.resized.connect( self, self.resize ); } + self.bounds = new google.maps.LatLngBounds(); + return this; }, @@ -112,17 +115,24 @@ var selection = _.result( ddmFilter, 'selection', [] ) || []; //console.log( 'ddmMap.update selection.length=' + selection.length ); + var bounds = new google.maps.LatLngBounds(); _.each( selection, function( item ) { if ( !_.has( self.counties, item.id ) ) { //_.defer( function() { - self._addCounty( item.id ); + county = self._addCounty( item.id ); + bounds.union( county.bounds ); //}); } else { self.show( item.id ); + county = self.counties[id]; + bounds.union( county.bounds ); } }); self.selection = selection; + self.bounds = bounds; + // console.log( bounds.toString() ); + self.fitSelection(); return this; }, @@ -174,6 +184,14 @@ return this; }, + fitSelection: function() { + var self = this; + if ( !self.bounds.isEmpty() ) { + self.map.fitBounds( self.bounds ); + } + return this; + }, + _findCounty: function( id ) { // console.log( 'ddmMap._findCounty' ); return _.find( ddmFilter.model.counties, function( county ) { @@ -257,7 +275,7 @@ polygon.setVisible( true ); - return this; + return self.counties[id]; }, _createPoint: function( lat, lng ) {