美文网首页开源OpenLayers
OpenLayers5绘制点、线、面

OpenLayers5绘制点、线、面

作者: WebGiser | 来源:发表于2018-10-28 16:47 被阅读1次
<template>
    <div>
        <div id="map">

        </div>
        <div id="popup" class="ol-popup">
            <a href="#" id="popup-closer" class="ol-popup-closer"></a>
            <div id="popup-content">
                <ul id="message">

                </ul>
            </div>
        </div>
        <form class="form-inline">
            <label>Geometry type &nbsp;</label>
            <select name="" id="type">
                <option value="Point">Point</option>
                <option value="LineString">LineString</option>
                <option value="Polygon">Polygon</option>
                <option value="Circle">Circle</option>
                <option value="None">None</option>
            </select>
        </form>
    </div>
</template>

<script>
    import Map from 'ol/Map';
    import View from 'ol/View';
    import TileLayer from 'ol/layer/Tile';
    import VectorLayer from 'ol/layer/Vector';
    import OSM from 'ol/source/OSM';
    import VectorSource from 'ol/source/Vector';
    import {defaults} from 'ol/control'
    import Draw from 'ol/interaction/Draw'
    import Overlay from 'ol/Overlay'
    import {toStringHDMS} from 'ol/coordinate'
    import {transform} from 'ol/proj'

export default {
  name: 'MainDiv',
  data () {
    return {
    }
  },
    mounted:function(){
        var container = document.getElementById('popup');
        var content = document.getElementById('popup-content');
        var closer = document.getElementById('popup-closer');
        //创建一个叠加层,将弹出式窗口定位到地图。
        var overlay = new Overlay(({
            element: container,
            autoPan: true,
            autoPanAnimation:{
                duration:250
            }
        }));
        //点击关闭按钮  关闭弹窗
        closer.onclick = function () {
            //不显示弹出框
            overlay.setPosition(undefined);
            closer.blur();
            return false;
        };

        var raster = new TileLayer({
            source:new OSM()
        });
        var source = new VectorSource({wrapX:false});

        //ol.layer.Vector用于显示在客户端渲染的矢量数据。
        var vector = new VectorLayer({
            source:source
        });

        //地图部分
        var map = new Map({
            layers:[raster,vector],
            target:'map',
            overlays:[overlay],
            view:new View({
                projection:'EPSG:4326',
                center:[120,30],
                zoom:4
            }),
            controls:defaults({
                attributionOptions:{
                    collapsible:false
                }
            })

        });

        var typeSelect = document.getElementById('type');
        var draw;
        function addInteraction() {
            var value = typeSelect.value;
            if(value !== 'None'){
                draw = new Draw({
                    source:source,
                    type: typeSelect.value
                });
                map.addInteraction(draw);
            }
        }
        typeSelect.onchange = function () {
            map.removeInteraction(draw);
            addInteraction();
        };

        addInteraction();
        //向地图中添加点击处理程序以呈现弹出式窗口。
        map.on('click',function (evt) {
            var coordinate = evt.coordinate;
            // var hdms = toStringHDMS(transform(
            //     coordinate,'EPSG:3857','EPSG:4326'
            // ));
            var hdms = toStringHDMS(coordinate);
            content.innerHTML = '<ul>'+'<li>'+"坐标:"+'<span>'+'<code>'+hdms+'</code>'+'</span>'+'</li>'+'</ul>';
            overlay.setPosition(coordinate);
            console.log(source)
        });
    }
}
</script>


<style scoped>
    #map{
        width: 100%;
        height: 500px;
    }
    ul li{list-style: none;}
    .ol-popup {
        position: absolute;
        background-color: white;
        -webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
        filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
        padding: 5px;
        border-radius: 10px;
        border: 1px solid #cccccc;
        bottom: 12px;
        left: -50px;
        min-width: 350px;
    }
    .ol-popup:after, .ol-popup:before {
        top: 100%;
        border: solid transparent;
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        pointer-events: none;
    }
    .ol-popup:after {
        border-top-color: white;
        border-width: 10px;
        left: 48px;
        margin-left: -10px;
    }
    .ol-popup:before {
        border-top-color: #cccccc;
        border-width: 11px;
        left: 48px;
        margin-left: -11px;
    }
    .ol-popup-closer {
        text-decoration: none;
        position: absolute;
        top: 2px;
        right: 8px;
    }
    .ol-popup-closer:after {
        content: "✖";
    }
</style>

相关文章

  • OpenLayers5绘制点、线、面

  • Cesium绘制点、线、面、矩形

    本文基于《基于Webpack的Cesium+Vue应用》文章,在此基础之上,进行功能的扩展。本文主要讲解如何在Ce...

  • openlayer绘制点,线,面,overlay(vue)

    demo可直接使用 TileLayer.html add-feature.js

  • Openlayers API-Draw

    绘制功能在Openlayers中比较常用,平时我们需要手动绘制一些点、线、面、多边形,圆等图形,Openlayer...

  • WebGL 绘制Line的bug(一)

    熟悉WebGL的同学都知道,WebGL绘制模式有点、线、面三种;通过点的绘制可以实现粒子系统等,通过线可以绘制一些...

  • *犀牛

    1.椭圆弧面怎么绘制?耳机-背面 线绘制中间弧线,fg拉伸,选中曲线三条线之后,p嵌面,选基准面(拉伸曲面) 2....

  • Blender绘制基本网格对象

    网格定义 网格是由点、线、面进行连接绘制的几何图形对象,Blender中将点、线、面的三维坐标信息储存在数组中。 ...

  • TWaver3D直线、曲线、曲面的绘制

    1. WebGL原生线 WebGL支持绘制点、线、三角;绘制线的方法比较简单,给定顶点,设置绘制方式即可; 假设给...

  • Primitive篇(贴图)

    前几篇博客我们了解了自定义点、线、面绘制,这篇我们接着学习cesium自定义纹理贴图。我们完成点线面的绘制,只是绘...

  • 《点·线·面》

    点: 中心点目击鹰的眼睛 对视,看清自己 赤裸行走在一片雪地 线: 直线弯曲的地平线 光芒淹没转身的影子 空白的远...

网友评论

    本文标题:OpenLayers5绘制点、线、面

    本文链接:https://www.haomeiwen.com/subject/iffmtqtx.html