3

我正在使用 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 数据库中检索和经度。

4

2 回答 2

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);
于 2012-12-21T08:24:01.493 回答
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
    });
于 2012-02-13T19:36:27.703 回答