使用Node.js查询OSM数据

时间:2016-05-19 05:12:25

标签: javascript node.js openlayers openstreetmap overpass-api

这里我试图通过以下代码使用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>

enter image description here 但是没有医院在地图图像中看到标记。但是在涡轮增压器中尝试http://overpass-turbo.eu/s/gj0工作正常。

0 个答案:

没有答案