我将有一堆图层需要加载到我的地图中,因此我没有单独加载每个图层,而是尝试使用 json 文件和 Openlayers.Request.GET 进行加载,但不知道如何完成编码。
.json 文件:
{
"layers": [
{ "title":"Client Manholes" , "url":"./mh_file.geojson" , "style":"mh_style"},
{ "title":"Client Pipe" , "url":"./pipe_file.geojson" , "style":"pipe_style"},
{ "title":"Client Parcels" , "url":"./parcel_file.geojson" , "style":"parcel_style"}
]
}
javascript:
var request = OpenLayers.Request.GET({
url: "http://domain.com/layers.json",
callback: handler
});
function handler(request) {
//alert (request);
var response = json.read (request.responseText);
//loop thru each layer
for each (var layer in request) {
//load layer
layer = new OpenLayers.Layer.Vector(layer_title, {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: layer_url,
format: new OpenLayers.Format.GeoJSON({
})
}),
//...load stylemap
});
//turn layer off
layer.setVisibility(false);
}
};