Skip to content

Commit b6292a0

Browse files
authored
#4 - Added ability for multiple detail maps to appear on a single view. Needed to give the <div> that contains the map a unique identifier. (#6)
1 parent 7821295 commit b6292a0

File tree

8 files changed

+67
-16
lines changed

8 files changed

+67
-16
lines changed

dist/ml-esri-maps-ng-tpls.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(function(module) {
2+
try {
3+
module = angular.module('ml.esri-maps.tpls');
4+
} catch (e) {
5+
module = angular.module('ml.esri-maps.tpls', []);
6+
}
7+
module.run(['$templateCache', function($templateCache) {
8+
$templateCache.put('/templates/detail-map.html',
9+
'<div id="{{ctrl.mapId}}" class="map-detail"></div>');
10+
}]);
11+
})();

dist/ml-esri-maps-ng-tpls.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ml-esri-maps-ng.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@
1818
scope: {
1919
geometry: '=',
2020
baseMap: '=',
21-
zoom: '='
21+
zoom: '=',
22+
mapId: '='
2223
},
23-
template: '<div id="detailMap" class="map-detail"></div>',
24+
templateUrl: '/templates/detail-map.html',
2425
controller: 'mlEsriDetailMapController',
2526
controllerAs: 'ctrl'
2627
};
2728
}
2829

29-
MLEsriDetailMapController.$inject = ['$scope'];
30-
function MLEsriDetailMapController($scope) {
30+
MLEsriDetailMapController.$inject = ['$scope', '$timeout'];
31+
function MLEsriDetailMapController($scope, $timeout) {
3132
var ctrl = this;
3233
var geometryData = [];
3334
var i=0;
3435

3536
// Settings
37+
ctrl.mapId = $scope.mapId ? $scope.mapId : 'detail-map-1';
3638
ctrl.baseMap = $scope.baseMap ? $scope.baseMap : 'national-geographic';
3739
ctrl.mapZoom = $scope.zoom ? $scope.zoom : 6;
3840
ctrl.mapGeometry = null;
@@ -60,7 +62,13 @@
6062
}
6163
}
6264

63-
initMap(geometryData);
65+
// Have to wait for scope value of <mapId> to be updated in view
66+
// before the map can be initialized.
67+
$scope.$watch('mapId', function(newValue) {
68+
$timeout(function(){
69+
initMap(geometryData);
70+
}, 300);
71+
});
6472

6573
/**
6674
* Initializes the map with a single feature layer for locations.
@@ -81,7 +89,7 @@
8189
processGeoData(geoData);
8290

8391
ctrl.map = new Map(
84-
'detailMap', {
92+
ctrl.mapId, {
8593
basemap: ctrl.baseMap,
8694
zoom: ctrl.mapZoom,
8795
smartNavigation: false

dist/ml-esri-maps-ng.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ var gulp = require('gulp'),
1111
uglify = require('gulp-uglify'),
1212
minifyCss = require('gulp-minify-css'),
1313
sourcemaps = require('gulp-sourcemaps'),
14-
info = require('gulp-print');
14+
info = require('gulp-print'),
15+
html2Js = require('gulp-ng-html2js'),
16+
minifyHtml = require('gulp-minify-html');
1517

1618
gulp.task('jshint', function() {
1719
return gulp.src([
@@ -71,4 +73,22 @@ gulp.task('styles', ['scripts'], function() {
7173
;
7274
});
7375

74-
gulp.task('default', ['styles']);
76+
gulp.task('templates', function() {
77+
return gulp.src([ './src/**/*.html' ])
78+
.pipe(minifyHtml({
79+
empty: true,
80+
spare: true,
81+
quotes: true
82+
}))
83+
.pipe(html2Js({
84+
moduleName: 'ml.esri-maps.tpls',
85+
prefix: '/'
86+
}))
87+
.pipe(concat('ml-esri-maps-ng-tpls.js'))
88+
.pipe(gulp.dest('dist'))
89+
.pipe(rename('ml-esri-maps-ng-tpls.min.js'))
90+
.pipe(uglify())
91+
.pipe(gulp.dest('dist'));
92+
});
93+
94+
gulp.task('default', ['styles', 'templates']);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"gulp-print": "^1.1.0",
1313
"gulp-less": "^3.0.3",
1414
"gulp-minify-css": "^1.2.0",
15-
"gulp-sourcemaps": "^1.5.2"
15+
"gulp-sourcemaps": "^1.5.2",
16+
"gulp-minify-html": "^1.0.3",
17+
"gulp-ng-html2js": "^0.2.0"
1618
},
1719
"engines": {
1820
"node": ">=0.8.0"

src/ml-esri-detail-map.directive.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@
1212
scope: {
1313
geometry: '=',
1414
baseMap: '=',
15-
zoom: '='
15+
zoom: '=',
16+
mapId: '='
1617
},
17-
template: '<div id="detailMap" class="map-detail"></div>',
18+
templateUrl: '/templates/detail-map.html',
1819
controller: 'mlEsriDetailMapController',
1920
controllerAs: 'ctrl'
2021
};
2122
}
2223

23-
MLEsriDetailMapController.$inject = ['$scope'];
24-
function MLEsriDetailMapController($scope) {
24+
MLEsriDetailMapController.$inject = ['$scope', '$timeout'];
25+
function MLEsriDetailMapController($scope, $timeout) {
2526
var ctrl = this;
2627
var geometryData = [];
2728
var i=0;
2829

2930
// Settings
31+
ctrl.mapId = $scope.mapId ? $scope.mapId : 'detail-map-1';
3032
ctrl.baseMap = $scope.baseMap ? $scope.baseMap : 'national-geographic';
3133
ctrl.mapZoom = $scope.zoom ? $scope.zoom : 6;
3234
ctrl.mapGeometry = null;
@@ -54,7 +56,13 @@
5456
}
5557
}
5658

57-
initMap(geometryData);
59+
// Have to wait for scope value of <mapId> to be updated in view
60+
// before the map can be initialized.
61+
$scope.$watch('mapId', function(newValue) {
62+
$timeout(function(){
63+
initMap(geometryData);
64+
}, 300);
65+
});
5866

5967
/**
6068
* Initializes the map with a single feature layer for locations.
@@ -75,7 +83,7 @@
7583
processGeoData(geoData);
7684

7785
ctrl.map = new Map(
78-
'detailMap', {
86+
ctrl.mapId, {
7987
basemap: ctrl.baseMap,
8088
zoom: ctrl.mapZoom,
8189
smartNavigation: false

src/templates/detail-map.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div id="{{ctrl.mapId}}" class="map-detail"></div>

0 commit comments

Comments
 (0)