PageSourceSearch

https://pod.rs.gov.br/matriz_common/versions/2.1.5/themes/frontend/js/mapa.js?2.1.5.161.7+2

js pod.rs.gov.br collected 2026-10-07 20:30:49 UTC 11,966 bytes, 250 lines download raw bytes

1jQuery(function ($) {
2    window.article = window.article || {};
3    window.article.locais = window.article.locais || {};
4    window.article.locais.mapa = {
5        init: function (options) {
6            options = options || {};
7            
8            var selector = options.selector || ".mapa";
9            
10//            debugger;
11            $(selector).each(function () {
12                //recupera o id o item
13                var id = $(this).attr("id");
14                var zoomMax = $(this).attr("data-zoommax");
15                var locais = eval($(this).find(".mapa-locaisdata").val());
16
17                var map = new google.maps.Map(document.getElementById(id + "Visualizacao"), obtemOpcoesMapa());
18                google.maps.event.addListenerOnce(map, 'idle', function () {
19                    if (window.location.hash.has("local-")) {
20                        var $spanLocal = $(window.location.hash);
21                        apontarLocal($spanLocal.attr("data-matriz-indice"), $spanLocal.attr("data-matriz-id"));
22                    }
23                });
24
25                var infoWindow = new google.maps.InfoWindow({});
26                var arrayLatLngs = new Array();
27                var arrayMarkers = new Array();
28
29                //percorre todos os locais do conteúdo analisando o tipo de
30                //objeto a ser criado pelo número de pontos que o mesmo usa
31                for (var a in locais) {
32                    var local = locais[a];
33                    var arrayPath = obtemArrayPath(local.txtLatLng, arrayLatLngs);
34                    switch (arrayPath.length) {
35                        case 1:
36                            adicionaMarker(arrayPath[0], local, map, arrayMarkers);
37                            break;
38                        case 2:
39                        default:
40                            adicionaPolygon(arrayPath, local, map, arrayMarkers);
41                            break;
42                    }
43                }
44
45                //enquadramento do mapa para visualização de todos seus pontos
46                centralizaMapa(map, arrayLatLngs);
47
48                //ao alterar a combo de locais, o mapa foca no local selecionado
49                //se o ponto estiver representando um polygon os limites deste
50                //estarão na propriedade bounds do marker sendo utilizado para
51                //ajustar o mapa senão utiliza o position do marker.
52                $("#" + id + "Select").selectpicker("refresh");
53                $("#" + id + "Select").change(function () {
54                    var indice = $(this).val();
55                    if (indice > 0) {
56                        trocarLocal("#local-".concat(indice));
57                    } else {
58                        centralizaMapa(map, arrayLatLngs);
59                    }
60                });
61
62                function trocarLocal(hash) {
63                    location.hash = hash;
64                    var $spanLocal = $(hash);
65                    apontarLocal($spanLocal.attr("data-matriz-indice"), $spanLocal.attr("data-matriz-id"));
66                }
67
68                function apontarLocal(indice, valor) {
69                    if (valor > 0) {
70                        for (var a in arrayMarkers) {
71                            var marker = arrayMarkers[a];
72                            var local = marker.get('local');
73                            if (local.codLocal == valor) {
74                                var bounds = marker.get('bounds');
75                                if (typeof (bounds) != "undefined") {
76                                    map.fitBounds(bounds);
77                                } else {
78                                    var arrayPath = new Array();
79                                    arrayPath.push(marker.position);
80                                    centralizaMapa(map, arrayPath);
81                                }
82                                map.setZoom(parseInt(zoomMax));
83                                //seleciona o item no combo
84                                $("#" + id + "Select").selectpicker("val", indice);
85                            }
86                        }
87                    } else {
88                        centralizaMapa(map, arrayLatLngs);
89                    }
90                }
91
92                //retorna um array de pontos vindos em string
93                function obtemArray(pontos, quebra) {
94                    pontos = pontos.replace(" ", "");
95
96                    if (pontos.substr(0, 1) == "(")
97                        pontos = pontos.substr(1, pontos.length);
98
99                    if (pontos.substr(pontos.length - 1, 1) == ")")
100                        pontos = pontos.substr(0, pontos.length - 1);
101
102                    return pontos.split(quebra);
103                }
104
105                //retorna um array de LatLng dos pontos passados
106                //o arrayLatLngs apenas acumula os pontos para posterior
107                //centralização do mapa (enquadrar todos seus markers)
108                function obtemArrayPath(pontos, arrayLatLngs) {
109                    var arrayPontos = obtemArray(pontos, "),(");
110                    var arrayPath = new Array();
111                    for (var a in arrayPontos) {
112                        var ponto = arrayPontos[a];
113                        var arrayPonto = obtemArray(ponto, ",");
114                        var latitude = arrayPonto[0];
115                        var longitude = arrayPonto[1];
116                        var latLng = new google.maps.LatLng(latitude, longitude);
117                        arrayPath.push(latLng);
118                        arrayLatLngs.push(latLng);
119                    }
120                    return arrayPath;
121                }
122
123                //adiciona um Marker ao mapa através do latLng passado
124                function adicionaMarker(latLng, local, map, arrayMarkers, bounds) {
125                    var marker = new google.maps.Marker({
126                        position: latLng,
127                        title: local.txtNome + " - " + matriz.utils.internationalization.translate("Clique para detalhes", "mapa") + ".",
128                        icon: local.icone,
129                        map: map
130                    });
131
132                    //cada marker é associado ao local para que quando o
133                    //local for clicado sejam apresentadas suas informações
134                    //no infowindow que é único no mapa.
135                    marker.set('local', local);
136
137                    //um marker pode estar sendo desenhado no meio de um polygon
138                    //apenas para representar seu ponto central e clicável para o
139                    //usuário poder visualizar mais ifnromações pelo infowindow.
140                    //Por isso, optou-se por informar os limites do polygon que
141                    //este marker está representando para posterior ajuste de
142                    //zoom quando o usuário alterar os locais pela combo.
143                    if (typeof (bounds) != "undefined")
144                        marker.set('bounds', bounds);
145
146                    //adiciona o marker ao array para poder percorrer
147                    //todos os markers a procura do marker informado
148                    //pelo usuário na combo de locais.
149                    arrayMarkers.push(marker);
150
151                    //evento de clique no local para exibir infoWindows
152                    google.maps.event.addListener(marker, "click", function (event) {
153                        var local = this.get('local');
154
155                        var content = '<div style="line-height:1.35; overflow:hidden; white-space:nowrap;">';
156                        content += "<strong>" + local.txtNome + "</strong>";
157
158                        if (local.txtLogradouro.length > 0)
159                        {
160                            content += "<br/>" + local.txtLogradouro + ".";
161                        }
162
163                        if (local.txtCEP.length > 0)
164                            content += "<br/>CEP: " + local.txtCEP + ".";
165
166                        content += '</div>';
167
168                        infoWindow.setContent(content);
169                        infoWindow.open(map, this);
170                    });
171                }
172
173                //adiciona um Polygon com os LatLngs passados dentro do arrayPath
174                function adicionaPolygon(arrayPath, local, map, arrayMarkers) {
175                    var polygon = new google.maps.Polygon({
176                        path: arrayPath,
177                        strokeColor: "#000000",
178                        strokeOpacity: 1.0,
179                        strokeWeight: 2,
180                        map: map
181                    });
182
183                    //calcula o ponto central do polygon
184                    var bounds = new google.maps.LatLngBounds();
185                    for (var a in arrayPath) {
186                        var latLng = arrayPath[a];
187                        bounds.extend(latLng);
188                    }
189
190                    //adiciona um marker no ponto central do polygon
191                    var ponto = bounds.getCenter().toString();
192                    var arrayPathPonto = obtemArrayPath(ponto, new Array());
193                    adicionaMarker(arrayPathPonto[0], local, map, arrayMarkers, bounds);
194                }
195
196                //retorna opções padrão para o mapa (ponto inicial: Rio Grande do Sul)
197                function obtemOpcoesMapa() {
198                    var latLng = new google.maps.LatLng(-30.0277041, -51.2287346);
199                    var opcoesMapa = {
200                        center: latLng,
201                        mapTypeId: google.maps.MapTypeId.ROADMAP,
202                        maxZoom: zoomMax
203                    };
204                    return opcoesMapa;
205                }
206
207                //calcula através de todos markers contidos no mapa
208                //o enquadradamento para exibição de todos os locais
209                function centralizaMapa(map, arrayLatLngs) {
210                    var bounds = new google.maps.LatLngBounds();
211                    if (arrayLatLngs.length === 1) {
212                        map.setCenter(arrayLatLngs[0]);
213                        map.setZoom(15);
214                        return;
215                    }
216                    for (var a in arrayLatLngs) {
217                        var latLng = arrayLatLngs[a];
218                        bounds.extend(latLng);
219                    }
220                    map.fitBounds(bounds);
221                }
222
223                $("#" + id.replace("mapa", "mapaLista")).find(".list-group-item .mapa-lista__item__titulo a").each(function () {
224                    $(this).click(function (event) {
225                        event.preventDefault();
226                        trocarLocal($(this).attr("href"));
227                    });
228                });
229                
230                $(".mapa-lista__item__link > a").each(function() {
231                    var arrayLatLngs = obtemArrayPath($(this).attr("data-matriz-pontos"), new Array());
232                    
233                    if (arrayLatLngs.length > 1) {
234                        var bounds = new google.maps.LatLngBounds();
235                        
236                        for (var key in arrayLatLngs) {
237                            bounds.extend(arrayLatLngs[key]);
238                        }
239                        
240                        $(this).attr("href", "https://www.google.com.br/maps/place/".concat(bounds.getCenter().toString()));
241                    }
242                });
243            });
244        }
245    };
246    if (typeof matriz.externalapis !== "undefined") {
247        matriz.externalapis.google.maps.load();
248        matriz.common.events.on("matriz.externalapis.google.maps.ready", article.locais.mapa.init);
249    }
250});

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.