我有一个控制器对web服务进行rest调用。它会响应一个KML文件,然后我需要获取响应并将其发送到open layers。我知道如何从控制器调用web服务,但是如何在.js文件中使用它呢?
发布于 2012-08-24 06:52:17
稍微修改一下openlayers/KML example,其中"grails URL“是指向您的控制器/操作的URL,它在响应中返回一些KML:
var map = new OpenLayers.Map({
div: "map",
layers: [
new OpenLayers.Layer.WMS(
"WMS", "http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: "basic"}
),
new OpenLayers.Layer.Vector("KML", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: **<grails URL>**
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 2
})
})
})
],
center: new OpenLayers.LonLat(-112.169, 36.099),
zoom: 11
});
显然,其他配置(居中、缩放等)需要适应自己的需求。
https://stackoverflow.com/questions/12094711
复制