ionic webApp 通过openlayer集成 arcgis 地图服务

本文介绍了如何在ionic webApp中通过openlayer集成arcgis地图服务,详细步骤包括导入openlayer的css和js包,然后在index.html中引入,接着在controller中初始化map实例,并构建矢量图层来展示标注数据。
摘要由CSDN通过智能技术生成

1、导入openlayer css包、js包

  

2、在APP 首页index.html中引入

index.html引入openlayer包

<!--引入openlayer css-->

<link rel="stylesheet" href="lib/openlayer/css/ol.css">

 

 

<!--引入openlayer js-->

<script src="lib/openlayer/js/ol.js"></script>

 

3、在controller中初始化openlayer map实例

实例化openlayer map 对象

//创建地图

var GISServiceUrl = GlobalVariable.GISServiceUrl;

var map = new ol.Map({ 

     target: 'mapPage'

     layers: [

        new ol.layer.Tile({      

        source: new ol.source.TileArcGISRest({        

            url: GISServiceUrl     

         })    

        }),    

        //featureOverlay8   ],

  view: new ol.View({    

    center: [

        112.3543, 37.5043],    

        zoom: 7,   

        minZoom: 6,    

        maxZoom: 20,    

        projection: 'EPSG:4326'  

        })

        });

 

 

//Map 图层click事件绑定 弹框

var object = '';

 map.on('click',function (evt) { 

 //如果模态框已经打开,则不弹出,防止openlayer 多点触发问题(后面可看下openlayer是否有其他点击监听事件)   

    var pixel = map.getEventPixel(evt.originalEvent);  

    var feature = map.forEachFeatureAtPixel(pixel, function (feature) {    

            object = feature.values_.type;

            $scope.openDetail(object);

  });

});

 

//遗留问题: openlayer 初始化监听事件后,在页面点击标点会触发多个点的事件,需要在打开弹出层的方法里做判断处理

4、构建矢量图层

openlayer 构建矢量图层

for (var j = 0; j < mapDatas1.length; j++) {  

    var x1 = mapDatas1[j].lnglat[0], y1 = mapDatas1[j].lnglat[1],   obj1 = mapDatas1[j];    var createLabelStyle = function (feature) {    

        return new ol.style.Style({      

            image: new ol.style.Icon(        

            ({          

                anchor: [0.5, 60],          

                anchorOrigin: 'top-right',          

                anchorXUnits: 'fraction',          

                anchorYUnits: 'pixels',          

                offsetOrigin: 'top-right',          

                opacity: 0.75,          

                src: styleObjectArr[obj1.style].url        

            })      

            )   

        });  

    } //实例化Vector要素,通过矢量图层添加到地图容器中  

iconFeature1[j] = new ol.Feature({    

    geometry: new ol.geom.Point([x1, y1]),     type:obj1   });  

    iconFeature1[j].setStyle(createLabelStyle(iconFeature1[j]

    ));

}

//矢量标注的数据源

vectorSource1 = new ol.source.Vector({   features: iconFeature1 });

//矢量标注图层

vectorLayer1 = new ol.layer.Vector({   source: vectorSource1 });

//地图添加图层

map.addLayer(vectorLayer1);

 

注:mapDatas1 是要添加标注的数据集合

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值