我正在使用Patrick Wied的OpenLayers热图图层,但仅适用于英国的地点。
如何预设初始地图显示区域以显示英国?
这是我在ASPX页面中使用的代码
var map, layer, heatmap;
function init() {
var testData = <asp:literal id="cLtMapData" runat="server" />
var transformedTestData = { max: testData.max, data: [] },
data = testData.data,
datalen = data.length,
nudata = [];
// in order to use the OpenLayers Heatmap Layer we have to transform our data into
// { max: <max>, data: [{lonlat: <OpenLayers.LonLat>, count: <count>},...]}
while (datalen--) {
nudata.push({
lonlat: new OpenLayers.LonLat(data[datalen].lon, data[datalen].lat),
count: data[datalen].count
});
}
transformedTestData.data = nudata;
map = new OpenLayers.Map('heatmapArea');
layer = new OpenLayers.Layer.OSM();
// create our heatmap layer
heatmap = new OpenLayers.Layer.Heatmap("Heatmap Layer", map, layer, { visible: true, radius: 10 }, { isBaseLayer: false, opacity: 0.3, projection: new OpenLayers.Projection("EPSG:4326") });
map.addLayers([layer, heatmap]);
map.zoomToMaxExtent();
//maxExtent: new OpenLayers.Bounds(-1*b, -1*b, b, b);
map.zoomIn();
heatmap.setDataSet(transformedTestData);
}
它几乎与Patrick的演示页面完全相同,但有一点不同 - var testData =(一个asp文字) - 这样我就可以使用用户选择的动态数据,并通过翻译英国的存储过程从SQL数据库中检索邮政编码为纬度和经度。
答案 0 :(得分:0)
我会在地图初始化中这样做。像这样:
map = new OpenLayers.Map({
projection: new OpenLayers.Projection("EPSG:900913"),
units: "m",
numZoomLevels: 18,
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(
-20037508.34, -20037508.34, 20037508.34, 20037508.34
),
layers: [
new OpenLayers.Layer.OSM("OpenStreetMap", null, {
transitionEffect: 'resize'
})
],
center: new OpenLayers.LonLat(-10309900, 4215100),
zoom: 4
});
答案 1 :(得分:0)
var lat = -3.841867446899414;
var lon = 43.466002139041116;
var zoom = 0;
var fromProjection = new OpenLayers.Projection("EPSG:28992"); // EPSG:4326Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection);
var options = {
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Permalink()
]
};
map = new OpenLayers.Map("basicMap", options);
var mapnik = new OpenLayers.Layer.OSM();
map.addLayer(mapnik);
map.setCenter(position, zoom);