2015-06-19 99 views
0

我試圖在eps:28992設置上使用自定義wmts圖層創建一個openlayers3地圖。我以前使用過openlayers 2,但我沒有成功。使用openlayers3創建EPSG:28992地圖

我已經嘗試將eps圖層添加到proj,但它似乎沒有做任何事情,出現錯誤:Uncaught TypeError:無法讀取null的屬性'0'。 並且沒有請求瓷磚。

var projection = ol.proj.get('EPSG:28992'); 
var projectionExtent = projection.getExtent(); 
var resolutions = [3440.640, 1720.320, 860.160, 430.080, 215.040, 107.520, 53.760, 26.880, 13.440, 6.720, 3.360, 1.680, 0.840, 0.420, 0.210]; 
var matrixIds = new Array(26); 
    for (var i=0; i<26; ++i) { 
    matrixIds[i] = "EPSG:28992:" + i; 
} 

var attribution = new ol.Attribution({ 
    html: 'Tiles &copy; <a href="http://services.arcgisonline.com/arcgis/rest/' + 
     'services/Demographics/USA_Population_Density/MapServer/">ArcGIS</a>' 
}); 

lonlat = result.center.split(','); 


var map = new ol.Map({ 


    view: new ol.View({ 
     center: [lonlat[0],lonlat[1]], 
     zoom: result.zoom 
    }), 

    layers: [ 
     new ol.layer.Tile({ 
      opacity: 0.7, 
      source: new ol.source.WMTS({ 
      attributions: [attribution], 
      url: "http://geodata.nationaalgeoregister.nl/wmts/", 
      name: "Basis Registratie Topografie", 
      layer: "brtachtergrondkaart", 
      matrixSet: "EPSG:28992", 
      format: 'image/png', 
      projection: projection, 
      tileGrid: new ol.tilegrid.WMTS({ 
       origin: ol.extent.getTopLeft(projectionExtent), 
       resolutions: resolutions, 
       matrixIds: matrixIds 
      }), 
      style: 'default' 
      }) 
     }) 
    ], 
    target: target 
}); 

分辨率EN matrixIds在openlayers2工作,所以我直接複製他們,我覺得我失去了一些東西非常小的不ANY1有一個想法?

p.s.我加了EPSG:28992與以下行proj4.js:

proj4.defs("EPSG:28992","+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +units=m +no_defs"); 

關於卡斯帕

+2

看看這是否可以幫助你:https://github.com/bartvde/PDOK-OpenLayers3 – bartvde

+0

Thnx的演示,這正是我需要的。 –

回答

1

這裏的問題是,ol.proj.Projection#getExtent()將返回null爲從Proj4js配置預測。你不需要Proj4js來讓你的地圖工作,但是你將需要tile網格的正確來源。配置WMTS層的最簡單方法是請求功能(http://geodata.nationaalgeoregister.nl/wmts/?request=GetCapabilities)並使用ol.format.WMTSCapabilitiesol.source.WMTS.optionsFromCapabilitiesol.source.WMTS實例創建選項。但是你也可以手動配置你的圖層。查看GetCapabilities響應,我發現正確的來源是[-285401.92 903402.0]