天天看點

Openlayers 3 繪制過程中坐标系統轉換方法示例 (EPSG4326到 3857)

Openlayers 3 Reproject EPSG:4326 vector to EPSG:3857 

關鍵點: dataProject 源的投影坐标系 , featureProjection目的投影坐标系 

示例中待繪制資料的投影坐标系為 4326(通用編号) 分别在4326坐标系統 及3857坐标系下繪制如下.

If you use EPSG:4326 in your view then your geojson vector declaration should be:

目标坐标系為 4326:

var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject, { 
dataProjection: 'EPSG:4326',
featureProjection:'EPSG:4326' })
});
           

If you use EPSG:3857 in your view use this:

目标坐标系為 3857:

var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject, { 
dataProjection: 'EPSG:4326',
featureProjection:'EPSG:3857' })
});
           

Just to explain 

dataProjection

 is the source coords. Means the epsg of your coordinates within the geojson file. While 

featureProjection

 is the EPSG of your view and thus the EPSG of your map. Means is the EPSG original coords should be trasformed.

解釋: dataProjection是源坐标系,即要繪制的geojson中存放的坐标的坐标系統. featureProjection是目标地圖視窗的坐标系統,即目标坐标系.

So try to remember this rule: 

featureProjection

 and 

ol.View

 projection declaration should be equal.

注意: 目标坐标系就是 ol.view裡面初始定義的投影坐标系統.不是任意指定的.

繼續閱讀