2014-09-26 20:43:54 +00:00
|
|
|
/**
|
2014-11-30 12:21:58 +00:00
|
|
|
* searx is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* searx is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
|
|
|
*
|
|
|
|
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
|
|
|
*/
|
2014-09-29 07:44:29 +00:00
|
|
|
|
2014-09-26 20:43:54 +00:00
|
|
|
$(document).ready(function(){
|
2014-11-19 13:59:30 +00:00
|
|
|
$(".searx_overpass_request").on( "click", function( event ) {
|
2014-11-20 14:31:00 +00:00
|
|
|
var overpass_url = "https://overpass-api.de/api/interpreter?data=";
|
2014-11-19 13:59:30 +00:00
|
|
|
var query_start = overpass_url + "[out:json][timeout:25];(";
|
|
|
|
var query_end = ");out meta;";
|
|
|
|
|
|
|
|
var osm_id = $(this).data('osm-id');
|
|
|
|
var osm_type = $(this).data('osm-type');
|
|
|
|
var result_table = $(this).data('result-table');
|
|
|
|
var result_table_loadicon = "#" + $(this).data('result-table-loadicon');
|
|
|
|
|
|
|
|
// tags which can be ignored
|
2014-11-30 12:21:58 +00:00
|
|
|
var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ];
|
2014-11-19 13:59:30 +00:00
|
|
|
|
|
|
|
if(osm_id && osm_type && result_table) {
|
|
|
|
result_table = "#" + result_table;
|
|
|
|
var query = null;
|
|
|
|
switch(osm_type) {
|
|
|
|
case 'node':
|
|
|
|
query = query_start + "node(" + osm_id + ");" + query_end;
|
|
|
|
break;
|
|
|
|
case 'way':
|
|
|
|
query = query_start + "way(" + osm_id + ");" + query_end;
|
|
|
|
break;
|
|
|
|
case 'relation':
|
|
|
|
query = query_start + "relation(" + osm_id + ");" + query_end;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(query) {
|
|
|
|
//alert(query);
|
|
|
|
var ajaxRequest = $.ajax( query )
|
|
|
|
.done(function( html) {
|
2014-11-30 12:21:58 +00:00
|
|
|
if(html && html.elements && html.elements[0]) {
|
|
|
|
var element = html.elements[0];
|
2014-11-19 13:59:30 +00:00
|
|
|
var newHtml = $(result_table).html();
|
|
|
|
for (var row in element.tags) {
|
2014-11-30 12:21:58 +00:00
|
|
|
if(element.tags.name === null || osm_ignore_tags.indexOf(row) == -1) {
|
2014-11-19 13:59:30 +00:00
|
|
|
newHtml += "<tr><td>" + row + "</td><td>";
|
|
|
|
switch(row) {
|
|
|
|
case "phone":
|
|
|
|
case "fax":
|
|
|
|
newHtml += "<a href=\"tel:" + element.tags[row].replace(/ /g,'') + "\">" + element.tags[row] + "</a>";
|
|
|
|
break;
|
|
|
|
case "email":
|
|
|
|
newHtml += "<a href=\"mailto:" + element.tags[row] + "\">" + element.tags[row] + "</a>";
|
|
|
|
break;
|
|
|
|
case "website":
|
|
|
|
case "url":
|
|
|
|
newHtml += "<a href=\"" + element.tags[row] + "\">" + element.tags[row] + "</a>";
|
|
|
|
break;
|
|
|
|
case "wikidata":
|
|
|
|
newHtml += "<a href=\"https://www.wikidata.org/wiki/" + element.tags[row] + "\">" + element.tags[row] + "</a>";
|
|
|
|
break;
|
|
|
|
case "wikipedia":
|
|
|
|
if(element.tags[row].indexOf(":") != -1) {
|
2014-11-30 12:21:58 +00:00
|
|
|
newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/" + element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
|
2014-11-19 13:59:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-30 12:21:58 +00:00
|
|
|
/* jshint ignore:start */
|
2014-11-19 13:59:30 +00:00
|
|
|
default:
|
2014-11-30 12:21:58 +00:00
|
|
|
/* jshint ignore:end */
|
2014-11-19 13:59:30 +00:00
|
|
|
newHtml += element.tags[row];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
newHtml += "</td></tr>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$(result_table).html(newHtml);
|
|
|
|
$(result_table).removeClass('hidden');
|
|
|
|
$(result_table_loadicon).addClass('hidden');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.fail(function() {
|
2014-11-20 14:31:00 +00:00
|
|
|
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">could not load data!</p>");
|
2014-11-30 12:21:58 +00:00
|
|
|
});
|
2014-11-19 13:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// this event occour only once per element
|
|
|
|
$( this ).off( event );
|
|
|
|
});
|
2014-11-02 12:00:28 +00:00
|
|
|
|
|
|
|
$(".searx_init_map").on( "click", function( event ) {
|
|
|
|
var leaflet_target = $(this).data('leaflet-target');
|
|
|
|
var map_lon = $(this).data('map-lon');
|
|
|
|
var map_lat = $(this).data('map-lat');
|
|
|
|
var map_zoom = $(this).data('map-zoom');
|
|
|
|
var map_boundingbox = $(this).data('map-boundingbox');
|
|
|
|
var map_geojson = $(this).data('map-geojson');
|
2014-11-30 12:21:58 +00:00
|
|
|
|
2014-11-02 12:00:28 +00:00
|
|
|
require(['leaflet-0.7.3.min'], function(leaflet) {
|
|
|
|
if(map_boundingbox) {
|
2014-11-30 12:21:58 +00:00
|
|
|
southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]);
|
|
|
|
northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]);
|
|
|
|
map_bounds = L.latLngBounds(southWest, northEast);
|
2014-11-02 12:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO hack
|
|
|
|
// change default imagePath
|
2015-01-01 16:54:33 +00:00
|
|
|
L.Icon.Default.imagePath = "./static/themes/oscar/img/map";
|
2014-11-02 12:00:28 +00:00
|
|
|
|
|
|
|
// init map
|
|
|
|
var map = L.map(leaflet_target);
|
|
|
|
|
|
|
|
// create the tile layer with correct attribution
|
2014-11-03 17:47:18 +00:00
|
|
|
var osmMapnikUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
|
|
|
|
var osmMapnikAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
|
|
|
|
var osmMapnik = new L.TileLayer(osmMapnikUrl, {minZoom: 1, maxZoom: 19, attribution: osmMapnikAttrib});
|
|
|
|
|
|
|
|
var osmMapquestUrl='http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg';
|
|
|
|
var osmMapquestAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png">';
|
|
|
|
var osmMapquest = new L.TileLayer(osmMapquestUrl, {minZoom: 1, maxZoom: 18, subdomains: '1234', attribution: osmMapquestAttrib});
|
|
|
|
|
|
|
|
var osmMapquestOpenAerialUrl='http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg';
|
|
|
|
var osmMapquestOpenAerialAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="https://developer.mapquest.com/content/osm/mq_logo.png"> | Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency';
|
|
|
|
var osmMapquestOpenAerial = new L.TileLayer(osmMapquestOpenAerialUrl, {minZoom: 1, maxZoom: 11, subdomains: '1234', attribution: osmMapquestOpenAerialAttrib});
|
2014-11-02 12:00:28 +00:00
|
|
|
|
|
|
|
// init map view
|
|
|
|
if(map_bounds) {
|
|
|
|
// TODO hack: https://github.com/Leaflet/Leaflet/issues/2021
|
|
|
|
setTimeout(function () {
|
2014-11-02 21:35:06 +00:00
|
|
|
map.fitBounds(map_bounds, {
|
|
|
|
maxZoom:17
|
|
|
|
});
|
2014-11-02 12:00:28 +00:00
|
|
|
}, 0);
|
|
|
|
} else if (map_lon && map_lat) {
|
|
|
|
if(map_zoom)
|
|
|
|
map.setView(new L.LatLng(map_lat, map_lon),map_zoom);
|
|
|
|
else
|
|
|
|
map.setView(new L.LatLng(map_lat, map_lon),8);
|
|
|
|
}
|
|
|
|
|
2014-11-19 13:59:30 +00:00
|
|
|
map.addLayer(osmMapquest);
|
2014-11-03 17:47:18 +00:00
|
|
|
|
|
|
|
var baseLayers = {
|
|
|
|
"OSM Mapnik": osmMapnik,
|
|
|
|
"MapQuest": osmMapquest/*,
|
|
|
|
"MapQuest Open Aerial": osmMapquestOpenAerial*/
|
|
|
|
};
|
|
|
|
|
|
|
|
L.control.layers(baseLayers).addTo(map);
|
|
|
|
|
2014-11-02 12:00:28 +00:00
|
|
|
|
|
|
|
if(map_geojson)
|
|
|
|
L.geoJson(map_geojson).addTo(map);
|
2014-11-02 21:35:06 +00:00
|
|
|
/*else if(map_bounds)
|
|
|
|
L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).addTo(map);*/
|
2014-11-02 12:00:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// this event occour only once per element
|
|
|
|
$( this ).off( event );
|
|
|
|
});
|
2014-09-29 07:44:29 +00:00
|
|
|
});
|