zoukankan      html  css  js  c++  java
  • openlayers地图画线+打点

    1. openlayer地图画线+打点

    
    /**
     * 注:
     *  创建openlayer图层三步骤:
     *      1. 创建图层
     *      2. 创建图层源
     *      3. 创建源特征
     *  特别重要的一句话:图层是图层,点是点,点是add到图层上面的。
     *  图层什么概念呢?千层饼吃过吧,,,当地图上图层很多的时候回非常卡,所以地图上不要同时加载很多图层,要及时释放空间。
     *
     */
    
    
    
    import { Vector as SourceVec } from 'ol/source'
    import VectorLayer from 'ol/layer/Vector';
    import Feature from 'ol/Feature';
    import LineString from 'ol/geom/LineString';
    import Style from  'ol/style/Style'
    import Stroke from 'ol/style/Stroke';
    import { asArray } from 'ol/color';
    import Point from 'ol/geom/Point';
    import Icon from 'ol/style/Icon';
    import { toSize } from 'ol/size';
    
    
    
    /**
     * 创建线
     * @param {经纬度数组} lnglats 
     * @param {参数,有color颜色,width线的粗细} params 
     */
    export function addLineString(lnglats,params) {
      if (!params) {
        params = {}
      }
      if (!params['color']) {
        params['color'] = '#3498db'
      }
      if (!params['width']) {
        params['width'] = 8
      }
      // 设置源特征
      let feature = new Feature({
        geometry: new LineString(lnglats),
        name: 'Line'
      })
      // 创建图层源
      let sourceVec = new SourceVec({
        features: [feature]
      })
      // 创建图层
      let vercorLayer = new VectorLayer({
          source: sourceVec,
          style: new Style({
            stroke: new Stroke({
               params.width,
              color: asArray(params.color)
            })
          })
      })
      return vercorLayer
    }
    
    
    
    /**
     * 地图打点
     * @param {经纬度数组} lnglats 
     * @param {图标地址} icon 
     * @param {图标大小} size 
     */
    
    export function addMarker(lnglats,icon,size) {
      if (!size) {
        size = 0.12
      }
      let features = []
      //创建图标特性
      lnglats.forEach(lnglat => {
        features.push(createFeature(lnglat))
      })
      // 创建矢量容器
      var vectorSource = new SourceVec({
        features: features
      })
         //创建图标样式
       var iconStyle = new Style({
         image: new Icon({
             opacity: 0.75,
             src: icon,
             scale: toSize(size)
         })
       })
       //创建矢量层
       var vectorLayer = new VectorLayer({
           source: vectorSource,
           style: iconStyle
       });
       return vectorLayer
    }
    
    function createFeature(lnglat) {
      return new Feature({
          geometry: new Point(lnglat, "XY")
      })
    }
    
  • 相关阅读:
    restframework 生成接口文档
    django simpleRoute 简化路由
    django 视图GenericView
    备份问题-原生问题
    django 中如何使用celery 和redis
    主外键定义与主从表关系
    django restframework 钩子函数:全局钩子和局部钩子
    QuerySet Django 几个必会方法
    django restframework -模型序列化高级用法终极篇
    django User.objects.get()报错 raise self.model.DoesNotExist手动处理解决办法
  • 原文地址:https://www.cnblogs.com/xyqbk/p/14070354.html
Copyright © 2011-2022 走看看