Subversion Repositories eFlore/Applications.cel

Rev

Rev 3849 | Rev 3867 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3849 Rev 3866
Line 67... Line 67...
67
};
67
};
Line 68... Line 68...
68
 
68
 
69
TbPlaces.prototype.launchSearch = function () {
69
TbPlaces.prototype.launchSearch = function () {
70
    if (!!this.places.val()) {
70
    if (!!this.places.val()) {
-
 
71
        const url = NOMINATIM_OSM_URL+'search',
71
        const url = NOMINATIM_OSM_URL+'search',
72
            params = {
-
 
73
                'q': this.places.val(),
-
 
74
                'format': 'json',
-
 
75
                'polygon_geojson': 1,
-
 
76
                'zoom': 17
Line 72... Line 77...
72
            params = {'q':  this.places.val()};
77
            };
73
 
78
 
74
        this.placeLabel.addClass('loading');
79
        this.placeLabel.addClass('loading');
75
        $.ajax({
80
        $.ajax({
Line 115... Line 120...
115
                    '</li>'
120
                    '</li>'
116
                );
121
                );
117
            }
122
            }
118
        }
123
        }
119
    });
124
    });
-
 
125
    if(0 < acceptedSuggestions.length) {
120
    this.placesResultsContainer.removeClass('hidden');
126
        this.placesResultsContainer.removeClass('hidden');
-
 
127
    } else {
-
 
128
        this.resetPlacesSearch();
-
 
129
    }
121
};
130
};
Line 122... Line 131...
122
 
131
 
123
TbPlaces.prototype.validateSuggestionData = function(suggestion) {
132
TbPlaces.prototype.validateSuggestionData = function(suggestion) {
-
 
133
    const validGeometry = undefined !== suggestion.lat && undefined !== suggestion.lon,
-
 
134
        typeLocalisation = this.places.data('typeLocalisation') || '',
124
    const validGeometry = undefined !== suggestion.lat && undefined !== suggestion.lon,
135
        validGeometryType = 'rue' === typeLocalisation ? 'LineString' === suggestion?.geojson.type : true,
125
        validAddressData = undefined !== suggestion.address,
136
        validAddressData = undefined !== suggestion.address,
Line 126... Line 137...
126
        validDisplayName = undefined !== suggestion['display_name'];
137
        validDisplayName = undefined !== suggestion['display_name'];
127
 
138
 
Line 128... Line 139...
128
    return (validGeometry && validAddressData && validDisplayName);
139
    return (validGeometry && validGeometryType && validAddressData && validDisplayName);
129
};
140
};
Line 136... Line 147...
136
            suggestion = lthis.searchResults.find(suggestion => suggestion['place_id'] === $thisSuggestion.data('placeId'));
147
            suggestion = lthis.searchResults.find(suggestion => suggestion['place_id'] === $thisSuggestion.data('placeId'));
Line 137... Line 148...
137
 
148
 
Line 138... Line 149...
138
        evt.preventDefault();
149
        evt.preventDefault();
-
 
150
 
-
 
151
        lthis.places.val($thisSuggestion.text());
139
 
152
 
140
        lthis.places.val($thisSuggestion.text());
153
        suggestion.geojson.coordinates = lthis.formatCoordinatesArray(suggestion.geojson);
Line 141... Line 154...
141
        lthis.clientCallback(suggestion);
154
        lthis.clientCallback(suggestion);
142
        lthis.placesCloseButton.trigger('click');
155
        lthis.placesCloseButton.trigger('click');
Line 161... Line 174...
161
            lthis.places.focus();
174
            lthis.places.focus();
162
        }
175
        }
163
    });
176
    });
164
};
177
};
Line -... Line 178...
-
 
178
 
-
 
179
TbPlaces.prototype.formatCoordinatesArray = function(geojson) {
-
 
180
    const coordinatesArray = geojson.coordinates,
-
 
181
        geojsonType = geojson.type,
-
 
182
        coordinatesArrayLength = coordinatesArray.length;
-
 
183
 
-
 
184
    if ('Point' === geojsonType) {
-
 
185
        coordinatesArray.reverse();
-
 
186
    } else if (0 > coordinatesArrayLength) {
-
 
187
        for (let i = 0; i <= coordinatesArrayLength; i++) {
-
 
188
            coordinatesArray[i].reverse();
-
 
189
        }
-
 
190
    }
-
 
191
 
-
 
192
    return coordinatesArray;
-
 
193
}
165
 
194
 
166
TbPlaces.prototype.resetOnClick = function () {
195
TbPlaces.prototype.resetOnClick = function () {
Line 167... Line 196...
167
    const lthis = this;
196
    const lthis = this;
168
 
197
 
Line 180... Line 209...
180
TbPlaces.prototype.handleSearchError = function() {
209
TbPlaces.prototype.handleSearchError = function() {
181
    this.resetPlacesSearch();
210
    this.resetPlacesSearch();
182
    if (0 === $('#tb-places-error').length) {
211
    if (0 === $('#tb-places-error').length) {
183
        this.places.closest('#tb-places-zone').after(
212
        this.places.closest('#tb-places-zone').after(
184
            `<span id="tb-places-error" class="error mb-3 mt-3">
213
            `<span id="tb-places-error" class="error mb-3 mt-3">
185
                Votre recherche n’a rien donné.<br>veuillez modifier votre recherche ou rechercher votre station directement sur la carte.
214
                Votre recherche n’a pas donné de résultat pour le moment.<br>Vous pouvez soit poursuivre ou modifier votre recherche,<br>soit rechercher votre station directement sur la carte.
186
            </span>`
215
            </span>`
187
        );
216
        );
188
        setTimeout(function() {
217
        setTimeout(function() {
189
            $('#tb-places-error').remove();
218
            $('#tb-places-error').remove();
190
        }, 5000);
219
        }, 10000);
191
    }
220
    }
192
};
221
};
Line 193... Line 222...
193
 
222
 
194
TbPlaces.prototype.resetPlacesSearch = function() {
223
TbPlaces.prototype.resetPlacesSearch = function() {