这里我试图通过以下代码使用overpass和openlayer从osm数据库查询医院
<script src="http://openlayers.org/api/2.11/OpenLayers.js"></script>
<script src="http://openstreetmap.org/openlayers/OpenStreetMap.js"></script>
<script src="http://overpass-api.de/overpass.js"></script>
<script>
var lat = 8.4967;
var lon = 76.9493;
var zoom = 15;
var data_url = "http://overpass-api.de/api/interpreter?data=node[amenity=%22hospital%22];out+skel;";
var map;
function init(){
map = new OpenLayers.Map ("demoMap", {
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Attribution()],
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
maxResolution: 156543.0399,
numZoomLevels: 19,
units: 'm',
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
} );
layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
map.addLayer(layerMapnik);
var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
map.setCenter (lonLat, zoom);
var styleMap = new OpenLayers.StyleMap({
strokeColor: "blue",
strokeOpacity: 0.5,
strokeWidth: 6,
pointRadius: 10,
fillColor: "blue",
fillOpacity: 0.25
});
var layer = new OpenLayers.Layer.Vector("Polygon", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: data_url,
format: new OpenLayers.Format.OSM()
}),
styleMap: styleMap,
projection: new OpenLayers.Projection("EPSG:4326")
});
map.addLayers([layer]);
}
</script>
但是没有医院在地图图像中看到标记。但是在涡轮增压器中尝试http://overpass-turbo.eu/s/gj0工作正常。