Skip to content

Commit

Permalink
ddmMapView: Реализован метод fitSelection для авто-масштабирования ка…
Browse files Browse the repository at this point in the history
…рты (при отображении нескольких выделенных графств)
  • Loading branch information
alexeymarunin committed Mar 16, 2015
1 parent 673af2f commit 1ff8168
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
16 changes: 16 additions & 0 deletions ddmMapView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();" ) );
}
}

/**
*
*
Expand Down
1 change: 1 addition & 0 deletions ddmMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ddmMapView : public QWebView
void setMarker( const QVariantMap& point );

void fitCounty( int county_id );
void fitSelection();

bool mapReady() const;

Expand Down
2 changes: 1 addition & 1 deletion ddmVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 20 additions & 2 deletions js/ddm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
marker: false,
counties: {},
selection: [],
bounds: false,

initialize: function() {
// console.log( 'ddmMap.initialize' );
Expand Down Expand Up @@ -48,6 +49,8 @@
ddmMapView.resized.connect( self, self.resize );
}

self.bounds = new google.maps.LatLngBounds();

return this;
},

Expand Down Expand Up @@ -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;
},

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -257,7 +275,7 @@

polygon.setVisible( true );

return this;
return self.counties[id];
},

_createPoint: function( lat, lng ) {
Expand Down

0 comments on commit 1ff8168

Please sign in to comment.