123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <template>
- <view id="container" class="" :prop="maplist" :change:prop="mapModule.addGeoJson" :item="mapitem"
- :change:item="mapModule.flyto">
- </view>
- </template>
- <script>
- export default {
- props: {
-
-
-
-
- },
- data() {
- return {
- maps: {},
- maplist: [],
- mapitem: {},
- };
- },
- mounted() {
-
- },
- methods: {
- setlist(list) {
- console.log(list, 'list')
- this.maplist = list
- },
- setitem(val) {
- console.log(val, 'val')
- if(val)this.mapitem = val
- },
- }
- }
- </script>
- <script module="mapModule" lang="renderjs">
-
- import "ol/ol.css";
- import {
- transform
- } from "ol/proj.js";
- import Map from "ol/Map";
- import View from "ol/View";
-
- import XYZ from "ol/source/XYZ";
- import Tile from "ol/layer/Tile";
- import OSM from 'ol/source/OSM';
- import parse from "wellknown";
- import VectorLayer from "ol/layer/Vector";
- import VectorSource from "ol/source/Vector";
- import {
- Style,
- Icon
- } from "ol/style";
- import Stroke from "ol/style/Stroke";
- import GeoJSON from "ol/format/GeoJSON";
- let map = null;
- export default {
- name: "map-view",
- data() {
- return {
- maps: {},
- vectorLayer: {},
- curPageResultLayer: {}
- };
- },
- mounted() {
- this.createMap();
- },
- methods: {
- createMap() {
- var view = new View({
- center: transform([116.40, 39.91], "EPSG:4326", "EPSG:3857"),
- projection: "EPSG:3857",
- zoom: 15,
- minZoom: 2,
- maxZoom: 18
- });
- this.addMap("container", view);
- },
- addMap(target, view) {
- if (this.maps[target]) return;
- var key = "12df6e32906dbb916fad14dc65ebdbf8";
-
- var vecLayer = new Tile({
- source: new XYZ({
-
-
- url: "http://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=" +
- key,
- }),
- });
-
- var cvaLayer = new Tile({
- source: new XYZ({
- url: "http://t0.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=" +
- key,
- }),
- });
- var lyr = new Tile({
- source: new XYZ({
-
- url: "../doc/tiles/{z}/{x}/{-y}.png"
- }),
- });
- let map = new Map({
-
- target,
-
- layers: [vecLayer, cvaLayer, lyr],
-
- view,
- });
- this.maps[target] = map;
-
-
- this.initVectorLayer()
-
-
- },
- getMap() {
- return this.maps
- },
- initVectorLayer(name = 'container') {
- if (!this.vectorLayer[name]) {
- let vectorSource = new VectorSource({
-
- });
- this.vectorLayer[name] = new VectorLayer({
- source: vectorSource,
- style: new Style({
- stroke: new Stroke({
- color: "#f00",
- width: 2,
- }),
- }),
- });
- this.maps[name].addLayer(this.vectorLayer[name]);
- }
- if (!this.curPageResultLayer[name]) {
- let vectorSource = new VectorSource();
- this.curPageResultLayer[name] = new VectorLayer({
- source: vectorSource,
- zIndex: 999,
- style: new Style({
- stroke: new Stroke({
- color: "#1f1cd3",
- width: 2,
- }),
- }),
- });
- this.maps[name].addLayer(this.curPageResultLayer[name]);
- }
- },
-
- addGeoJson(maplist, ) {
- maplist.forEach((titem, i) => {
- if (titem.geom && titem.geom != "") {
- if (typeof titem.geom === "string") {
- titem.geom = parse(titem.geom);
- }
- let features = new GeoJSON().readFeatures(titem.geom, {
- dataProjection: "EPSG:4326",
- featureProjection: "EPSG:3857"
- });
- var tempName = name + i;
- this.curPageResultLayer[tempName] = new VectorLayer({
- source: new VectorSource({
- features: features,
- }),
- style: function(feature) {
- return new Style({
- stroke: new Stroke({
-
- color: "rgba(0, 0, 255, 1)",
- width: 2,
- }),
- });
- },
- zIndex: 9999,
- });
- this.maps.container.addLayer(this.curPageResultLayer[tempName]);
- }
- });
- if (maplist.length) {
- this.flytoByLayer(this.curPageResultLayer[0])
- }
- },
- flyto(item) {
-
- if (!this.maps['container']) return
- this.maps['container'].getView().animate({
- center: transform([item.lzb, item.bzb], "EPSG:4326", "EPSG:3857"),
- zoom: 18,
- duration: 20,
- });
- },
- flytoByLayer(layer) {
- let fullExtent = layer
- .getSource()
- .getExtent();
- console.log('maplist', fullExtent)
- let map = this.maps.container
- map.getView().fit(fullExtent, {
- duration: 3,
- callback: null,
- size: map.getSize(),
- padding: [100, 100, 100, 100],
- constrainResolution: false,
- });
- },
- },
- };
- </script>
- <style scoped>
- #container {
- width: 100vw;
- height: 40vh;
- }
- </style>
|