switch search plugin, result-dependent zoom
This commit is contained in:
parent
b808fbe44e
commit
9aa6ede63c
4 changed files with 53 additions and 30 deletions
11
js/index.js
11
js/index.js
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
var topo = L.tileLayer('http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
|
||||
minZoom: 5,
|
||||
maxZoom: 15,
|
||||
maxZoom: 16,
|
||||
attribution: 'tiles © <a target="_blank" href="https://opentopomap.org">OpenTopoMap</a>, <a target="_blank" href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>'
|
||||
+ ', <a target="_blank" href="http://viewfinderpanoramas.org">SRTM</a>'
|
||||
});
|
||||
|
|
@ -90,15 +90,14 @@
|
|||
'Hiking (Waymarked Trails)': hiking
|
||||
}).addTo(map);
|
||||
|
||||
map.addControl(new BR.Search());
|
||||
|
||||
// expose map instance for console debugging
|
||||
BR.debug = BR.debug || {};
|
||||
BR.debug.map = map;
|
||||
}
|
||||
|
||||
function initApp() {
|
||||
var router,
|
||||
var search,
|
||||
router,
|
||||
routing,
|
||||
routesLayer,
|
||||
routingOptions,
|
||||
|
|
@ -114,6 +113,9 @@
|
|||
// left sidebar as additional control position
|
||||
map._controlCorners[leftPaneId] = L.DomUtil.create('div', 'leaflet-' + leftPaneId, map._controlContainer);
|
||||
|
||||
search = new BR.Search();
|
||||
map.addControl(search);
|
||||
|
||||
router = L.bRouter(); //brouterCgi dummyRouter
|
||||
|
||||
function updateRoute(evt) {
|
||||
|
|
@ -197,6 +199,7 @@
|
|||
}
|
||||
});
|
||||
routing.on('routing:routeWaypointEnd routing:setWaypointsEnd', function(evt) {
|
||||
search.clear();
|
||||
onUpdate(evt && evt.err);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,38 @@
|
|||
BR.Search = L.Control.Search.extend({
|
||||
BR.Search = L.Control.Geocoder.extend({
|
||||
options: {
|
||||
//url: 'http://nominatim.openstreetmap.org/search?format=json&q={s}',
|
||||
url: 'http://open.mapquestapi.com/nominatim/v1/search.php?format=json&q={s}',
|
||||
jsonpParam: 'json_callback',
|
||||
propertyName: 'display_name',
|
||||
propertyLoc: ['lat','lon'],
|
||||
markerLocation: false,
|
||||
circleLocation: false,
|
||||
autoType: false,
|
||||
autoCollapse: true,
|
||||
minLength: 2,
|
||||
zoom: 12
|
||||
geocoder: new L.Control.Geocoder.Nominatim({
|
||||
serviceUrl: 'https://open.mapquestapi.com/nominatim/v1/'
|
||||
}),
|
||||
position: 'topleft'
|
||||
},
|
||||
|
||||
// patch: interferes with draw plugin (adds all layers twice to map?)
|
||||
_onLayerAddRemove: function() {}
|
||||
|
||||
onAdd: function (map) {
|
||||
map.attributionControl.addAttribution('Nominatim Search Courtesy of '
|
||||
+ '<a href="http://www.mapquest.com/" target="_blank">MapQuest</a>'
|
||||
+ ' <img src="http://developer.mapquest.com/content/osm/mq_logo.png">');
|
||||
|
||||
return L.Control.Geocoder.prototype.onAdd.call(this, map);
|
||||
},
|
||||
|
||||
markGeocode: function(result) {
|
||||
this._map.fitBounds(result.bbox, {
|
||||
maxZoom: 17
|
||||
});
|
||||
|
||||
this.clear();
|
||||
this._geocodeMarker = new L.CircleMarker(result.center, {
|
||||
clickable: false,
|
||||
color: 'red',
|
||||
opacity: 1,
|
||||
weight: 3
|
||||
}).addTo(this._map);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
if (this._geocodeMarker) {
|
||||
this._map.removeLayer(this._geocodeMarker);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue