|
280 | 280 | (function() { |
281 | 281 | 'use strict'; |
282 | 282 |
|
283 | | - angular.module('angular-mapbox').directive('mapbox', function($compile, $q, mapboxService) { |
| 283 | + angular.module('angular-mapbox').directive('mapbox', function($compile, $q, $parse, mapboxService) { |
284 | 284 | var _mapboxMap; |
285 | 285 |
|
286 | 286 | return { |
|
298 | 298 | }; |
299 | 299 | mapboxService.addMapInstance(scope.map, mapOptions); |
300 | 300 |
|
| 301 | + if (attrs.dragging === 'false') { |
| 302 | + scope.map.dragging.disable(); |
| 303 | + } |
| 304 | + if (attrs.touchZoom === 'false') { |
| 305 | + scope.map.touchZoom.disable(); |
| 306 | + } |
| 307 | + if (attrs.doubleClickZoom === 'false') { |
| 308 | + scope.map.doubleClickZoom.disable(); |
| 309 | + } |
| 310 | + if (attrs.scrollWheelZoom === 'false') { |
| 311 | + scope.map.scrollWheelZoom.disable(); |
| 312 | + } |
| 313 | + |
301 | 314 | var mapWidth = attrs.width || 500; |
302 | 315 | var mapHeight = attrs.height || 500; |
303 | | - element.css('width', mapWidth + 'px'); |
304 | | - element.css('height', mapHeight + 'px'); |
| 316 | + element.css('width', mapWidth + (/^[0-9]+$/.test(mapWidth)?'px':'')); |
| 317 | + element.css('height', mapHeight + (/^[0-9]+$/.test(mapHeight)?'px':'')); |
305 | 318 |
|
306 | 319 | scope.zoom = attrs.zoom || 12; |
307 | 320 | if(attrs.lat && attrs.lng) { |
308 | 321 | scope.map.setView([attrs.lat, attrs.lng], scope.zoom); |
309 | 322 | } |
310 | 323 |
|
311 | 324 | if(attrs.onReposition) { |
312 | | - scope.map.on('dragend', function() { |
313 | | - scope[attrs.onReposition](scope.map.getBounds()); |
| 325 | + var repositionFn = $parse(attrs.onReposition, null, true); |
| 326 | + scope.map.on('dragend', function(event) { |
| 327 | + scope.$apply(function() { |
| 328 | + repositionFn(scope, {$event:event}); |
| 329 | + }); |
314 | 330 | }); |
315 | 331 | } |
316 | 332 |
|
317 | 333 | if(attrs.onZoom) { |
318 | | - scope.map.on('zoomend', function() { |
319 | | - scope[attrs.onZoom](scope.map.getBounds()); |
| 334 | + var zoomFn = $parse(attrs.onZoom, null, true); |
| 335 | + scope.map.on('zoomend', function(event) { |
| 336 | + scope.$apply(function() { |
| 337 | + zoomFn(scope, {$event:event}); |
| 338 | + }); |
| 339 | + }); |
| 340 | + } |
| 341 | + |
| 342 | + if(attrs.onClick) { |
| 343 | + var clickFn = $parse(attrs.onClick, null, true); |
| 344 | + scope.map.on('click', function(event) { |
| 345 | + scope.$apply(function() { |
| 346 | + clickFn(scope, {$event:event}); |
| 347 | + }); |
320 | 348 | }); |
321 | 349 | } |
322 | 350 |
|
|
357 | 385 | (function() { |
358 | 386 | 'use strict'; |
359 | 387 |
|
360 | | - angular.module('angular-mapbox').directive('marker', function($compile, $timeout, mapboxService) { |
| 388 | + angular.module('angular-mapbox').directive('marker', function($compile, $timeout, $parse, mapboxService) { |
361 | 389 | var _colors = { |
362 | 390 | navy: '#001f3f', |
363 | 391 | blue: '#0074d9', |
|
413 | 441 | map.locate(); |
414 | 442 | } else { |
415 | 443 | _marker = addMarker(scope, map, [attrs.lat, attrs.lng], popupContentElement, _opts, _style); |
| 444 | + |
| 445 | + if(attrs.onClick) { |
| 446 | + var clickFn = $parse(attrs.onClick, null, true); |
| 447 | + _marker.on('click', function() { |
| 448 | + scope.$apply(function() { |
| 449 | + clickFn(scope, {$event:event}); |
| 450 | + }); |
| 451 | + }); |
| 452 | + } |
416 | 453 | } |
417 | 454 | }); |
418 | 455 |
|
|
0 commit comments