javascript download geoserver layer as kml file

 var sqlfilter = " CITY='" + city + "' and SDATE>" + sdate + " and SDATE <" + edate;

soMapRoad.downLoadGeoLayer(actionId, kpi, layerTitle, sqlfilter);
 
 function downloadTileGridMap(layerName, styleId, filterQuery) {

        var url = "http://" + geoIP + "/geoserver/wms?service=WMS&version=1.1.0&request=GetMap&LAYERS=FAST:" + layerName + "&STYLES=" + styleId + "&CQL_FILTER=" + filterQuery + "&bbox=109.0,20.0,118.0,26.0&width=768&height=512&srs=EPSG:4326&format=application/vnd.google-earth.kml+xml";
                 
        window.open(url);
    }


    function downLoadGeoLayer(currentActionId, kpi, sqlfilter) {

        $.getJSON("../Action.json",
            function (json) {
                $.each(json,
                    function (infoIndex, info) {

                        var actionId = info["ID"];

                        if (actionId === currentActionId) {
                            var layerName = info["layers"];
                            var styleId = info["style"];
                            var bbox = info['filter'];
                            var filter = sqlfilter;
                            downloadTileGridMap(layerName, styleId, filter, bbox);
                        }
                    });
            });
    }
原文地址:https://www.cnblogs.com/googlegis/p/11764947.html