123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727 |
- <template>
- <div id="map">
- <!-- <div id="popup" class="style_container ol-popup">
- <div class="container">
- <div class="close_func">
- <a href="#" id="popup-closer" class="ol-popup-closer">×</a>
- </div>
- <div id="popup-title" class="popup-title"></div>
- <div id="popup-content" class="popup-content"></div>
- </div>
- </div>
- <div class="style_container changeBaseMap">
- <div class="container">
- <p
- :class="[
- 'bg',
- {
- active: mapChangeIsShow,
- },
- ]"
- @click="mapChangeIsShow = !mapChangeIsShow"
- ></p>
- <div class="style_container mapChangeIsShow" v-if="mapChangeIsShow">
- <div class="container">
- <ul>
- <li v-for="(item, index) in mapList" :key="index">
- <p :class="['bg', item.class, { active: item.active }]" @click="changeMap(item)">
- <span>{{ item.title }}</span>
- </p>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div> -->
- </div>
- </template>
- <script>
- import api from "@/api/menu";
- import Map from "ol/Map";
- import View from "ol/View";
- import Tile from "ol/layer/Tile";
- import XYZ from "ol/source/XYZ";
- import { defaults } from "ol/control";
- import { transform } from "ol/proj";
- import { Zoom, ScaleLine, Rotate, FullScreen, MousePosition } from "ol/control";
- import { createStringXY } from "ol/coordinate";
- import GeoJSON from "ol/format/GeoJSON";
- import VectorSource from "ol/source/Vector";
- import VectorLayer from "ol/layer/Vector";
- import Overlay from "ol/Overlay";
- import { Fill, Stroke, Text, Style } from "ol/style";
- import Select from "ol/interaction/Select";
- import { getLayerData } from "@/utils/getLayerDataAndCreateFeatures";
- import { createLayer } from "@/utils/ol_plugins/layer_control";
- export default {
- data() {
- return {
- TDT_Mercator: {
- vector_layer: { id: "vec_w", layer_id: "vec" },
- vector_layer_annotation: { id: "cva_w", layer_id: "cva" },
- raster_layer: { id: "img_w", layer_id: "img" },
- raster_layer_annotation: { id: "cia_w", layer_id: "cia" },
- topography_layer: { id: "ter_w", layer_id: "ter" },
- topography_layer_annotation: { id: "cta_w", layer_id: "cta" },
- national_boundary: { id: "ibo_w", layer_id: "ibo" },
- },
- TDT_lnglat: {
- vector_layer: { id: "vec_c", layer_id: "vec" },
- vector_layer_annotation: { id: "cva_c", layer_id: "cva" },
- raster_layer: { id: "img_c", layer_id: "img" },
- raster_layer_annotation: { id: "cia_c", layer_id: "cia" },
- topography_layer: { id: "ter_c", layer_id: "ter" },
- topography_layer_annotation: { id: "cta_c", layer_id: "cta" },
- national_boundary: { id: "ibo_c", layer_id: "ibo" },
- },
- TDT_layer_common_config: {
- SERVICE: "WMTS",
- REQUEST: "GetTile",
- VERSION: "1.0.0",
- STYLE: "default",
- TILEMATRIXSET: "w",
- TILEMATRIX: "{z}",
- TILEROW: "{y}",
- TILECOL: "{x}",
- FORMAT: "tiles",
- },
- TDT_Mercator_common_config:
- "&SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&STYLE=default&TILEMATRIXSET=w&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=tiles",
- TDT_lnglat_common_config:
- "&SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&STYLE=default&TILEMATRIXSET=c&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&FORMAT=tiles",
- keyword: "",
- mapList: [
- {
- title: "地图",
- class: "vector",
- active: true,
- },
- {
- title: "影像",
- class: "raster",
- active: false,
- },
- {
- title: "地形",
- class: "dixing",
- active: false,
- },
- ],
- mapChangeIsShow: false,
- base_layer: null,
- base_layer_annotation: null,
- national_boundary: null,
- };
- },
- components: {},
- created() { },
- mounted() {
- let that = this;
- var mousePositionControl = new MousePosition({
- coordinateFormat: createStringXY(6),
- projection: "EPSG:4326",
- className: "custom-mouse-position",
- target: document.getElementById("mouse-position"),
- undefinedHTML: " ",
- });
- let rotate = new Rotate({
- autoHide: true,
- label: "N",
- });
- let zoom = new Zoom({ target: undefined, delta: 1 });
- let scaleLine = new ScaleLine();
- let fullScreen = new FullScreen();
- // e90d56e5a09d1767899ad45846b0cefd
- let center = transform(
- [systemConfig.mapDefault.center.lng, systemConfig.mapDefault.center.lat],
- "EPSG:4326",
- "EPSG:3857"
- );
- let view = new View({
- center: center,
- zoom: systemConfig.mapDefault.zoom,
- constrainResolution: true, // 以整数级别缩放地图
- });
- that.$store.commit("setMouseLocation", [
- systemConfig.mapDefault.center.lng,
- systemConfig.mapDefault.center.lat,
- ]);
- that.$store.commit("setZoom", systemConfig.mapDefault.zoom);
- let map = new Map({
- target: "map", //地图标签id
- logo: false,
- controls: defaults({
- attribution: false,
- zoom: false,
- rotate: false,
- }),
- //.extend([scaleLine, fullScreen]),
- view: view,
- });
- globalVariable.map = map;
- globalVariable.map.getLayerById = function (id) {
- let arr = this.getLayers()
- .getArray()
- .filter(function (layer) {
- return layer.id == id || layer.values_.id == id;
- });
- if (arr.length == 0) {
- return null;
- } else if (arr.length < 2) {
- return arr[0];
- } else {
- throw "Layer ID repeat";
- }
- };
- // // 监听鼠标经纬度
- // map.on("pointermove", function (e) {
- // let lonlat = transform(e.coordinate, "EPSG:3857", "EPSG:4326");
- // that.$store.commit("setMouseLocation", [
- // Number(lonlat[0].toFixed(6)),
- // Number(lonlat[1].toFixed(6)),
- // ]);
- // });
- // // 监听地图变化时,缩放级别
- // map.getView().on("change:center", function (e) {
- // let lonlat = transform(globalVariable.map.getView().getCenter(), "EPSG:3857", "EPSG:4326");
- // that.$store.commit("setMouseLocation", [
- // Number(lonlat[0].toFixed(6)),
- // Number(lonlat[1].toFixed(6)),
- // ]);
- // });
- // map.getView().on("change", function (e) {
- // that.$store.commit("setZoom", e.target.getZoom());
- // });
- // // 图层选中事件
- // this.selectSingleClick = new Select();
- // globalVariable.map.addInteraction(this.selectSingleClick);
- // this.selectSingleClick.on("select", function (selectEvent) {
- // let selectSingleClickFeatures = that.selectSingleClick.getFeatures();
- // let selected = selectEvent.selected[0];
- // if (!selected) return;
- // if (selectEvent.target.getLayer(selectEvent.selected[0]) != null) {
- // switch (selectEvent.target.getLayer(selectEvent.selected[0]).values_.name) {
- // case "singlepoint":
- // if (selected.values_.callback) {
- // selected.values_.callback(selected, selectSingleClickFeatures);
- // return;
- // }
- // selectSingleClickFeatures.clear();
- // break;
- // case "cluster":
- // if (!selected.values_.features) {
- // selectSingleClickFeatures.clear();
- // break;
- // }
- // if (selected.values_.features.length == 1) {
- // let newFeature = selected.values_.features[0];
- // if (newFeature.values_.callback) {
- // newFeature.values_.callback(
- // newFeature,
- // selectSingleClickFeatures
- // );
- // } else {
- // selectSingleClickFeatures.clear();
- // return;
- // }
- // } else {
- // // TODO 缩放级别
- // globalVariable.map.getView().fit(
- // new VectorSource({
- // features: selected.values_.features,
- // }).getExtent()
- // );
- // selectSingleClickFeatures.clear();
- // return;
- // }
- // break;
- // case "heatmap":
- // return;
- // break;
- // default:
- // if (selected.values_.callback) {
- // selected.values_.callback(selected, selectSingleClickFeatures);
- // }
- // selectSingleClickFeatures.clear();
- // break;
- // }
- // } else {
- // selectSingleClickFeatures.clear();
- // }
- // });
- this.changeMap(this.mapList[0]);
- // this.loadRegionBoundary();
- // if (!this.$root.popup) {
- // this.$root.popup_container = $("#popup");
- // this.$root.popup_content = $("#popup-content");
- // this.$root.popup_title = $("#popup-title");
- // this.$root.popup_closer = $("#popup-closer");
- // this.$root.popup_closer.bind("click", this.popupcloseEvent);
- // this.$root.popup = new Overlay({
- // element: this.$root.popup_container[0],
- // autoPan: true,
- // autoPanMargin: 100,
- // positioning: "center-right",
- // });
- // globalVariable.map.addOverlay(this.$root.popup);
- // this.$root.popup_setPositionAndRelocation = function (position) {
- // that.$root.popup.setPosition(position);
- // let height = 0 - 70 - that.$root.popup_content.height();
- // that.$root.popup_container.css({
- // transform: " translate(-50%, " + height + "px)",
- // });
- // };
- // // 初始化
- // this.$root.popup.setPosition(undefined);
- // // 地图点击事件
- // map.on("click", function (e) {
- // that.$root.popup.setPosition(undefined);
- // });
- // }
- },
- methods: {
- // // overlay 关闭
- // popupcloseEvent() {
- // this.$root.popup.setPosition(undefined);
- // return false;
- // },
- getCompleteUrl(param) {
- let url =
- systemConfig.tdt_url +
- "/" +
- param.id +
- "/wmts?" +
- "tk=" +
- systemConfig.tdt_tk +
- "&LAYER=" +
- param.layer_id +
- this.TDT_Mercator_common_config;
- return url;
- },
- addLayerToMap(url, title) {
- let layer = new Tile({
- title: title,
- source: new XYZ({ url: url }),
- zIndex: 0,
- });
- globalVariable.map.addLayer(layer);
- return layer;
- },
- removeLayerToMap(layer) {
- globalVariable.map.removeLayer(layer);
- },
- changeMap(item) {
- this.mapList = this.mapList.map(function name(item_) {
- if (item_.class != item.class) {
- item_.active = false;
- } else {
- item_.active = true;
- }
- return item_;
- });
- this.addBaseLayer(item);
- },
- addBaseLayer(item) {
- if (this.base_layer) {
- this.removeLayerToMap(this.base_layer);
- }
- if (this.base_layer_annotation) {
- this.removeLayerToMap(this.base_layer_annotation);
- }
- if (this.national_boundary) {
- this.removeLayerToMap(this.national_boundary);
- }
- switch (item.class) {
- case "vector":
- this.base_layer = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.vector_layer)
- ); // 天地图 底图
- this.base_layer_annotation = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.vector_layer_annotation)
- ); // 天地图 国境线
- this.national_boundary = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.national_boundary)
- ); // 天地图 底图对应注记
- globalVariable.map.getView().setMaxZoom(18);
- break;
- case "raster":
- this.base_layer = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.raster_layer)
- ); // 天地图 底图
- this.base_layer_annotation = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.raster_layer_annotation)
- ); // 天地图 国境线
- this.national_boundary = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.national_boundary)
- ); // 天地图 底图对应注记
- globalVariable.map.getView().setMaxZoom(18);
- break;
- case "dixing":
- this.base_layer = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.topography_layer)
- ); // 天地图 底图
- this.base_layer_annotation = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.topography_layer_annotation)
- ); // 天地图 国境线
- this.national_boundary = this.addLayerToMap(
- this.getCompleteUrl(this.TDT_Mercator.national_boundary)
- ); // 天地图 底图对应注记
- globalVariable.map.getView().setMaxZoom(14);
- break;
- default:
- break;
- }
- },
- loadRegionBoundary() {
- const boundary_style = function (feature) {
- let default_style = new Style({
- stroke: new Stroke({
- color: "rgba(50, 164, 220, 1)",
- width: 3,
- }),
- fill: new Fill({
- color: "rgba(50, 164, 220, 0.1)",
- }),
- });
- return default_style;
- };
- const diming_textStyle = new Style({
- text: new Text({
- // 字体与大小
- font: "16px Microsoft YaHei",
- //文字填充色
- fill: new Fill({
- color: "rgba(50, 164, 220, 1)",
- }),
- //文字边界宽度与颜色
- stroke: new Stroke({
- color: "#fff",
- width: 2,
- }),
- // 显示文本,数字需要转换为文本string类型!
- /*text: "" + vectorSource.features.values_.limitvalue + "",*/
- offsetX: 0,
- offsetY: 0,
- }),
- });
- let that = this;
- const styleCallback = function (feature) {
- const limitvalue = feature.values_.Name;
- if (
- limitvalue != null &&
- limitvalue != undefined &&
- limitvalue.length > 0
- ) {
- diming_textStyle.getText().setText("" + limitvalue + "");
- }
- return diming_textStyle;
- };
- let province_boundary = this.geojsonSource(
- "../static/data/sheng.geojson"
- );
- let province_text = this.geojsonSource("../static/data/shengD.geojson");
- let city_boundary = this.geojsonSource("../static/data/shi.geojson");
- let city_text = this.geojsonSource("../static/data/shiD.geojson");
- let country_boundary = this.geojsonSource("../static/data/xian.geojson");
- let country_text = this.geojsonSource("../static/data/xianD.geojson");
- let province_boundary_layer = this.geojsonLayer(
- "province_boundary",
- province_boundary,
- boundary_style,
- 1,
- 7
- );
- let province_text_layer = this.geojsonLayer(
- "province_text",
- province_text,
- styleCallback,
- 1,
- 7
- );
- let city_boundary_layer = this.geojsonLayer(
- "city_boundary",
- city_boundary,
- boundary_style,
- 7,
- 9
- );
- let city_text_layer = this.geojsonLayer(
- "city_text",
- city_text,
- styleCallback,
- 7,
- 9
- );
- let country_boundary_layer = this.geojsonLayer(
- "country_boundary",
- country_boundary,
- boundary_style,
- 9,
- 18
- );
- let country_text_layer = this.geojsonLayer(
- "country_text",
- country_text,
- styleCallback,
- 9,
- 18
- );
- globalVariable.map.addLayer(province_boundary_layer);
- globalVariable.map.addLayer(province_text_layer);
- globalVariable.map.addLayer(city_boundary_layer);
- globalVariable.map.addLayer(city_text_layer);
- globalVariable.map.addLayer(country_boundary_layer);
- globalVariable.map.addLayer(country_text_layer);
- },
- geojsonSource(url) {
- return new VectorSource({
- projection: "EPSG:4326",
- url: url,
- format: new GeoJSON(),
- });
- },
- geojsonLayer(id, source, style, minZoom, maxZoom) {
- return new VectorLayer({
- id: id,
- source: source,
- style: style,
- minZoom: minZoom,
- maxZoom: maxZoom,
- zIndex: 1,
- });
- },
- // loadDefaultLayer() {
- // let that = this,
- // type = 0;
- // if (
- // this.urlParam.modelId == "" ||
- // this.urlParam.modelId == null ||
- // this.urlParam.modelId == undefined
- // ) {
- // return;
- // }
- // if (!isNaN(Number(this.urlParam.showType))) {
- // if (
- // Number(this.urlParam.showType) < 0 ||
- // Number(this.urlParam.showType) > 3
- // ) {
- // type = 0;
- // } else {
- // type = Number(this.urlParam.showType);
- // }
- // } else {
- // type = 0;
- // }
- // let layerType = "singlepoint";
- // switch (type) {
- // case 0:
- // layerType = "singlepoint";
- // break;
- // case 1:
- // layerType = "aggregation";
- // break;
- // case 2:
- // layerType = "heatmap";
- // break;
- // default:
- // break;
- // }
- // // 根据类型加载;
- // api
- // .getModelByID({ id: this.urlParam.modelId })
- // .then((result) => {
- // if (result.code == 200) {
- // that.searchData(result.content, layerType);
- // } else {
- // that.$message({
- // type: "warning",
- // message: result.message,
- // });
- // }
- // })
- // .catch((err) => {
- // that.$message({
- // type: "warning",
- // message: "服务器异常,请稍后重试!",
- // });
- // });
- // },
- searchData(content, layerType) {
- let that = this;
- // 上传loading
- const loading = this.$createLoading("数据获取中,请稍后!")
- getLayerData(content, this.setPopup, loading)
- .then((result) => {
- let source = new VectorSource();
- source.addFeatures(result);
- that.addDifferentLayer(content, layerType, source);
- })
- .catch((err) => {
- that.$message({
- type: "warning",
- message: err,
- });
- });
- },
- // 设置 popup
- setPopup(properties, position) {
- let that = this;
- that.$root.popup_content.html(
- `<div>名称:${properties.title}</div>
- <div>类别:${properties.classify}</div>
- <div>详情:${properties.content}</div>
- `
- );
- that.$root.popup_setPositionAndRelocation(position);
- },
- // 地图 加载 不同图层
- addDifferentLayer(item, layerType, source) {
- let layer = createLayer(item, layerType, source, this.$store.state.token);
- globalVariable.map.addLayer(layer);
- globalVariable.map.getView().fit(source.getExtent());
- },
- },
- computed: {
- // urlParam() {
- // return this.$store.state.urlParams;
- // },
- },
- watch: {},
- };
- </script>
- <style lang="less" scoped>
- #map {
- width: 100%;
- height: 100%;
- position: absolute;
- /deep/ .ol-zoom {
- top: inherit;
- left: inherit;
- bottom: 60px;
- right: 20px;
- .ol-zoom-in,
- .ol-zoom-out {
- width: 30px;
- height: 30px;
- font-size: 24px;
- }
- }
- /deep/ .ol-scale-line {
- top: unset;
- left: unset;
- // bottom: 60px;
- left: 20px;
- }
- .changeBaseMap {
- position: absolute;
- top: 90px;
- right: 20px;
- z-index: 2;
- }
- .changeBaseMap > .container {
- width: 40px;
- height: 40px;
- cursor: pointer;
- border-radius: 4px;
- overflow: hidden;
- > p {
- width: 30px;
- height: 30px;
- margin: 5px 5px;
- background-position-x: center;
- background-position-y: center;
- background-repeat: no-repeat;
- background-image: url(~@/assets/images/tool/mapchange1.png);
- &:hover,
- &.active {
- background-image: url(~@/assets/images/tool/mapchange_active1.png);
- }
- }
- .mapChangeIsShow {
- position: absolute;
- top: -5px;
- left: calc(-234px - 10px - 12px - 10px);
- }
- .mapChangeIsShow > .container {
- width: calc(234px + 12px);
- height: 100%;
- border-radius: 4px;
- ul {
- width: fit-content;
- height: fit-content;
- }
- li {
- position: relative;
- display: inline-block;
- .bg {
- width: 68px;
- height: 63px;
- margin: 5px 5px;
- border: 2px solid #ffffff;
- background-position-x: center;
- background-position-y: center;
- background-size: 100% 100%;
- background-repeat: no-repeat;
- &:hover {
- border: 2px solid #c9c9c9;
- }
- &.active {
- border: 2px solid #00a9f9;
- span {
- background: #00a9f9b3;
- }
- }
- &.vector {
- background-image: url(~@/assets/images/maptype/xianhua.png);
- }
- &.raster {
- background-image: url(~@/assets/images/maptype/raster.png);
- }
- &.dixing {
- background-image: url(~@/assets/images/maptype/dixing.png);
- }
- }
- span {
- position: absolute;
- bottom: 5px;
- padding: 2px 5px;
- text-align: center;
- color: #ffffff;
- background: #00000080;
- }
- }
- }
- }
- }
- </style>
|