1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150 |
- <template>
- <div id="mapbox">
-
- <div id="mapview" class="map" @click="basemapShow = false">
- </div>
-
- <layer-selector
- @getCheckedMap = 'getCheckedMap'
- @getCheckedTag = 'getCheckedTag'
- ></layer-selector>
-
- <div
- id='div-draw'
- v-if="isDraw"
- class='float-right'
- >
- <b-form inline>
-
- <b-button variant="danger" @click="drawEnd" >结束绘制</b-button>
- </b-form>
- </div>
-
- <div>
-
- <div id="pcPopup" class="ol-popup" v-if="this.$store.state.isMobile === false">
- <PhoneCard
- :title="popupData.info.title"
- :time="popupData.info.time"
- :info="popupData.info.content"
- :url="popupData.info.url"
- :img="popupData.info.img"
- :isMobile = "false"
- >
- </PhoneCard>
- </div>
-
- <div id="mobilePopup" v-else v-show="isShow">
- <PhoneCard
- :title="popupData.info.title"
- :time="popupData.info.time"
- :info="popupData.info.content"
- :url="popupData.info.url"
- :img="popupData.info.img"
- :isMobile = 'true'
- >
- </PhoneCard>
- </div>
- </div>
-
- <div v-if="this.$store.state.isMobile === true">
- <Slogan v-show="slogan.isShow" :slogan="slogan.content"></Slogan>
- </div>
- </div>
- </template>
- <script>
- import util from '../util'
- import 'ol/ol.css'
- import {Map, View} from 'ol'
- import * as Extent from 'ol/extent'
- import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer'
- import * as olProj from 'ol/proj'
- import {Point, MultiLineString} from 'ol/geom'
- import {defaults as defaultInteractions} from 'ol/interaction'
- import Feature from 'ol/Feature'
- import * as control from 'ol/control'
- import {Style, Icon, Stroke} from 'ol/style'
- import {Vector as VectorSource} from 'ol/source'
- import TileSource from 'ol/source/TileWMS'
- import XYZ from 'ol/source/XYZ'
- import Overlay from 'ol/Overlay'
- import bus from '../../static/js/eventBus'
- import culture from '../assets/icon/culture.svg'
- import info from '../assets/icon/info.svg'
- import report from '../assets/icon/report.svg'
- import more from '../assets/icon/more.svg'
- import DrawShape from '../../static/js/startDrawShape'
- import phoneCard from './card.vue'
- import slogan from './slogan.vue'
- import cluster from '../../static/js/clusterDisplay'
- var map = null
- export default {
- name: 'Map',
- components: {
- PhoneCard: phoneCard,
- Slogan: slogan,
- LayerSelector: () => import('./LayerSelector.vue')
- },
- data () {
- return {
- noticeStyles: {
- Point: new Style({
- image: new Icon({
- crossOrigin: 'anonymous',
- src: info,
- scale: 0.225
- })
- }),
- LineString: new Style({
- stroke: new Stroke({
- color: '#ff8c42',
- width: 6
- })
- })
- },
- reportStyles: {
- Point: new Style({
- image: new Icon({
- crossOrigin: 'anonymous',
- src: report,
- scale: 0.25
- })
- }),
- LineString: new Style({
- stroke: new Stroke({
- color: '#2953a5',
- width: 6
- })
- })
- },
- cultureStyles: {
- Point: new Style({
- image: new Icon({
- crossOrigin: 'anonymous',
- src: culture,
- scale: 0.225
- })
- }),
- LineString: new Style({
- stroke: new Stroke({
- color: '#f51a51',
- width: 6
- })
- })
- },
- otherStyles: {
- Point: new Style({
- image: new Icon({
- crossOrigin: 'anonymous',
- src: more,
- scale: 0.25
- })
- }),
- LineString: new Style({
- stroke: new Stroke({
- color: '#f51a51',
- width: 6
- })
- })
- },
-
- popup: null,
- popupData: {
- type: '',
- info: ''
- },
-
- isShow: false,
-
- isDraw: false,
-
- drawTypeOption: ['线', '点'],
-
- drawType: '线',
-
- drawColor: '#585eaa',
-
- checkTagList: [],
- checkMapList: [],
-
- slogan: {
- isShow: true,
- content: ''
- }
- }
- },
- methods: {
-
- initMap: function () {
-
- let leftTop = [104.134737921, 30.6924231322]
- let rightBottom = [104.155317192, 30.6466570878]
- rightBottom = this.getExtentFromPNG(leftTop, rightBottom)
- leftTop = olProj.fromLonLat(leftTop)
- rightBottom = olProj.fromLonLat(rightBottom)
-
- const MOBILE = [leftTop[0], rightBottom[1], rightBottom[0], leftTop[1]]
-
- const PC = [11591064, 3589994, 11596565, 3592078]
- let extent = this.$store.state.isMobile ? MOBILE : PC
- let center = [
- (extent[0] + extent[2]) / 2,
- (extent[1] + extent[3]) / 2
- ]
-
-
-
-
- let zoom = this.$store.state.isMobile ? 14.5 : 15.5
- map = new Map({
- target: 'mapview',
- layers: [
-
- new TileLayer({
- class: 'basemap',
- title: 'tiandi',
- source: new XYZ({
- url: 'http://t3.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=a7baca459fe5be059d34849072e84fd0'
- }),
- visible: true
-
- }),
-
- new TileLayer({
- class: 'basemap',
- title: 'tiandi',
- source: new XYZ({
- url: 'http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=a7baca459fe5be059d34849072e84fd0'
- }),
- visible: true
-
- }),
-
- new TileLayer({
- class: 'basemap',
- title: 'cdut',
- source: new TileSource({
- url: 'http://cn-gz-ali-1.sakurafrp.com:10265/geoserver/CDUT/wms',
- crossOrigin: 'anonymous',
- params: {
- LAYERS: 'cdut_920',
- TILED: true
- },
- servertype: 'geoserver',
- transition: 0
- })
-
- })
- ],
- interactions: defaultInteractions({
- pinchRotate: false
- }),
- view: new View({
- center: center,
- zoom: zoom,
- extent: extent,
- maxZoom: 18.5
- }),
-
-
-
- controls: control.defaults().extend([
-
- ])
- })
- map.updateSize()
- },
-
- getExtentFromPNG: function (leftTop, rightBot) {
-
- let width = window.screen.width
- let height = window.screen.height
-
-
- let imgTop = leftTop[1]
- let imgRight = rightBot[0]
- let imgBottom = rightBot[1]
-
-
- let imgHeightratio = 20
-
-
- let screenHeightratio = 9 * height / width
-
- let screenRight = imgRight
- let screenBottom = imgTop - (imgTop - imgBottom) * (screenHeightratio / imgHeightratio)
-
-
- let screenRightbottom = [screenRight, screenBottom]
- return screenRightbottom
- },
-
- initPopupOverLay: function () {
- var container = document.getElementById('pcPopup')
- this.popup = new Overlay({
- element: container,
- autoPan: true,
- autoPanAnimation: {
- duration: 250
- }
- })
- map.addOverlay(this.popup)
- },
-
- printFeature: function (title, msg, type, isRefresh = false, isLocate = false, isRelate = false) {
-
- var layer = this.getLayerByTitle(title)
- if (layer !== null) {
-
- if (isRefresh) {
- layer.getSource().clear()
- }
- } else {
-
- layer = new VectorLayer({
- title: title,
- class: 'layer',
- className: title,
- source: new VectorSource({
- })
- })
- map.addLayer(layer)
- }
-
- var geometry = msg.geometry
- var style
- switch (type) {
- case 'notice':
- style = this.noticeStyles
- break
- case 'report':
- style = this.reportStyles
- break
- case 'culture':
- style = this.cultureStyles
- break
- case 'other':
- style = this.otherStyles
- break
- }
- var feature = this.GeoJSON_to_Feature(geometry, style)
-
- feature.set('id', msg.id)
- feature.set('type', type)
-
-
- layer.getSource().addFeature(feature)
-
- let fe = null
- if (isRelate && msg.relate) {
- fe = this.GeoJSON_to_Feature(msg.relate, style)
- fe.set('id', msg.id)
- fe.set('type', type)
- layer.getSource().addFeature(fe)
- }
-
- if (isLocate) {
- let locatedFeature = feature
- let feaType = 'origin'
- if (isRelate && msg.relate) {
- locatedFeature = fe
- feaType = 'relate'
- }
- this.locateAtFeature(locatedFeature, feaType)
- }
- },
-
- GeoJSON_to_Feature: function (geometry, styles) {
- if (!geometry.type) {
- console.log('printFromGeoJSON 所输入的GeoJSON不符合规范')
- return
- }
- var feature = null
-
- switch (geometry.type) {
- case 'Point':
- feature = new Feature({
- geometry: new Point(olProj.fromLonLat(geometry.coordinates, 'EPSG:3857')),
- shape: geometry.type
- })
- feature.setStyle(styles.Point)
- break
- case 'MultiLineString':
-
-
-
-
-
-
-
-
- let coords = []
-
- geometry.coordinates.forEach(i => {
-
- let co = i.map(x => {
- x = olProj.fromLonLat(x, 'EPSG:3857')
- return x
- })
- coords.push(co)
- })
- feature = new Feature({
- geometry: new MultiLineString(coords),
- shape: geometry.type
- })
- feature.setStyle(styles.LineString)
- break
- default:
- console.log('printFromGeoJSON不支持该"' + geometry.type + '"类型')
- return
- }
- return feature
- },
-
- Feature_to_GeoJSon: function (feature) {
- let baseType = feature[0].type
-
-
- let isMulti = feature.length > 1 ? true : false
-
- isMulti = baseType === 'LineString' ? true : false
- if (isMulti) {
- let type = 'MultiLineString'
- let coords = []
-
- feature.forEach(i => {
- i = i.coordinates
-
- let co = i.map(x => {
- x = olProj.toLonLat(x)
- return x
- })
- coords.push(co)
- })
- return {
- type: type,
- coordinates: coords
- }
- } else {
- let coord = feature[0].coordinates
- switch (baseType) {
- case 'LineString':
- coord = coord.map(x => {
- x = olProj.toLonLat(x)
- return x
- })
- break
- case 'Point':
- coord = olProj.toLonLat(coord)
- break
- }
- return {
- type: baseType,
- coordinates: coord
- }
- }
- },
-
- locateAtFeature: function (feature, type, zoom = 17) {
- let view = map.getView()
- view.setZoom(zoom)
- if (this.$store.state.isMobile && type !== 'relate') {
- let coord = Extent.getCenter(feature.getGeometry().getExtent())
- coord[1] = coord[1] * 1.00008
- view.setCenter(coord)
- } else {
- view.setCenter(Extent.getCenter(feature.getGeometry().getExtent()))
- }
- if (type === 'relate') {
- view.setZoom(zoom * 0.975)
- }
- },
-
- loadRecentReports: function (day) {
- var that = this
- this.$axios
- .post('/report/recent', {
- day: day
- })
- .then(res => {
- res.data.forEach(item => {
- that.printFeature('reportLayer', item, 'report')
- })
- })
- },
-
- loadRecentNotices: function (day) {
- var that = this
- this.$axios
- .post('/notice/recent', {
- day: day
- })
- .then(res => {
- res.data.forEach(item => {
- that.printFeature('noticeLayer', item, 'notice')
- })
- })
- },
-
- loadCulture: function () {
- var that = this
- this.$axios
- .post('/culture/all')
- .then(res => {
- res.data.forEach(e => {
- that.printFeature('cultureLayer', e, 'culture')
- })
- })
- },
-
- loadOthers: function () {
- var that = this
- this.$axios
- .post('/others/all')
- .then(res => {
- res.data.forEach(e => {
- that.printFeature('otherLayer', e, 'other')
- })
- })
- },
-
- mapClick: function () {
- var that = this
-
- var clickFun = this.$store.state.isMobile ? mobileClickFun : pcClickFun
- map.on('singleclick', clickFun)
- async function mobileClickFun (e) {
- var feature = map.forEachFeatureAtPixel(e.pixel, function (feature) {
- return feature
- })
- if (feature) {
- var id = feature.get('id')
- let type = feature.get('type')
- let data = null
- switch (type) {
- case 'notice':
- data = await that.loadNoticeByID(id)
- break
- case 'report':
- data = await that.loadReportByID(id)
- break
- case 'culture':
- data = await that.loadCultureByID(id)
- break
- case 'other':
- data = await that.loadOthersByID(id)
- break
- }
- that.printFeature('markLayer', data, type, true, true, true)
- that.isShow = true
- bus.$emit('closeList')
- } else {
- that.closePopup()
- }
- }
- async function pcClickFun (e) {
-
- var feature = map.forEachFeatureAtPixel(e.pixel, feature => {
- return feature
- })
- if (feature) {
- bus.$emit('printMapMark', {
- type: feature.get('type'),
- id: feature.get('id')
- })
- } else {
- that.closePopup()
- }
- }
- },
-
- getLayerByTitle: function (title) {
- var layers = map.getLayers().array_
- for (let i = 0; i < layers.length; i++) {
- if (layers[i].get('title') === title) {
- return layers[i]
- } else {
- continue
- }
- }
- return null
- },
-
- loadReportByID: async function (id) {
- var that = this
- var res
- await this.$axios
- .post('/report/detail', {
- id: id
- })
- .then(response => {
- that.popupData.info = response.data
- that.popupData.type = '新闻报道'
- res = response.data
- })
- return res
- },
-
- loadNoticeByID: async function (id) {
- var that = this
- var res
- await this.$axios
- .post('/notice/detail', {
- id: id
- })
- .then(response => {
- that.popupData.info = response.data
- that.popupData.type = '活动通知'
- res = response.data
- })
- return res
- },
-
- loadCultureByID: async function (id) {
- var that = this
- var res
- await this.$axios
- .post('/culture/detail', {
- id: id
- })
- .then(response => {
- response.data.content = response.data.content.join('')
- that.popupData.info = response.data
- that.popupData.type = '文化设施'
- res = response.data
- })
- return res
- },
-
- loadOthersByID: async function (id) {
- var that = this
- var res
- await this.$axios
- .post('/others/detail', {
- id: id
- })
- .then(response => {
- that.popupData.info = response.data
- that.popupData.type = '活动通知'
- res = response.data
- res = response.data
- })
- return res
- },
-
- setPopupPosition: function (coordinate, zoom = 18) {
- this.popup.setPosition(coordinate)
- this.isShow = true
- var view = map.getView()
- view.setCenter(coordinate)
-
- },
-
- closePopup: function (dom) {
- if (this.$store.state.isMobile) {
- this.isShow = false
- } else {
- this.popup.setPosition(undefined)
- this.isShow = false
-
- if (dom) {
- dom.blur()
- }
- }
- return false
- },
-
- drawBegin: function () {
-
- this.isDraw = true
- let col = this.drawColor
- switch (this.drawType) {
- case '点':
- DrawShape.drawPoint(col, map)
- break
- case '线':
- DrawShape.drawLine(col, map)
- break
- }
- },
-
- drawEnd: function () {
- this.isDraw = false
- let data = DrawShape.closeDrawShape()
- if (data.length !== 0) {
- data = this.Feature_to_GeoJSon(data)
- } else {
- data = null
- }
- switch (this.drawType) {
- case '点':
- bus.$emit('drawGeometryEnd', data)
- break
- case '线':
- bus.$emit('drawRelateEnd', data)
- break
- }
- },
-
- basemapChange: function (name) {
- switch (name) {
- case 'all':
- this.setMapVisible(['cdut', 'tiandi', 'tiandi-label'])
- break
- case 'cdut':
- this.setMapVisible(['cdut'])
- break
- case 'tiandi':
- this.setMapVisible(['tiandi', 'tiandi-label'])
- break
- }
- },
-
- setMapVisible: function (titles) {
- var layers = map.getLayers().array_
- for (var i = 0; i < layers.length; i++) {
- if (layers[i].values_.class !== 'basemap') {
- continue
- }
- if (titles.indexOf(layers[i].values_.title) > -1) {
- layers[i].setVisible(true)
- } else {
- layers[i].setVisible(false)
- }
- }
- },
-
-
- getCheckedMap: function (checkMapList) {
- this.checkMapList = checkMapList
- util.map.setMapVisible(map, checkMapList, 'basemap')
- },
- getCheckedTag: function (checkTagList) {
- this.checkTagList = checkTagList
- util.map.setMapVisible(map, checkTagList, 'layer')
- },
-
- sloganListener: function () {
- var that = this
-
- var mapDiv = document.getElementById('mapview')
-
-
- function onMouseWheel (ev) {
- window.setTimeout(function () {
- let zoom = map.getView().getZoom()
- console.log('zoom:' + zoom)
- if (zoom > 15.3) {
-
- that.slogan.isShow = false
- } else {
-
- that.slogan.isShow = true
- }
-
- if (ev.preventDefault) {
- ev.preventDefault()
- }
- return false
- }, 500)
- }
- addEvent(mapDiv, 'mousewheel', onMouseWheel)
- addEvent(mapDiv, 'DOMMouseScroll', onMouseWheel)
- function addEvent (obj, xEvent, fn) {
- if (obj.attachEvent) {
- obj.attachEvent('on' + xEvent, fn)
- } else {
- obj.addEventListener(xEvent, fn, false)
- }
- }
- },
-
- openCluster: function () {
- cluster.openNoticeLayerCluster(info, map)
- cluster.openReportLayerCluster(report, map)
- cluster.openCultureLayerCluster(culture, map)
- cluster.openOtherLayerCluster(more, map)
- },
-
- busOnAction: function () {
- var that = this
-
- bus.$on('showReportDetail', async id => {
- that.loadReportByID(id)
- .then(res => {
- that.printFeature('markLayer', res, 'report', true, true, true)
- that.isShow = true
- })
- })
-
- bus.$on('printMapMark', async msg => {
- let data
- let id = msg.id
- switch (msg.type) {
- case 'notice':
- await that.loadNoticeByID(id)
- .then(res => {
- data = res
- })
- break
- case 'report':
- await that.loadReportByID(id)
- .then(res => {
- data = res
- })
- break
- case 'culture':
- await that.loadCultureByID(id)
- .then(res => {
- data = res
- })
- break
- case 'other':
- await that.loadOthersByID(id)
- .then(res => {
- data = res
- })
- break
- }
- that.printFeature('markLayer', data, msg.type, true, true, true)
-
- var feature = that.getLayerByTitle('markLayer').getSource().getFeatures()[0]
- var coord = feature.getGeometry().getCoordinates()
- that.setPopupPosition(coord)
- })
-
- bus.$on('refreshMap', () => {
- map.removeLayer(that.getLayerByTitle('noticeLayer'))
- map.removeLayer(that.getLayerByTitle('reportLayer'))
- map.removeLayer(that.getLayerByTitle('cultureLayer'))
- map.removeLayer(that.getLayerByTitle('otherLayer'))
- map.removeLayer(that.getLayerByTitle('markLayer'))
- that.loadRecentNotices(7)
- that.loadRecentReports(7)
- that.loadCulture()
- that.loadOthers()
- that.closePopup()
- })
-
- bus.$on('drawBegin', type => {
- that.drawType = type
- that.drawBegin(type)
- })
-
- bus.$on('closePopup', () => {
- that.closePopup()
- })
- }
- },
- mounted () {
- this.initMap()
- this.initPopupOverLay()
- this.busOnAction()
- this.loadRecentReports(7)
- this.loadRecentNotices(7)
- this.loadOthers()
- this.loadCulture()
- this.openCluster()
- this.mapClick()
- this.sloganListener()
- },
- watch: {
- drawType: function () {
- DrawShape.closeDrawShape()
- this.drawBegin()
- },
- isShow: function () {
- if (this.isShow === true) {
- this.slogan.isShow = false
- }
- }
- },
- filters: {
-
- ellipsis: function (value) {
- if (!value) return ''
- if (value.length > 70) {
- return value.slice(0, 70) + '...'
- }
- return value
- }
- }
- }
- </script>
- <style scoped>
- #mapview{
- width: 100%;
- height: 100%;
- position: absolute;
-
- }
- #div-draw {
- position: absolute;
- left: 50%;
- top:2px;
- z-index: 100;
- background: white;
- border-radius: 5px;
- padding: 10px 10px 10px 10px;
- border: 1px solid gray;
- transform: translateX(-50%);
- }
- #basemap-content {
- position: absolute;
- font-size: 12px;
- z-index: 100;
- background: rgba(255, 255, 255, 0.7);
- opacity: 0.95;
- right: 0px;
- margin-top: 40px;
- height: 50px;
- width:65px;
- align-content: center;
- }
- .basemap-item {
- padding: 5px;
- cursor: pointer;
- }
- .basemap-text,.online-map-text{
- width: 60px;
- height: 12px;
- }
- .basemap-text{
- color: #007bff;
- font-weight: bold;
- font-family: "Source Han Sans CN";
- }
- .info-select-button {
- width: 22px;
- height: 20px;
- }
- .info-select-button-div {
- width: 22px;
- height: 22px;
- z-index: 999;
- cursor: pointer;
- position: absolute;
- }
- .layer-select-button {
- width: 22px;
- height: 22px;
- }
- .layer-select-button-div {
- width: 22px;
- height: 22px;
- z-index: 999;
- right: 3px;
- cursor: pointer;
- position: absolute;
- }
- </style>
|