码迷,mamicode.com
首页 > 其他好文 > 详细

openlayers入门开发系列之批量叠加zip压缩SHP图层篇

时间:2018-12-16 23:15:17      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:res   vector   tran   形式   .so   src   center   width   []   

本篇的重点内容是直接加载压缩文件zip形式shp,可以批量加载点、线、面shp图层,效果图如下:

技术分享图片

实现的思路跟之前实现arcgis api for js版本是一致的:arcgis api for js入门开发系列二十三批量叠加zip压缩SHP图层

压缩的shp截图如下:

技术分享图片

实现的核心代码:

//叠加压缩SHP图层,批量加载显示
$("#zipshp").click(function () {
            shp("js/main/shpJS/gishome.zip").then(function (data) {
                if (data && data.length > 0) {
                var layers = map.getLayers().getArray();
                var remolayers = [];
                for(var i =0;i<layers.length;i++){
                    var layer = layers[i];
                    if(layer.get("id") && layer.get("id").indexOf("zipshp") != -1){ 
                        remolayers.push(layer);
                    }
                }
                for(var j=0;j<remolayers.length;j++){
                    map.removeLayer(remolayers[j]); 
                }
                var image = new ol.style.Circle({
                        radius: 5,
                        fill: null,
                        stroke: new ol.style.Stroke({color: ‘red‘, width: 1})
                });
                var styles = {
                        ‘Point‘: new ol.style.Style({
                          image: image
                        }),
                        ‘LineString‘: new ol.style.Style({
                          stroke: new ol.style.Stroke({
                            color: ‘red‘,
                            width: 6
                          })
                        }),
                        ‘MultiLineString‘: new ol.style.Style({
                          stroke: new ol.style.Stroke({
                            color: ‘red‘,
                            width: 6
                          })
                        }),
                        ‘MultiPoint‘: new ol.style.Style({
                          image: image
                        }),
                        ‘MultiPolygon‘: new ol.style.Style({
                          stroke: new ol.style.Stroke({
                            color: ‘yellow‘,
                            width: 1
                          }),
                          fill: new ol.style.Fill({
                            color: ‘rgba(255, 255, 0, 0.1)‘
                          })
                        }),
                        ‘Polygon‘: new ol.style.Style({
                          stroke: new ol.style.Stroke({
                            color: ‘blue‘,
                            lineDash: [4],
                            width: 3
                          }),
                          fill: new ol.style.Fill({
                            color: ‘rgba(0, 0, 255, 0.1)‘
                          })
                        })
                      };
                    var styleFunction = function(feature) {
                        return styles[feature.getGeometry().getType()];
                    };
                    for (var i = 0; i < data.length; i++) {
                        var vectorSource = new ol.source.Vector({
                            features: (new ol.format.GeoJSON()).readFeatures(data[i])
                        });
                        var features = vectorSource.getFeatures();
                        for(var j=0;j<features.length;j++){
                            var feature = features[j];
                            var geom = feature.getGeometry().transform(‘EPSG:4326‘, ‘EPSG:3857‘);
                            feature.setGeometry(geom);                            
                        }
                        var vectorLayer = new ol.layer.Vector({
                            source: vectorSource,
                            style: styleFunction
                          });
                        vectorLayer.set("id", "zipshp"+i);
                           map.addLayer(vectorLayer);
                        //地图跳转范围
                        map.getView().setCenter([13654710.733, 4878822.641]);
                        map.getView().setZoom(8);
                    }
                }
            });
});

openlayers入门开发系列之批量叠加zip压缩SHP图层篇

标签:res   vector   tran   形式   .so   src   center   width   []   

原文地址:https://www.cnblogs.com/giserhome/p/10128146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!