AngularJS with OpenLayers

1,847 views
Skip to first unread message

obura...@gmail.com

unread,
Jul 26, 2012, 3:23:30 AM7/26/12
to ang...@googlegroups.com
Hi,
I'm evaluating AngularJS for my project which is a web/mobile GIS app that will be using OpenLayers. Currently I'm struggling to initialize OpenLayer from the Angular-driven code. It seems "normal" javascript is not being called called (e.g. by onload event for example). Is there a way to call a function from a third-party library in Angular?

Peter Bacon Darwin

unread,
Jul 26, 2012, 3:58:48 AM7/26/12
to ang...@googlegroups.com
Have you tried running it from a controller?

On 26 July 2012 08:23, <obura...@gmail.com> wrote:
Hi,
I'm evaluating AngularJS for my project which is a web/mobile GIS app that will be using OpenLayers. Currently I'm struggling to initialize OpenLayer from the Angular-driven code. It seems "normal" javascript is not being called called (e.g. by onload event for example). Is there a way to call a function from a third-party library in Angular?

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/YRBGs-KE3EsJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

obura...@gmail.com

unread,
Jul 26, 2012, 4:42:11 AM7/26/12
to ang...@googlegroups.com
It's not being called from a controller.

'use strict';

/* Controllers */

function MapViewCtrl($scope, $routeParams) {
    $scope.workspaceName = $routeParams.workspaceName;
    $scope.mapName = $routeParams.mapName;

    initMap();
}

MapViewCtrl.$inject = ['$scope', '$routeParams'];



But I managed to get the function called by wrapping it in a directive.

angular.module('myApp.directives', []).
  directive('appVersion', ['version', function(version) {
    return function(scope, elm, attrs) {
      initMap(); // a JS function declared in other file
      elm.text(version);
    };
  }]);


On Thursday, July 26, 2012 5:58:48 PM UTC+10, Peter Bacon Darwin wrote:
Have you tried running it from a controller?

On 26 July 2012 08:23, <obura...@gmail.com> wrote:
Hi,
I'm evaluating AngularJS for my project which is a web/mobile GIS app that will be using OpenLayers. Currently I'm struggling to initialize OpenLayer from the Angular-driven code. It seems "normal" javascript is not being called called (e.g. by onload event for example). Is there a way to call a function from a third-party library in Angular?

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/YRBGs-KE3EsJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Peter Bacon Darwin

unread,
Jul 26, 2012, 7:00:39 AM7/26/12
to ang...@googlegroups.com

Are you sure it is not being called. I suspect it is but that the library is relying on the scope being bound to some element before the call.

You could try putting the call to initMap in a $timeout to ensure the digest has updated everything.

Pete
...from my mobile.

To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/rPVS72444NoJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages