PageSourceSearch

http://monumenta.gov.br/assets/js/ng.search.controller.spatial-521801298-1649785341.js

js monumenta.gov.br collected 2026-10-02 14:18:37 UTC 9,361 bytes, 229 lines download raw bytes

1(function(angular) {
2    var app = angular.module('search.controller.spatial', ['ng-mapasculturais']);
3    app.controller('SearchSpatialController', ['$window', '$scope', '$location', "$rootScope", "$timeout", function($window, $scope, $location, $rootScope, $timeout) {
4
5        var map = null;
6        if($scope.data.global.locationFilters.address.text != "")
7            filterAddress();
8
9        var labels = MapasCulturais.gettext.controllerSpatial;
10
11        angular.element(document).ready(function() {
12            map = $window.leaflet.map;
13            if(!map) return;
14            map.invalidateSize();
15            var drawnItems = new L.FeatureGroup();
16            map.addLayer(drawnItems);
17            $window.leaflet.map.drawnItems = drawnItems;
18
19
20            if($scope.data.global.locationFilters.enabled){
21                var lf = $scope.data.global.locationFilters;
22                (new L.Circle(
23                    new L.LatLng(lf[lf.enabled].center.lat, lf[lf.enabled].center.lng),
24                    lf[lf.enabled].radius,
25                    {className : 'vetorial-padrao'}
26                ).addTo(map.drawnItems));
27
28                if($scope.data.global.locationFilters.enabled == 'address'){
29                    filterAddress ();
30                }
31            }
32
33
34            L.drawLocal.draw.handlers.circle.tooltip.start = labels['tooltip.start'];
35            L.drawLocal.draw.handlers.circle.tooltip.end = labels['tooltip.end'];
36            L.drawLocal.draw.toolbar.actions.title = labels['title'];
37            L.drawLocal.draw.toolbar.actions.text = labels['text'];
38            L.drawLocal.draw.toolbar.buttons.circle = labels['circle'];
39
40            L.Draw.Circle = L.Draw.Circle.extend({
41                _onMouseMove: function(e) {
42                    var latlng = e.latlng,
43                        showRadius = this.options.showRadius,
44                        useMetric = this.options.metric,
45                        radius;
46
47                    this._tooltip.updatePosition(latlng);
48                    if (this._isDrawing) {
49                        this._drawShape(latlng);
50
51                        // Get the new radius (rounded to 1 dp)
52                        radius = this._shape.getRadius().toFixed(1);
53
54                        this._tooltip.updateContent({
55                            text: L.drawLocal.draw.handlers.circle.tooltip.end,
56                            subtext: showRadius ? labels['radius'] + ': ' + L.GeometryUtil.readableDistance(radius, useMetric).replace('.',',') : ''
57                        });
58                    }
59                }
60            });
61
62            var drawControl = new L.Control.Draw({
63                draw: {
64                    position: 'topleft',
65                    polygon: false,
66                    rectangle: false,
67                    marker: false,
68                    polyline: false,
69                    circle: {
70                        shapeOptions: {
71                            className : 'vetorial-padrao'
72                        }
73                    }
74                },
75                edit: false,
76            });
77            map.addControl(drawControl);
78
79            map.on('draw:created', function(e) {
80                var type = e.layerType,
81                    layer = e.layer;
82
83                if (type === 'circle') {
84                    $scope.data.global.locationFilters = {
85                        enabled : 'circle',
86                        circle : {
87                            center : {
88                                lat: layer._latlng.lat,
89                                lng: layer._latlng.lng
90                            },
91                            radius: parseInt(layer._mRadius),
92                        }
93                    };
94                    $scope.$apply();
95                }
96
97
98                if (type === 'marker') {
99                    layer.bindPopup('A popup!');
100                }
101
102                if($window.leaflet.locationMarker) $window.leaflet.map.removeLayer($window.leaflet.locationMarker);
103                drawnItems.addLayer(layer);
104
105                //ESCONDE O CONTROLE PARA POSTERIORMENTE USAR O BOTÃO (NÃO CONSEGUI SETAR OS EVENTOS DO DRAW CIRCLE SEM ESTE CONTROLE
106                //document.querySelector('.leaflet-draw-draw-circle').style.display = 'none';
107
108            });
109
110
111            //ESCONDE O CONTROLE PARA POSTERIORMENTE USAR O BOTÃO (NÃO CONSEGUI SETAR OS EVENTOS DO DRAW CIRCLE SEM ESTE CONTROLE
112//            document.querySelector('.leaflet-draw-draw-circle').style.display = 'none';
113
114
115            map.on('locationfound', function(e) {
116                $window.$timout.cancel($window.dataTimeout);
117                var radius = e.accuracy / 2,
118                    neighborhoodRadius = $scope.defaultLocationRadius;
119
120                var currentLocationLabel = labels['currentLocation'];
121                currentLocationLabel.replace('{{errorMargin}}', radius.toString().replace('.',','));
122                currentLocationLabel.replace('{{radius}}', neighborhoodRadius/1000);
123
124                var marker = L.marker(e.latlng, $window.leaflet.iconOptions['location']).addTo(map)
125                    .bindPopup(currentLocationLabel)
126                    .openPopup();
127
128                var circle = L.circle(e.latlng, $scope.defaultLocationRadius, {className : 'vetorial-padrao'}).addTo(map.drawnItems);
129
130
131                $scope.data.global.locationFilters = {
132                    enabled : 'neighborhood',
133                    neighborhood : {
134                        center : {
135                            lat: map.getCenter().lat,
136                            lng: map.getCenter().lng
137                        },
138                        radius : $scope.defaultLocationRadius
139                    }
140                };
141                $scope.$apply();
142
143                if($window.leaflet.locationMarker) {
144                    $window.leaflet.map.removeLayer($window.leaflet.locationMarker);
145                    $window.leaflet.map.removeLayer($window.leaflet.locationCircle);
146                }
147                $window.leaflet.locationMarker = marker;
148                $window.leaflet.locationCircle = circle;
149
150            });
151
152            map.on('locationerror', function(e) {
153                /* @TODO alert de erro para o usuário */
154            });
155
156            //to fix address field not getting focus on touch screens
157            $('#endereco').on('click dblclick', function(e){
158                var $self = $(this);
159                $self.focus();
160                e.stopPropagation();
161                //loose focus on click outslide
162                $('body').one('click', function(event){
163                    if($self.parent().find(event.target).length == 0){
164                        $self.blur();
165                    }
166                });
167            });
168
169        });
170
171
172        $scope.filterNeighborhood = function (){
173            $window.leaflet.map.locate({setView : true, maxZoom:13});
174        };
175
176
177        function filterAddress () {
178            var addressString = $scope.data.global.locationFilters.address.text;
179
180            MapasCulturais.geocoder.geocode({'fullAddress': addressString}, function(results) {
181                if (results) {
182                    $window.$timout.cancel($window.dataTimeout);
183                    var foundLocation = new L.latLng(results.lat, results.lon);
184
185                    $window.leaflet.map.setView(foundLocation, 13);
186
187                    if($window.leaflet.locationMarker) {
188                        $window.leaflet.map.removeLayer($window.leaflet.locationMarker);
189                        $window.leaflet.map.removeLayer($window.leaflet.locationCircle);
190                    }
191                    $window.leaflet.locationMarker = new L.marker(foundLocation, $window.leaflet.iconOptions['location']).addTo($window.leaflet.map);
192                    $window.leaflet.locationCircle = L.circle(foundLocation, $scope.defaultLocationRadius, {className : 'vetorial-padrao'})
193                            .addTo($window.leaflet.map.drawnItems);
194
195                    $scope.data.global.locationFilters = {
196                        enabled : 'address',
197                        address : {
198                            text : $scope.data.global.locationFilters.address.text,
199                            center : {
200                                lat: results.lat,
201                                lng: results.lon
202                            },
203                            radius : $scope.defaultLocationRadius
204                        }
205                    };
206                    $scope.$apply();
207                }
208            });
209        };
210
211        $scope.$watch('data.global.locationFilters.address.text', function(newValue, oldValue){
212            if(!newValue && !oldValue || newValue == oldValue){
213                return;
214            }
215            //if(newValue === '' || newValue === oldValue) return;
216            if(!newValue || !newValue.trim()) {
217                $scope.data.global.locationFilters.enabled = null;
218                if($rootScope.resultLayer.getBounds()._northEast)
219                    map.fitBounds($rootScope.resultLayer.getBounds());
220                return;
221            }
222            $timeout.cancel($scope.timer2);
223            $scope.timer2 = $timeout(function() {
224                filterAddress();
225            }, 1000);
226        });
227
228    }]);
229})(angular);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.