PageSourceSearch

https://placealacte.fr/js/carto.js

js placealacte.fr collected 2026-10-07 20:00:30 UTC 6,830 bytes, 203 lines download raw bytes

1 jQuery(document).ready(function($){
2    var map_center = [46.4,2.51]
3    var map = L.map('carte').setView(map_center,5)
4    var poiMarkers = null
5    var details = $('#details_carte')
6    var auto_geo_options = {
7      enableHighAccuracy: true,
8      timeout: 5000,
9      maximumAge: 0
10    };
11
12    function getMapBounds() {
13        var bounds = map.getBounds()
14        return [bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()]
15    }
16
17    function project_contact_form() {
18        var clicked = $(this)
19        var id = clicked.data('id')
20        window.location.href = "/contact?projet=" + id
21    }
22
23    function project_visit_web_site() {
24        var clicked = $(this)
25        var url = clicked.data('url')
26        if (url && url.length > 1) {
27            window.open(url)
28        }
29    }
30
31    function lien_fiche() {
32        var clicked = $(this)
33        var url = clicked.data('url')
34        if (url && url.length > 1) {
35            window.open(url)
36        }
37    }
38
39    function show_poi_details(id) {
40
41        var data = null
42        var lt = "";
43
44        details.empty()
45        $.each(poiMarkers.getLayers(), function(i,e) {
46            if (e.options && e.options.linked_data && e.options.linked_data.id == id) {
47                data = e.options.linked_data
48            }
49        })
50
51        // console.log("cliqué : " + id)
52        // console.log(data);
53        if (data !== null) {
54            var title = $('<h3>').addClass('title').text(data.name)
55            var address = $('<div>').addClass('address').text(data.zip + ' '+ data.town)
56            var contact = ''
57            if (data.email_len > 0) {
58                contact = $('<button>').attr('type','button').addClass('button contact')
59                          .attr('data-id',id)
60                          .text('Contacter le porteur de projet')
61            } else if (data.site_len > 1) {
62                contact = $('<button>').attr('type','button').addClass('button site')
63                          .attr('data-url',data.web_site)
64                          .text('Visiter le site web')
65            }
66
67            // lien vers la fiche
68            // cat "aider-des-initiatives" + type
69            if (data.type = 1290281158) {
70                lt = "initiatives";
71            } else if (data.type = 1) {
72                lt = "idees";
73            }
74            if (lt != "")
75            {
76                var titreurl = data.name.replace(/ /g,"-");
77                titreurl = titreurl.replace(/[^a-z0-9-]/ig,'');
78                var lienfiche = "/aider-des-initiatives/" + encodeURIComponent(titreurl + "." + id + "." + lt + ".html");
79
80                lienfiche = $('<button>').attr('type','button').addClass('button lienfiche')
81                          .attr('data-url',lienfiche)
82                          .text('Voir la fiche')
83            }
84
85           
86            var descr = $('<div>').addClass('descr').html(data.descr)
87            details.append(title)
88            details.append(lienfiche)
89            details.append(address)
90            details.append(contact)
91            details.append(descr)
92            
93        } 
94
95    }
96
97    function marker_click_listener() {
98        var clicked = this
99        show_poi_details(clicked.options.linked_data.id)
100    }
101    
102    function add_n_replace_POI_Markers_With(json_elts, callback) {
103        if (poiMarkers != null) map.removeLayer(poiMarkers)
104        poiMarkers = null
105        var markers = []
106        $.each(json_elts,function(i,e) {
107                    //descr (html), id, lat,lng, name, type zip, town
108            var marker = L.marker([e.lat,e.lng], 
109                                   {linked_data: e}
110                                 )
111
112            try {
113                var poi_data = $('<div>')
114
115                poi_data.append($('<h3>').addClass('ptitle').attr('data-id', e.id).text(e.name))
116                poi_data.append($('<p>').text(e.zip + ' '+ e.town))
117                marker.bindPopup(poi_data.html())
118                marker.on('click', marker_click_listener)
119            } catch (err) {
120                console.log(err)
121            }
122            markers.push(marker)
123        })
124        if (markers.length > 0) {
125            poiMarkers = L.markerClusterGroup({maxClusterRadius: 1});
126            poiMarkers.addLayer(L.featureGroup(markers))
127            
128            poiMarkers.addTo(map)
129        }
130    }
131    function get_and_display_POI() {
132        $.ajax({
133                url : '/poi',
134                dataType: "json",
135                data : {mapWSEN : getMapBounds()}
136                
137        })
138        .done(function(response){
139            if (typeof (response.results) != "undefined" && response.results.length > 0) {
140                add_n_replace_POI_Markers_With(response.results, function() {
141                    // markers have ben displayed
142                })
143            } else {
144                console.log(response);
145            }
146            
147        })
148    } 
149    
150    function auto_geo_success(pos) {
151      var crd = pos.coords
152      //crd.accuracy
153      map_center = [crd.latitude,crd.longitude]
154      map.setView(map_center,9)
155      
156    }
157
158    function auto_geo_error(err) {
159      console.warn(`ERREUR (${err.code}): ${err.message}`);
160    }
161
162    try {
163        navigator.geolocation.getCurrentPosition(auto_geo_success, auto_geo_error, auto_geo_options);
164    } catch(err) {
165        //not so important. Visitor can enter a postal adress (or just a town)
166    }
167   
168      const key = 'SMdvlAKMa89V5pAKvgDq';
169      const mtLayer = L.maptilerLayer({
170        apiKey: key,
171        id: 'mapbox.streets',
172        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
173        style: "basic-v2", //optional
174      }).addTo(map);
175    
176    
177       L.tileLayer("" ,{
178        maxZoom: 18,
179    }).addTo(map);
180 
181    L.control.scale({imperial: false}).addTo(map);
182
183    map.on('zoomend dragend', function() {
184        get_and_display_POI()
185    })
186
187    $('#carte').on('click', '.ptitle', function() {
188        var clicked = $(this)
189        var id = clicked.data('id')
190        show_poi_details(id)
191    })
192    $('#address_search').addGeolocAutocomplete($('#address_lat'),$('#address_lng'), $('#address'),$('#city'),$('#zip'));
193    $('#address').on("new_selection", function() {
194        map_center = [$('#address_lat').val(),$('#address_lng').val()]
195        var zoom = map.getZoom()  
196        map.setView(map_center,9) 
197        if (zoom == 9) get_and_display_POI() // because no zoom event here
198
199    })
200    details.on('click','.button.contact',project_contact_form)
201    details.on('click','.button.site',project_visit_web_site)
202    details.on('click','.button.lienfiche',lien_fiche)
203 })

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.