<commit_before>goog.provide('mapextension');

goog.require('ngeo_map_directive');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.layer.Tile');
goog.require('ol.source.OSM');

(function() {
  var module = angular.module('app', ['ngeo']);

  /**
   * An application-specific map directive. This directive gets a reference
   * to the map instance through the "app-map" attribute.
   */
  module.directive('appMap', [
    /**
     * @return {angular.Directive} The directive specs.
     */
    function() {
      return {
        restrict: 'E',
        scope: {
          'map': '=appMap'
        },
        controller: function() {
          var map = this['map'];
          // do something with map…
          map.getView().on('propertychange',
              /**
               * @param {ol.ObjectEvent} e Object event.
               */
              function(e) {
                // we simply output the view property here, but we
                // could update the browser URL for example…
                window.console.log('"' + e.key + '" event received');
              });
        },
        controllerAs: 'ctrl',
        bindToController: true,
        template: '<div ngeo-map=ctrl.map></div>'
      };
    }]);


  module.controller('MainController', ['$scope',
    /**
     * @param {angular.Scope} $scope Scope.
     */
    function($scope) {
      /** @type {ol.Map} */
      this['map'] = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        view: new ol.View({
          center: [0, 0],
          zoom: 4
        })
      });
    }]);

})();<commit_msg>Use location service in map-extension example<commit_after>goog.provide('mapextension');

goog.require('ngeo_location_service');
goog.require('ngeo_map_directive');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.layer.Tile');
goog.require('ol.source.OSM');

(function() {
  var module = angular.module('app', ['ngeo']);

  /**
   * An application-specific map directive that updates the URL in the browser
   * address bar when the map view changes. It also sets the initial view based
   * on the URL query params at init time.
   *
   * This directive gets a reference to the map instance through the "app-map"
   * attribute.
   */
  module.directive('appMap', [
    /**
     * @return {angular.Directive} The directive specs.
     */
    function(ngeoLocation) {
      return {
        restrict: 'E',
        scope: {
          'map': '=appMap'
        },
        controller: 'AppMapController',
        controllerAs: 'ctrl',
        bindToController: true,
        template: '<div ngeo-map=ctrl.map></div>'
      };
    }]);


  /**
   * The controller for the `appMap` directive.
   */
  module.controller('AppMapController', ['$scope', 'ngeoLocation',
    /**
     * @param {angular.Scope} $scope Scope.
     * @param {ngeo.Location} ngeoLocation ngeo Location service.
     */
    function($scope, ngeoLocation) {
      var map = this['map'];
      var view = map.getView();

      var zoom = ngeoLocation.getParam('z');
      zoom = angular.isDefined(zoom) ? +zoom : 4;

      var x = ngeoLocation.getParam('x');
      var y = ngeoLocation.getParam('y');
      var center = angular.isDefined(x) && angular.isDefined(y) ?
          [+x, +y] : [0, 0];

      view.setCenter(center);
      view.setZoom(zoom);

      ngeoLocation.updateParams({
        'z': zoom,
        'x': Math.round(center[0]),
        'y': Math.round(center[1])
      });

      view.on('propertychange',
          /**
           * @param {ol.ObjectEvent} e Object event.
           */
          function(e) {
            var center = view.getCenter();
            var params = {
              'z': view.getZoom(),
              'x': Math.round(center[0]),
              'y': Math.round(center[1])
            };
            $scope.$apply(function() {
              ngeoLocation.updateParams(params);
            });
          });

    }]);


  module.controller('MainController', ['$scope',
    /**
     * @param {angular.Scope} $scope Scope.
     */
    function($scope) {
      /** @type {ol.Map} */
      this['map'] = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ]
      });
    }]);

})();
{'fraction_non_alphanumeric': 0.16228676809589673, 'fraction_numerical': 0.002305209774089442, 'mean_word_length': 1.9357239512855209, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686307', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1292, 'n_words': 290}