OL_measure.vue 2.98 KB
<!--
 * @Author: jiangbotao
 * @Date: 2019-12-17 23:19:19
 * @LastEditors: jiangbotao
 * @LastEditTime: 2019-12-18 00:02:39
 * @FilePath: \supermapvue\src\components\ol\OL_measure.vue
 -->
<template>
  <div >
    <div id="map"></div>
  </div>
</template>

<script>
import "ol/ol.css";
import { Map, View } from "ol";
import { XYZ } from 'ol/source';
import WKT from 'ol/format/WKT';
import VectorSource from "ol/source/Vector";
import Point from "ol/geom/Point";
import {Draw, Modify, Snap} from 'ol/interaction';
import { Tile as TileLayer, Vector as VectorLayer } from "ol/layer";
import {Circle as CircleStyle, Fill, Stroke, Style} from 'ol/style';

export default {
    data() {
        return {
        map: null
        };
    },
    mounted() {
        var tdt_vec = new TileLayer({
        source: new XYZ({
            url: "http://t3.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=394404c8b901574fdc4cdf8c18a98448"
        })
        });
        var tdt_cva = new TileLayer({
        source: new XYZ({
            url: "http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=394404c8b901574fdc4cdf8c18a98448"
        })
        });
        // 矢量绘制图层
        var source = new VectorSource();
        var vectorLayer = new VectorLayer({
            source: source,
            style: new Style({
                fill: new Fill({
                    color: 'rgba(255, 0, 0, 0.2)'
                }),
                stroke: new Stroke({
                    color: '#ffcc33',
                    width: 2
                }),
                image: new CircleStyle({
                    radius: 7,
                    fill: new Fill({
                        color: '#ffcc33'
                    })
                })
            })
        });
        this.map = new Map({
            target: "map",
            layers: [
                tdt_vec, tdt_cva, vectorLayer
            ],
            view: new View({
                projection: "EPSG:4326",
                center: [120.79, 27.99],
                zoom: 12,
                minZoom: 10,
                maxZoom: 18
            })
        });

    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#map {
  position: absolute;
  height: 100%;
  width: 100%;
  background-color: white
}
.ol-tooltip {
    position: relative;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    color: white;
    padding: 4px 8px;
    opacity: 0.7;
    white-space: nowrap;
    font-size: 12px;
    }
.ol-tooltip-measure {
    opacity: 1;
    font-weight: bold;
}
.ol-tooltip-static {
    background-color: #ffcc33;
    color: black;
    border: 1px solid white;
}
.ol-tooltip-measure:before,
.ol-tooltip-static:before {
    border-top: 6px solid rgba(0, 0, 0, 0.5);
    border-right: 6px solid transparent;
    border-left: 6px solid transparent;
    content: "";
    position: absolute;
    bottom: -6px;
    margin-left: -7px;
    left: 50%;
}
.ol-tooltip-static:before {
    border-top-color: #ffcc33;
}
</style>