首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Openlayers 3重新设计EPSG:4326矢量到EPSG:3857

Openlayers 3重新设计EPSG:4326矢量到EPSG:3857
EN

Stack Overflow用户
提问于 2017-07-06 19:33:23
回答 1查看 3.5K关注 0票数 6

我需要将GeoJSON矢量数据从EPSG:4326转换为EPSG:3857.

我有一张地图.

代码语言:javascript
复制
var olMapDiv = document.getElementById('olmap');
            control.map = new ol.Map({
                target: olMapDiv,
                renderer: 'canvas',
                layers: layers,
                interactions: ol.interaction.defaults({
                    altShiftDragRotate: false,
                    dragPan: false,
                    rotate: false
                }).extend([new ol.interaction.DragPan({ kinetic: null })]),
                pixelRatio: 1,
                loadTilesWhileAnimating: true,
                loadTilesWhileInteracting: true,
                view: view
            });

和一个视图.

代码语言:javascript
复制
var view = new ol.View({
                // make sure the view doesn't go beyond the 22 zoom levels of Google Maps
                maxZoom: 21,
                projection: 'EPSG:3857',
                center: [0, 0],
                zoom: 0
            });

我定义了我的geoJson对象.

代码语言:javascript
复制
var geoJsonObj = {
                        'type': 'Feature',
                        'geometry': JSON.parse(shape),
                        'name': 'V',
                        'id': V.vID

                    }

我尝试将这些特性读入一个开放层向量对象并提供投影参数.

代码语言:javascript
复制
var vectorSource = new ol.source.Vector({
                        features: (new ol.format.GeoJSON()).readFeatures(geoJsonObj, {defaultDataProjection:"EPSG:4326",featureProjection:"EPSG:3857"})
                    });

然后我在一个新的向量层中使用上面的"vectorSource“.

代码语言:javascript
复制
vectors = new ol.layer.Vector({                           
                        title: V.vID,
                        source: vectorSource,
                        id: V.vID,
                        name: 'V',
                        label: response.VList[key].Acres,
                        fill: response.VList[key].Shade,
                        stroke: defaultStrokeHex,
                        style: function (feature, resolution) {
                            var text = resolution * 100000 < 10 ? response.VList[key].Acres : '';

                            if (text != "") {
                                styleCache[text] = [new ol.style.Style({
                                    stroke: new ol.style.Stroke({
                                        color: '#319FD3',
                                        width: 1
                                    }),
                                    text: new ol.style.Text({
                                        font: '12px Calibri,sans-serif',
                                        text: text,
                                        fill: new ol.style.Fill({
                                            color: '#000'
                                        }),
                                        stroke: new ol.style.Stroke({
                                            color: '#fff',
                                            width: 3
                                        })
                                    }),
                                    fill: new ol.style.Fill({
                                        color: rcisWebMapUtilities.convertHex(response.VList[key].Shade, '0.5')
                                    })
                                })];
                            }
                            else if (text == "") {
                                styleCache[text] = [new ol.style.Style({
                                    fill: new ol.style.Fill({
                                        color: rcisWebMapUtilities.convertHex(response.VList[key].Shade, '0.5')
                                    })
                                })
                                ]
                            } return styleCache[text];
                        }


                    });

无论我做什么,我要么在EPSG:4326中看到矢量drawn...but,要么没有负载.

我花了太多的时间试图弄清楚如何让OpenLayers3做this...Any的帮助是非常感谢的!!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-07 07:09:02

如果在您的视图中使用EPSG:4326,那么您的geojson矢量声明应该是

代码语言:javascript
复制
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject, { 
dataProjection: 'EPSG:4326',
featureProjection:'EPSG:4326' })
});

如果在视图中使用EPSG:3857,请使用以下命令:

代码语言:javascript
复制
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject, { 
dataProjection: 'EPSG:4326',
featureProjection:'EPSG:3857' })
});

只是为了解释dataProjection是源和弦。表示您在geojson文件中的坐标的epsg。而featureProjection是视图的EPSG,因此是地图的EPSG。手段是EPSG的原始和弦应该被转换。

因此,请记住以下规则:featureProjectionol.View投影声明应该相等。

注意,我假设你的地弦投影在EPSG:4326.中。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44957431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档