Skip to content

Commit

Permalink
nunaliit2-js: Add utilities to set up map cluster click behaviour:
Browse files Browse the repository at this point in the history
mapClusterClickToZoom, mapClusterClickToMultiSelect and
mapClusterClickHandler.

Issue #628
  • Loading branch information
jpfiset committed Feb 22, 2017
1 parent a1d0152 commit 13aec57
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 0 deletions.
1 change: 1 addition & 0 deletions nunaliit2-js/compress/nunaliit2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dbweb.js
n2.mapAndControls.js
n2.mapStyles.js
n2.mapInitialBounds.js
n2.mapUtilities.js
patcher.js
n2.GeoJsonGeometryCompressor.js
n2.GeoJsonFeatureCoordinatesProcessor.js
Expand Down
4 changes: 4 additions & 0 deletions nunaliit2-js/src/main/js/nunaliit2/n2.mapAndControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4896,6 +4896,10 @@ var MapAndControls = $n2.Class({
this.map.setCenter(ll, z, false, false);
},

getResolution: function(){
return this.map.getResolution();
},

/**
* This is called when the map has moved.
*/
Expand Down
218 changes: 218 additions & 0 deletions nunaliit2-js/src/main/js/nunaliit2/n2.mapUtilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/*
Copyright (c) 2017, Geomatics and Cartographic Research Centre, Carleton
University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of the Geomatics and Cartographic Research Centre,
Carleton University nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

;(function($n2){
"use strict";

// Localization
var _loc = function(str,args){ return $n2.loc(str,'nunaliit2',args); }
,DH='n2.mapUtilities';

//=========================================================================
var MapClusterClickToZoom = $n2.Class('MapClusterClickToZoom',{

customService: undefined,

initialize: function(opts_){
var opts = $n2.extend({
customService: undefined
},opts_);

var _this = this;

this.customService = opts.customService;

if( this.customService ){
this.customService.setOption('mapClusterClickCallback',$n2.mapAndControls.ZoomInClusterClickCallback);
};

$n2.log(this._classname, this);
}
});

//=========================================================================
var MapClusterClickToMultiSelect = $n2.Class('MapClusterClickToMultiSelect',{

customService: undefined,

initialize: function(opts_){
var opts = $n2.extend({
customService: undefined
},opts_);

var _this = this;

this.customService = opts.customService;

if( this.customService ){
this.customService.setOption('mapClusterClickCallback',$n2.mapAndControls.MultiSelectClusterClickCallback);
};

$n2.log(this._classname, this);
}
});

//=========================================================================
var MapClusterClickHandler = $n2.Class('MapClusterClickHandler',{

customService: undefined,

minimumCountToZoom: undefined,

minimumResolutionToZoom: undefined,

initialize: function(opts_){
var opts = $n2.extend({
customService: undefined
,minimumCountToZoom: 0
,minimumResolutionToZoom: -1
},opts_);

var _this = this;

this.customService = opts.customService;
if( typeof opts.minimumCountToZoom === 'number' ){
this.minimumCountToZoom = opts.minimumCountToZoom;
} else {
$n2.logError('MapClusterClickHandler: minimumCountToZoom must be a number');
};
if( typeof opts.minimumResolutionToZoom === 'number' ){
this.minimumResolutionToZoom = opts.minimumResolutionToZoom;
} else {
$n2.logError('MapClusterClickHandler: minimumResolutionToZoom must be a number');
};

if( this.customService ){
var f = function(feature, mapAndControls){
_this._clusterClickCallback(feature, mapAndControls);
};

this.customService.setOption('mapClusterClickCallback',f);
};

$n2.log(this._classname, this);
},

_clusterClickCallback: function(feature, mapAndControls){
var zoom = false;
if( feature.cluster
&& feature.cluster.length >= this.minimumCountToZoom ) {
zoom = true;
};
if( this.minimumResolutionToZoom > 0 ){
var resolution = mapAndControls.getResolution();
if( resolution <= this.minimumResolutionToZoom ){
zoom = false;
};
};

if( zoom ){
$n2.mapAndControls.ZoomInClusterClickCallback(feature, mapAndControls);
} else {
$n2.mapAndControls.MultiSelectClusterClickCallback(feature, mapAndControls);
};
}
});

//=========================================================================
function HandleUtilityCreateRequests(m, addr, dispatcher){
if( 'mapClusterClickToZoom' === m.utilityType ){
var options = {};

if( typeof m.utilityOptions === 'object' ){
for(var key in m.utilityOptions){
var value = m.utilityOptions[key];
options[key] = value;
};
};

if( m.config ){
if( m.config.directory ){
options.customService = m.config.directory.customService;
};
};

new MapClusterClickToZoom(options);

m.created = true;

} else if( 'mapClusterClickToMultiSelect' === m.utilityType ){
var options = {};

if( typeof m.utilityOptions === 'object' ){
for(var key in m.utilityOptions){
var value = m.utilityOptions[key];
options[key] = value;
};
};

if( m.config ){
if( m.config.directory ){
options.customService = m.config.directory.customService;
};
};

new MapClusterClickToMultiSelect(options);

m.created = true;

} else if( 'mapClusterClickHandler' === m.utilityType ){
var options = {};

if( typeof m.utilityOptions === 'object' ){
for(var key in m.utilityOptions){
var value = m.utilityOptions[key];
options[key] = value;
};
};

if( m.config ){
if( m.config.directory ){
options.customService = m.config.directory.customService;
};
};

new MapClusterClickHandler(options);

m.created = true;
};
};

//=========================================================================
$n2.mapUtilities = {
HandleUtilityCreateRequests: HandleUtilityCreateRequests
,MapClusterClickToZoom: MapClusterClickToZoom
,MapClusterClickToMultiSelect: MapClusterClickToMultiSelect
,MapClusterClickHandler: MapClusterClickHandler
};

})(nunaliit2);
6 changes: 6 additions & 0 deletions nunaliit2-js/src/main/js/nunaliit2/n2.utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ var Service = $n2.Class({
new SelectDocumentOnModuleIntroduction(options);

m.created = true;

} else {
if( $n2.mapUtilities
&& typeof $n2.mapUtilities.HandleUtilityCreateRequests === 'function' ){
$n2.mapUtilities.HandleUtilityCreateRequests(m, addr, dispatcher);
};
};
};
}
Expand Down

0 comments on commit 13aec57

Please sign in to comment.