Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

[r1-dev] Get map options from scope, instead of parsing HTML-embedded JSON #80

Merged
merged 8 commits into from
Aug 19, 2013
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ old/
tmp/
*~
app/components
/nbproject
/nbproject
.idea
60 changes: 30 additions & 30 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-open');
grunt.loadNpmTasks('grunt-mkdir');
grunt.loadNpmTasks('grunt-contrib-coffee');


// Project configuration.
grunt.initConfig({

pkg: grunt.file.readJSON('package.json'),

clean: {
coffee: ['tmp/output_coffee.js'],
dist: ['dist/*', 'tmp'],
example: ['example/<%= pkg.name %>.js']
},

mkdir: {
all: {
options: {
Expand All @@ -36,7 +36,7 @@ module.exports = function(grunt) {
coffee: {
compile: {
files: {
'tmp/output_coffee.js':
'tmp/output_coffee.js':
['src/coffee/*.coffee',
'src/coffee/oo/ng-gmap-module.coffee',
'src/coffee/oo/base-object.coffee',
Expand All @@ -48,20 +48,20 @@ module.exports = function(grunt) {
}
}
},

concat: {
options: {
separator: ';'
},
dist: {
src: ['src/js/module.js',
src: ['src/js/module.js',
'tmp/output_coffee.js',
'src/js/utils/LatLngArraySync.js',
'src/js/utils/MapEvents.js',
'src/js/utils/LatLngArraySync.js',
'src/js/utils/MapEvents.js',
'src/js/controllers/polyline-display.js',
'src/js/directives/map.js',
'src/js/directives/marker.js',
'src/js/directives/markers.js',
'src/js/directives/map.js',
'src/js/directives/marker.js',
'src/js/directives/markers.js',
'src/js/directives/polygon.js',
'src/js/directives/polyline.js',
'src/js/directives/window.js',
Expand All @@ -72,12 +72,12 @@ module.exports = function(grunt) {
example: {
src: ['src/js/module.js',
'tmp/output_coffee.js',
'src/js/utils/LatLngArraySync.js',
'src/js/utils/MapEvents.js',
'src/js/utils/LatLngArraySync.js',
'src/js/utils/MapEvents.js',
'src/js/controllers/polyline-display.js',
'src/js/directives/map.js',
'src/js/directives/marker.js',
'src/js/directives/markers.js',
'src/js/directives/map.js',
'src/js/directives/marker.js',
'src/js/directives/markers.js',
'src/js/directives/polygon.js',
'src/js/directives/polyline.js',
'src/js/directives/window.js',
Expand All @@ -86,7 +86,7 @@ module.exports = function(grunt) {
dest: 'example/<%= pkg.name %>.js'
}
},

copy: {
dist: {
files: [{
Expand All @@ -95,7 +95,7 @@ module.exports = function(grunt) {
}]
}
},

uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %>\n * <%= pkg.description %>\n * <%= pkg.repository.type %>: <%= pkg.repository.url %>\n */\n',
Expand All @@ -107,29 +107,29 @@ module.exports = function(grunt) {
dest: 'dist/<%= pkg.name %>.min.js'
}
},

jshint: {
all: ['Gruntfile.js', 'src/js/**/*.js', 'test/js/**/*.js']
},

test: {

},

watch: {
all: {
options: { livereload: true },
files: ['src/js/**/*.js','src/coffee/**/*.coffee','src/coffee/*.coffee'],
tasks: ['clean:example','coffee','concat:example'],
},
},

open: {
example: {
path: 'http://localhost:3000/example.html'
}
},

connect: {
server: {
options: {
Expand All @@ -147,14 +147,14 @@ module.exports = function(grunt) {

// Default task: build a release in dist/
grunt.registerTask('default', ['clean:dist',
'test',
'jshint',
'mkdir',
'test',
'jshint',
'mkdir',
'coffee',
'concat:dist',
'concat:dist',
'copy:dist',
'uglify']);

// Run the example page by creating a local copy of angular-google-maps.js
// and running a webserver on port 3000 with livereload. Web page is opened
// automatically in the default browser.
Expand Down
11 changes: 6 additions & 5 deletions dist/angular-google-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ angular.module('google-maps')
.directive('googleMap', ['$log', '$timeout', function ($log, $timeout) {

"use strict";

directives.api.utils.Logger.logger = $log;

var DEFAULTS = {
Expand Down Expand Up @@ -1542,7 +1542,8 @@ angular.module('google-maps')
markers: '=markers', // optional
refresh: '&refresh', // optional
windows: '=windows', // optional
events: '=events', // optional
options: '=options', // optional
events: '=events', // optional
bounds: '=bounds'
},

Expand Down Expand Up @@ -1587,7 +1588,7 @@ angular.module('google-maps')
// Parse options
var opts = {options: {}};
if (attrs.options) {
opts.options = angular.fromJson(attrs.options);
opts.options = scope.options;
}

if (attrs.type) {
Expand Down Expand Up @@ -1654,7 +1655,7 @@ angular.module('google-maps')
google.maps.event.addListener(_m, 'center_changed', function () {
var c = _m.center;

if(settingCenterFromScope)
if(settingCenterFromScope)
return; //if the scope notified this change then there is no reason to update scope otherwise infinite loop
$timeout(function () {
scope.$apply(function (s) {
Expand Down Expand Up @@ -1757,7 +1758,7 @@ angular.module('google-maps')

//_m.draw();
});

scope.$watch('bounds', function (newValue, oldValue) {
if (newValue === oldValue) {
return;
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-google-maps.min.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions example/example-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function ExampleController ($scope, $timeout, $log) {
latitude: 45,
longitude: -73
},
options: {
streetViewControl: false,
panControl: false
},
zoom: 3,
dragging: false,
bounds: {},
Expand Down Expand Up @@ -169,7 +173,7 @@ function ExampleController ($scope, $timeout, $log) {
});

_.each($scope.map.markers,function(marker){
marker.closeClick = function(){
marker.closeClick = function(){
marker.showWindow = false;
$scope.$apply();
};
Expand All @@ -179,7 +183,7 @@ function ExampleController ($scope, $timeout, $log) {
});

_.each($scope.map.markers2,function(marker){
marker.closeClick = function(){
marker.closeClick = function(){
marker.showWindow = false;
$scope.$apply();
};
Expand Down Expand Up @@ -219,7 +223,7 @@ function ExampleController ($scope, $timeout, $log) {
}
];
_.each(dynamicMarkers,function(marker){
marker.closeClick = function(){
marker.closeClick = function(){
marker.showWindow = false;
$scope.$apply();
};
Expand Down
9 changes: 5 additions & 4 deletions example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<!--[if IE]>
<script>
window.html5 = {
'elements': 'marker window windows markers trafficlayer polyline'
'elements': 'marker window windows markers trafficlayer polyline'
};
</script>

<script src="es5-shim.js"></script>
<script src="event-shim.js"></script>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,800,600,300,700' rel='stylesheet' type='text/css'>
<style>
Expand Down Expand Up @@ -74,7 +74,8 @@ <h1>angular-google-maps example</h1>
draggable="true"
dragging="map.dragging"
bounds="map.bounds"
events="map.events">
events="map.events"
options="map.options">
<trafficlayer show="map.showTraffic" />

<markers models="map.markers2" coords="'self'" icon="'icon'" click="'onClicked'">
Expand Down
11 changes: 6 additions & 5 deletions src/js/directives/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ angular.module('google-maps')
.directive('googleMap', ['$log', '$timeout', function ($log, $timeout) {

"use strict";

directives.api.utils.Logger.logger = $log;

var DEFAULTS = {
Expand Down Expand Up @@ -90,7 +90,8 @@ angular.module('google-maps')
markers: '=markers', // optional
refresh: '&refresh', // optional
windows: '=windows', // optional
events: '=events', // optional
options: '=options', // optional
events: '=events', // optional
bounds: '=bounds'
},

Expand Down Expand Up @@ -135,7 +136,7 @@ angular.module('google-maps')
// Parse options
var opts = {options: {}};
if (attrs.options) {
opts.options = angular.fromJson(attrs.options);
opts.options = scope.options;
}

if (attrs.type) {
Expand Down Expand Up @@ -202,7 +203,7 @@ angular.module('google-maps')
google.maps.event.addListener(_m, 'center_changed', function () {
var c = _m.center;

if(settingCenterFromScope)
if(settingCenterFromScope)
return; //if the scope notified this change then there is no reason to update scope otherwise infinite loop
$timeout(function () {
scope.$apply(function (s) {
Expand Down Expand Up @@ -305,7 +306,7 @@ angular.module('google-maps')

//_m.draw();
});

scope.$watch('bounds', function (newValue, oldValue) {
if (newValue === oldValue) {
return;
Expand Down