switch search plugin, result-dependent zoom
This commit is contained in:
parent
b808fbe44e
commit
9aa6ede63c
4 changed files with 53 additions and 30 deletions
|
|
@ -88,8 +88,8 @@ Copyright (c) 2013 Felix Bache; [MIT License](https://github.com/MrMufflon/Leafl
|
|||
Copyright (c) 2013, Michael Bostock. All rights reserved.; [3-clause BSD License](https://github.com/mbostock/d3/blob/master/LICENSE)
|
||||
* [Leaflet.draw](https://github.com/Leaflet/Leaflet.draw)
|
||||
Copyright 2012 Jacob Toye; [MIT License](https://github.com/Leaflet/Leaflet.draw/blob/master/MIT-LICENCE.txt)
|
||||
* [Leaflet.Control.Search](https://github.com/stefanocudini/leaflet-search)
|
||||
Copyright (c) 2013 Stefano Cudini; [MIT License](https://github.com/stefanocudini/leaflet-search/blob/master/LICENSE.txt)
|
||||
* [Leaflet Control Geocoder](https://github.com/perliedman/leaflet-control-geocoder)
|
||||
Copyright (c) 2012 [sa3m](https://github.com/sa3m), Copyright (c) 2013 Per Liedman; [2-clause BSD License](https://github.com/perliedman/leaflet-control-geocoder/blob/master/LICENSE)
|
||||
* [leaflet-plugins](https://github.com/shramov/leaflet-plugins)
|
||||
Copyright (c) 2011-2012, Pavel Shramov; [2-clause BSD License](https://github.com/shramov/leaflet-plugins/blob/master/LICENSE)
|
||||
* [Async.js](https://github.com/caolan/async)
|
||||
|
|
|
|||
18
bower.json
18
bower.json
|
|
@ -8,7 +8,6 @@
|
|||
],
|
||||
"dependencies": {
|
||||
"leaflet": "~0.7.3",
|
||||
"leaflet-search": "*",
|
||||
"leaflet-plugins": "~1.3.2",
|
||||
"leaflet-routing": "Turistforeningen/leaflet-routing#gh-pages",
|
||||
"async": "~0.9.2",
|
||||
|
|
@ -16,7 +15,8 @@
|
|||
"leaflet.draw": "~0.2.3",
|
||||
"bootstrap": "~3.3.4",
|
||||
"DataTables": "~1.10.5",
|
||||
"Leaflet.Elevation": "MrMufflon/Leaflet.Elevation#master"
|
||||
"Leaflet.Elevation": "MrMufflon/Leaflet.Elevation#master",
|
||||
"leaflet-control-geocoder": "~1.1.0"
|
||||
},
|
||||
"overrides": {
|
||||
"leaflet": {
|
||||
|
|
@ -26,13 +26,6 @@
|
|||
"dist/images/*.png"
|
||||
]
|
||||
},
|
||||
"leaflet-search": {
|
||||
"main": [
|
||||
"dist/leaflet-search.src.js",
|
||||
"dist/leaflet-search.min.css",
|
||||
"images/*.+(png|gif)"
|
||||
]
|
||||
},
|
||||
"leaflet-plugins": {
|
||||
"main": [
|
||||
"control/Permalink.js",
|
||||
|
|
@ -66,6 +59,13 @@
|
|||
},
|
||||
"Leaflet.Elevation": {
|
||||
"dependencies": null
|
||||
},
|
||||
"leaflet-control-geocoder": {
|
||||
"main": [
|
||||
"Control.Geocoder.js",
|
||||
"Control.Geocoder.css",
|
||||
"images/*.+(png|gif)"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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