Browse Source

同步screen-map

shibei_master
ZhaoTongYao 3 years ago
parent
commit
43aeea6deb
  1. 7
      src/views/modules/visual/communityGovern/duoyuanfuwu/duoyuanfuwufenxi.vue
  2. 220
      src/views/modules/visual/components/screen-map/index.vue

7
src/views/modules/visual/communityGovern/duoyuanfuwu/duoyuanfuwufenxi.vue

@ -447,11 +447,11 @@ export default {
// //
loadMap () { loadMap () {
if (this.isfirstInit) { if (this.isfirstInit) {
this.agencyInfo.level = 'agency' // this.agencyInfo.level = 'agency'
//mapInfo, polygonArray, polIconUrlArray, iconArrays, iconUrlArray //mapInfo, polygonArray, polIconUrlArray, iconArrays, iconUrlArray
this.$refs.map.loadMap(this.agencyInfo, this.polygonList, null, this.distributionsList, this.iconUrlArray, null) this.$refs.map.loadMap(this.agencyInfo, this.polygonList, null, this.distributionsList, this.iconUrlArray, null)
} else { } else {
this.$refs.map.refreshMap(this.polygonList, this.distributionsList) this.$refs.map.refreshMap(this.agencyInfo, this.polygonList, this.distributionsList)
} }
}, },
@ -613,6 +613,9 @@ export default {
if (!this.agencyInfo.level) { if (!this.agencyInfo.level) {
this.agencyInfo.level = 'street' this.agencyInfo.level = 'street'
} }
if (!this.agencyInfo.agencyLevel) {
this.agencyInfo.agencyLevel = 'street'
}
} else { } else {
this.$message.error(msg); this.$message.error(msg);
} }

220
src/views/modules/visual/components/screen-map/index.vue

