Skip to content

Commit

Permalink
Makes leaflet search globally configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
yefim committed Jun 1, 2015
1 parent 6ecad92 commit 822dd85
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
46 changes: 24 additions & 22 deletions flask_admin/static/admin/js/form-1.0.0.js
Expand Up @@ -168,32 +168,34 @@
return true;
}

var geocoder = new google.maps.Geocoder();
if (window.google) {
var geocoder = new google.maps.Geocoder();

function googleGeocoding(text, callResponse) {
geocoder.geocode({address: text}, callResponse);
}
function googleGeocoding(text, callResponse) {
geocoder.geocode({address: text}, callResponse);
}

function filterJSONCall(rawjson) {
var json = {}, key, loc, disp = [];
for (var i in rawjson) {
key = rawjson[i].formatted_address;
loc = L.latLng(rawjson[i].geometry.location.lat(),
rawjson[i].geometry.location.lng());
json[key] = loc;
function filterJSONCall(rawjson) {
var json = {}, key, loc, disp = [];
for (var i in rawjson) {
key = rawjson[i].formatted_address;
loc = L.latLng(rawjson[i].geometry.location.lat(),
rawjson[i].geometry.location.lng());
json[key] = loc;
}
return json;
}
return json;
}

map.addControl(new L.Control.Search({
callData: googleGeocoding,
filterJSON: filterJSONCall,
markerLocation: true,
autoType: false,
autoCollapse: true,
minLength: 2,
zoom: 10
}));
map.addControl(new L.Control.Search({
callData: googleGeocoding,
filterJSON: filterJSONCall,
markerLocation: true,
autoType: false,
autoCollapse: true,
minLength: 2,
zoom: 10
}));
}

// set up Leaflet.draw editor
var drawOptions = {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion flask_admin/static/vendor/leaflet/leaflet.search.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion flask_admin/templates/bootstrap2/admin/lib.html
Expand Up @@ -177,8 +177,10 @@ <h3>{{ text }}</h3>
{% if config.MAPBOX_MAP_ID %}
<link href="{{ admin_static.url(filename='vendor/leaflet/leaflet.css') }}" rel="stylesheet">
<link href="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.css') }}" rel="stylesheet">
{% if config.MAPBOX_SEARCH %}
<link href="{{ admin_static.url(filename='vendor/leaflet/leaflet.search.css') }}" rel="stylesheet">
{% endif %}
{% endif %}
{% if editable_columns %}
<link href="{{ admin_static.url(filename='vendor/x-editable/css/bootstrap2-editable-1.5.1.css') }}" rel="stylesheet">
{% endif %}
Expand All @@ -192,11 +194,13 @@ <h3>{{ text }}</h3>
window.MAPBOX_ACCESS_TOKEN = "{{ config.MAPBOX_ACCESS_TOKEN }}";
{% endif %}
</script>
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.js') }}"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.draw.js') }}"></script>
{% if config.MAPBOX_SEARCH %}
<script src="https://maps.googleapis.com/maps/api/js?v=3&sensor=false"></script>
<script src="{{ admin_static.url(filename='vendor/leaflet/leaflet.search.js') }}"></script>
{% endif %}
{% endif %}
<script src="{{ admin_static.url(filename='vendor/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
{% if editable_columns %}
<script src="{{ admin_static.url(filename='vendor/x-editable/js/bootstrap2-editable-1.5.1.min.js') }}"></script>
Expand Down

0 comments on commit 822dd85

Please sign in to comment.