@ -21,8 +21,8 @@
</div>--> </div>-->
<div class="div_map" <div class="div_map"
id="map" :id="mapId"
ref="map"> :ref="mapId">
</div> </div>
<div id="popup" <div id="popup"
style="display: none;" style="display: none;"
@ -32,6 +32,9 @@
class="ol-popup-closer"></a> class="ol-popup-closer"></a>
<div id="popup-content" <div id="popup-content"
class="popup-content"></div> class="popup-content"></div>
<a href="#"
id="popup-goMore"
class="popup-goMore">更多>>>></a>
</div> </div>
</div> </div>
</template> </template>
@ -79,6 +82,24 @@ let iconSource; // icon
let select;// let select;//
let iconTextsStyle = {
textAlign: undefined,
font: "18px Arial",
//fontFamily: "Courier New, monospace",
// fontWeight: "bold",
text: '',
backgroundFill: new Fill({
color: 'rgba(0, 146, 238, 0.75)'
// color: textColorArray[feature.values_.colorIndex]
}),
padding: [4, 10, 4, 10],
//text: "",
fill: new Fill({ color: "#ffffff" }),
// stroke: new Stroke({ color: "#ffffff", width: 3 }),
offsetY: -30,
offsetX: -50,
overflow: true,
}
let polygonColorArray = [ let polygonColorArray = [
'rgba(210, 2, 2, 0.24)', 'rgba(210, 2, 2, 0.24)',
@ -86,7 +107,19 @@ let polygonColorArray = [
'rgba(183, 185, 0, 0.16)' 'rgba(183, 185, 0, 0.16)'
]; ];
//icon
let createTextStyle = function (feature) {
if (iconTextsStyle) {
let iconTextsStyles = { ...iconTextsStyle }
iconTextsStyles.text = feature.values_ && feature.values_.name || feature.name
return new Text({ ...iconTextsStyles })
} else {
return null
}
}
// //
var polygonStyleFunction = (function () { var polygonStyleFunction = (function () {
return function (feature) { return function (feature) {
@ -105,6 +138,8 @@ var polygonStyleFunction = (function () {
}; };
})() })()
const vueGis = { const vueGis = {
name: 'HomeMap', name: 'HomeMap',
data () { data () {
@ -151,7 +186,7 @@ const vueGis = {
iconArrays: [ iconArrays: [
], ],
iconTextStyle: {}, // iconTextStyle: {},
//policon //policon
polIconUrlArray: [ polIconUrlArray: [
@ -181,10 +216,10 @@ const vueGis = {
loadMap (mapInfo, polygonArray, polIconUrlArray, iconArrays, iconUrlArray, iconTextStyle, distanceMax) { loadMap (mapInfo, polygonArray, polIconUrlArray, iconArrays, iconUrlArray, iconTextStyle, distanceMax) {
this.mapInfo = mapInfo this.mapInfo = mapInfo
this.polygonArray = polygonArray this.polygonArray = polygonArray
this.polIconUrlArray = polIconUrlArray this.polIconUrlArray = polIconUrlArray || []
this.iconArrays = iconArrays this.iconArrays = iconArrays
this.iconUrlArray = iconUrlArray this.iconUrlArray = iconUrlArray
this.iconTextStyle = iconTextStyle iconTextsStyle = iconTextStyle || iconTextsStyle
this.distanceMax = distanceMax this.distanceMax = distanceMax
// iconArrays.forEach(item => { // iconArrays.forEach(item => {
@ -195,18 +230,18 @@ const vueGis = {
// //
this.initMap() this.initMap()
if (this.showPolygonLayer) { if (this.showPolIconLayer) {
console.log('showPolIconLayer++++++++++++++++++++++', this.showPolIconLayer)
// //
this.initPolygonLayer() this.initPolIconLayer()
// //
this.loadPolygon() // this.loadPolIcon()
} }
if (this.showPolIconLayer) { if (this.showPolygonLayer) {
// //
this.initPolygonLayer() this.initPolygonLayer()
// //
this.loadPolIcon() this.loadPolygon()
} }
if (this.showIconLayer) { if (this.showIconLayer) {
@ -220,41 +255,51 @@ const vueGis = {
this.addOverlay() this.addOverlay()
} }
this.addMapClick() this.addMapClick()
}, },
// //
async refreshMap (polygonArray, iconArrays) { async refreshMap (mapInfo, polygonArray, iconArrays) {
this.mapInfo = mapInfo
this.polygonArray = []
this.polygonArray = polygonArray this.polygonArray = polygonArray
this.iconArrays = iconArrays this.iconArrays = iconArrays
if (iconSource) {
iconSource.clear()
}
if (polygonSource) {
polygonSource.clear()
}
if (polIconSource) {
polIconSource.clear()
}
this.initPolIconLayer()
if (this.showPolygonLayer) { if (this.showPolygonLayer) {
this.initPolygonLayer()
// //
this.loadPolygon() this.loadPolygon()
} }
if (this.showPolIconLayer) { if (this.showPolIconLayer) {
this.initIconLayer()
// //
this.loadPolIcon() // this.loadPolIcon()
} }
if (this.showIconLayer) { if (this.showIconLayer) {
this.loadIcon() this.loadIcon()
} }
this.setMapLocation()
// gaodeMapLayer.getSource().changed()
}, },
// //
loadPolygon () { loadPolygon () {
polygonSource.clear()// polygonSource.clear()//
// iconSource.clear()
let featureData = []// let featureData = []//
if (this.polygonArray && this.polygonArray.length > 0) {// if (this.polygonArray && this.polygonArray.length > 0) {//
@ -311,9 +356,11 @@ const vueGis = {
}, },
//icon //icon
loadPolIcon (feature) { loadPolIcon (feature) {
polIconSource.clear()
let polyIconFeatures = []; let polyIconFeatures = [];
console.log('feature-----', feature)
feature.forEach(oneIcon => { feature.forEach(oneIcon => {
var extent = boundingExtent(oneIcon.getGeometry().getCoordinates()[0]); //[minx,miny,maxx,maxy] var extent = boundingExtent(oneIcon.getGeometry().getCoordinates()[0]); //[minx,miny,maxx,maxy]
@ -330,28 +377,27 @@ const vueGis = {
id: oneIcon.id_ id: oneIcon.id_
} }
}); });
// console.log('oneIcon----', oneIcon)
let polyIconStyle = new Style({ let polyIconStyle = new Style({
image: new Icon({ image: new Icon({
// anchor: [0.5, 0.5], // anchor: [0.5, 0.5],
// imgSize: [32, 32], // imgSize: [32, 32],
scale: 0.5, scale: this.areaScale,
src: polIconUrlArray[oneIcon.values_.index - 1] src: this.polIconUrlArray[0]
}) }),
text: createTextStyle(oneIcon)
}); });
polyIcon.setStyle(polyIconStyle); polyIcon.setStyle(polyIconStyle);
polyIconFeatures.push(polyIcon); polyIconFeatures.push(polyIcon);
}); });
polIconSource.addFeatures(polyIconFeatures); polIconSource.addFeatures(polyIconFeatures);
}, },
//icon //icon
loadIcon () { loadIcon () {
iconSource.clear()// iconSource.clear()//
if (this.iconArrays && this.iconArrays.length > 0) { if (this.iconArrays && this.iconArrays.length > 0) {
let iconFeatures = []; let iconFeatures = [];
@ -367,15 +413,14 @@ const vueGis = {
info: { ...oneIcon } info: { ...oneIcon }
} }
}); });
let iconStyle = new Style({ let iconStyle = new Style({
image: new Icon({ image: new Icon({
// anchor: [0.5, 0.5], // anchor: [0.5, 0.5],
// imgSize: [32, 32], // imgSize: [32, 32],
// scale: 0.5, // scale: 0.5,
src: this.iconUrlArray[oneIcon.urlIndex] src: oneIcon.urlIndex && this.iconUrlArray[oneIcon.urlIndex] || this.iconUrlArray[0]
}), }),
text: this.createTextStyle(oneIcon) // text: createTextStyle(oneIcon)
}); });
iconItem.setStyle(iconStyle); iconItem.setStyle(iconStyle);
@ -397,18 +442,6 @@ const vueGis = {
} }
}, },
//icon
createTextStyle (feature) {
if (this.iconTextStyle) {
let iconTextStyle = { ...this.iconTextStyle }
iconTextStyle.text = feature.values_.name
return new Text({ ...iconTextStyle })
} else {
return null
}
},
// //
computedDistance (lon, lat, max) { computedDistance (lon, lat, max) {
@ -425,7 +458,7 @@ const vueGis = {
// //
initMap () { initMap () {
this.setMapLocation() this.firstCentermap()
gaodeMapLayer = new TileLayer({ gaodeMapLayer = new TileLayer({
title: "地图", title: "地图",
source: new XYZ({ source: new XYZ({
@ -452,7 +485,7 @@ const vueGis = {
layers: [gaodeMapLayer], layers: [gaodeMapLayer],
// //
view: mapView, view: mapView,
target: 'map' target: this.mapId
//map //map
}) })
@ -478,8 +511,53 @@ const vueGis = {
}, },
// //
setMapLocation () { setMapLocation () {
if (!this.zoom) {
this.setZoom(this.mapInfo.agencyLevel)
}
this.centerPoint = []
//
if (this.center && this.center.length > 0) {
this.centerPoint = this.center
this.centerFlag = 'point'
this.center = []
} else if (polygonLayer.getSource().getFeatures()[0]) {//,
this.centerFlag = 'flag_polygon'
this.centerPoint.push(this.mapInfo.longitude)
this.centerPoint.push(this.mapInfo.latitude)
} else if (this.mapInfo.longitude && this.mapInfo.latitude) {
this.centerPoint.push(this.mapInfo.longitude)
this.centerPoint.push(this.mapInfo.latitude)
this.centerFlag = 'point'
} else {
this.centerPoint = centerPointGlobal
this.centerFlag = 'point'
}
// debugger
if (this.centerFlag === 'flag_parent') {
let parentFeatures = parentLayer.getSource().getFeatures()[0]
let polygon = parentFeatures.getGeometry();
map.getView().fit(polygon, map.getSize());
this.zoom = map.getView().getZoom() - 1
} else if (this.centerFlag === 'flag_polygon') {
let polygonFeatures = polygonLayer.getSource().getFeatures()[0]
let polygon = polygonFeatures.getGeometry();
map.getView().fit(polygon, map.getSize());
this.zoom = map.getView().getZoom() - 1
} else {
mapView.setCenter(this.centerPoint);
}
mapView.setZoom(this.zoom);
},
firstCentermap() {
if (this.mapInfo.longitude && this.mapInfo.latitude) { if (this.mapInfo.longitude && this.mapInfo.latitude) {
this.centerPoint = [] this.centerPoint = []
this.centerPoint.push(this.mapInfo.longitude) this.centerPoint.push(this.mapInfo.longitude)
@ -489,7 +567,7 @@ const vueGis = {
this.centerPoint = centerPointGlobal this.centerPoint = centerPointGlobal
} }
this.setZoom(this.mapInfo.level) this.setZoom(this.mapInfo.agencyLevel)
}, },
// //
@ -507,7 +585,8 @@ const vueGis = {
// //
initPolygonLayer () { initPolygonLayer () {
polygonSource = new VectorSource({ polygonSource = new VectorSource({
//features: (new GeoJSON()).readFeatures(geojsonObject) // features: (new GeoJSON()).readFeatures(geojsonObject)
wrapX: false
}); });
polygonLayer = new VectorLayer({ polygonLayer = new VectorLayer({
@ -515,7 +594,7 @@ const vueGis = {
style: polygonStyleFunction, style: polygonStyleFunction,
zIndex: 50 zIndex: 50
}); });
let that = this
// //
var overlayStyle = (function () { var overlayStyle = (function () {
@ -535,7 +614,7 @@ const vueGis = {
}) })
}), }),
new Style({ new Style({
// text: createTextStyle(feature) // zty 2022.05.19 // text: createTextStyle(feature) // zhaotongyao 2022.05.19
}) })
]; ];
styles['MultiPolygon'] = styles['Polygon']; styles['MultiPolygon'] = styles['Polygon'];
@ -558,6 +637,7 @@ const vueGis = {
initPolIconLayer () { initPolIconLayer () {
polIconSource = new VectorSource({ polIconSource = new VectorSource({
//features: (new GeoJSON()).readFeatures(geojsonObject) //features: (new GeoJSON()).readFeatures(geojsonObject)
wrapX: false
}); });
polIconLayer = new VectorLayer({ polIconLayer = new VectorLayer({
@ -571,9 +651,9 @@ const vueGis = {
//icon //icon
initIconLayer () { initIconLayer () {
iconSource = new VectorSource({ iconSource = new VectorSource({
//features: (new GeoJSON()).readFeatures(geojsonObject) //features: (new GeoJSON()).readFeatures(geojsonObject)
wrapX: false
}); });
iconLayer = new VectorLayer({ iconLayer = new VectorLayer({
@ -597,6 +677,7 @@ const vueGis = {
var container = document.getElementById("popup"); var container = document.getElementById("popup");
var closer = document.getElementById("popup-closer"); var closer = document.getElementById("popup-closer");
var content = document.getElementById("popup-content"); var content = document.getElementById("popup-content");
var goMore = document.getElementById("popup-goMore") ? document.getElementById("popup-goMore") : null
// Overlay // Overlay
this.overlay = new Overlay({ this.overlay = new Overlay({
@ -619,6 +700,11 @@ const vueGis = {
closer.blur(); closer.blur();
return false; return false;
}; };
if (goMore) {
goMore.onclick = function () {
_that.$emit('lookMore')
};
}
}, },
// //
@ -650,15 +736,27 @@ const vueGis = {
}); });
}, },
handleShowPopup (showData, coordinate) { handleShowPopup (showData, coordinate, isShowMore) {
if (isShowMore) {
document.getElementById("popup-goMore").style.display = 'block'
} else {
document.getElementById("popup-goMore").style.display = 'none'
}
console.log(this.overlay.getElement()) console.log(this.overlay.getElement())
let content = document.getElementById("popup-content");
this.overlay.getElement().style.display = 'block' this.overlay.getElement().style.display = 'block'
this.overlay.getElement().parentNode.style.display = 'block' this.overlay.getElement().parentNode.style.display = 'block'
this.overlay.getElement().parentNode.parentNode.style.display = 'block' this.overlay.getElement().parentNode.parentNode.style.display = 'block'
var content = document.getElementById("popup-content");
content.innerHTML = showData; content.innerHTML = showData;
this.overlay.setPosition(coordinate); // overlay x,y this.overlay.setPosition(coordinate);
// overlay x,y
},
//
handleClosePopup() {
this.overlay.setPosition(undefined);
document.getElementById("popup-closer").blur();
return false;
}, },
// //
@ -685,6 +783,10 @@ const vueGis = {
}, },
}, },
props: { props: {
mapId: {
type: String,
default: 'map'
},
// //
showPolygonLayer: { showPolygonLayer: {
type: Boolean, type: Boolean,
@ -711,6 +813,10 @@ const vueGis = {
clickType: { clickType: {
type: String, type: String,
default: 'back' default: 'back'
},
areaScale: {
type: Number,
default: 0.5
} }
}, },
@ -795,8 +901,12 @@ export default vueGis;
.popup-content { .popup-content {
width: 300px; width: 300px;
} }
.popup-goMore{
margin: 20px 0;
}
.ol-popup-closer:after { .ol-popup-closer:after {
content: "✖"; content: "✖";
color: rgba(1, 17, 104, 1); // color: rgba(1, 17, 104, 1);
color: #fff;
} }
</style> </style>
Loading…
Cancel
Save