Compare commits

...

2 Commits

  1. 10
      build/webpack.base.conf.js
  2. 2
      index.html
  3. 1
      package.json
  4. 35
      src/assets/geojson/town_boundaries.geojson
  5. 244
      src/views/screen/components/gisMapOfCounty.vue

10
build/webpack.base.conf.js

@ -64,7 +64,7 @@ const webpackConfig = {
limit: 10000, limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]') name: utils.assetsPath('media/[name].[hash:7].[ext]')
} }
}, },
{ {
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader', loader: 'url-loader',
@ -92,7 +92,11 @@ const webpackConfig = {
} }
} }
] ]
} },
{
test: /\.geojson$/,
use: 'json-loader'
},
], ],
// unknownContextRegExp: /^.\/.*$/, // unknownContextRegExp: /^.\/.*$/,
unknownContextCritical: false unknownContextCritical: false
@ -111,4 +115,4 @@ const webpackConfig = {
} }
} }
module.exports = vuxLoader.merge(webpackConfig, {plugins: ['vux-ui']}) module.exports = vuxLoader.merge(webpackConfig, { plugins: ['vux-ui'] })

2
index.html

@ -20,7 +20,7 @@
<script type="text/javascript" src="./static/liveplayer/liveplayer-lib.min.js"></script> <script type="text/javascript" src="./static/liveplayer/liveplayer-lib.min.js"></script>
<script type="text/javascript" src="./static/yjgb/recordmp3.js"></script> <script type="text/javascript" src="./static/yjgb/recordmp3.js"></script>
<script type="text/javascript" <script type="text/javascript"
src="https://webapi.amap.com/maps?v=2.0&key=3a3db11b089ab8bbb3c4894e650dc077&plugin=AMap.MouseTool,AMap.PolyEditor,AMap.MapType,AMap.ControlBar,AMap.ToolBar,AMap.ElasticMarker,AMap.HawkEye,AMap.DistrictSearch,AMap.MarkerCluster,AMap.Driving,AMap.AutoComplete,AMap.PlaceSearch,AMap.ImageLayer"></script> src="https://webapi.amap.com/maps?v=2.0&key=3a3db11b089ab8bbb3c4894e650dc077&plugin=AMap.MouseTool,AMap.PolyEditor,AMap.MapType,AMap.ControlBar,AMap.ToolBar,AMap.ElasticMarker,AMap.HawkEye,AMap.DistrictSearch,AMap.MarkerCluster,AMap.Driving,AMap.AutoComplete,AMap.PlaceSearch,AMap.ImageLayer,AMap.GeoJSON"></script>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

1
package.json

@ -59,6 +59,7 @@
"file-loader": "^1.1.4", "file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1", "friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1", "html-webpack-plugin": "^2.30.1",
"json-loader": "^0.5.7",
"less-loader": "^4.0.5", "less-loader": "^4.0.5",
"node-notifier": "^5.1.2", "node-notifier": "^5.1.2",
"optimize-css-assets-webpack-plugin": "^3.2.0", "optimize-css-assets-webpack-plugin": "^3.2.0",

35
src/assets/geojson/town_boundaries.geojson

File diff suppressed because one or more lines are too long

244
src/views/screen/components/gisMapOfCounty.vue

@ -4,12 +4,7 @@
<slot name="content" class="content"></slot> <slot name="content" class="content"></slot>
<commonModal v-model="pointsState" width="800" title="聚合列表"> <commonModal v-model="pointsState" width="800" title="聚合列表">
<div class="points"> <div class="points">
<div <div class="item" v-for="(item, index) in points" :key="index" @click="getPoint(item.point)">
class="item"
v-for="(item, index) in points"
:key="index"
@click="getPoint(item.point)"
>
{{ item.point[listItemKey] }} {{ item.point[listItemKey] }}
</div> </div>
</div> </div>
@ -90,6 +85,8 @@ export default {
pointsState: false, pointsState: false,
points: [], points: [],
tags: [], tags: [],
geojsonPath: "@/assets/geojson/town_boundaries.geojson", // GeoJSON
polygons: [], //
}; };
}, },
props: { props: {
@ -176,6 +173,7 @@ export default {
} }
}); });
}, },
initMap() { initMap() {
const imgLayer = new AMap.TileLayer({ const imgLayer = new AMap.TileLayer({
zIndex: 0, zIndex: 0,
@ -183,49 +181,216 @@ export default {
`http://t0.tianditu.gov.cn/DataServer?T=img_w&tk=${this.common.mapKey}&x=${x}&y=${y}&l=${z}`, `http://t0.tianditu.gov.cn/DataServer?T=img_w&tk=${this.common.mapKey}&x=${x}&y=${y}&l=${z}`,
}); });
const district = new AMap.DistrictSearch({ this.map = new AMap.Map("center-map", {
subdistrict: 3, layers: this.common.isSkyMap ? [imgLayer] : [new AMap.TileLayer.RoadNet()],
zoom: this.zoom,
zooms: [3, 16],
scrollWheel: true,
center: this.center || [104.62, 28.77], //
viewMode: "3D",
resizeEnable: true,
mapStyle: "amap://styles/darkblue",
features: ["bg", "road", "building", "point"],
});
this.map.on("complete", () => {
if (this.aggregationPoint) {
this.aggregationPoint(this.pointList);
}
this.addPoints(); //
});
// GeoJSON
this.loadGeoJSON();
//
this.loadCuiPingDistrict();
//
// this.map.on('click', this.handleMapClick);
},
handleMapClick(e) {
const lngLat = e.lnglat;
console.log('点击坐标:', lngLat);
this.polygons.forEach(polygon => {
const path = polygon.getPath();
const isInPolygon = AMap.GeometryUtil.isPointInRing(lngLat.toArray(), path.map(p => p.toArray()));
console.log('多边形:', isInPolygon);
if (isInPolygon) {
const name = polygon.getExtData().name;
console.log('点击:', name);
this.map.setZoomAndCenter(10, lngLat); //
alert(`您点击了乡镇:${name}`);
}
});
},
loadCuiPingDistrict() {
const districtSearch = new AMap.DistrictSearch({
subdistrict: 3, //
extensions: "all", extensions: "all",
level: "district", level: "district",
}); });
district.search(this.districtLocation, (status, result) => { const self = this; // 便使
const bounds = result.districtList[0].boundaries; districtSearch.search(this.districtLocation, function (status, result) {
const mask = bounds.map((bound) => [bound]); if (status === "complete" && result.districtList && result.districtList.length) {
const polygons = bounds.map( const district = result.districtList[0];
(bound) => const boundaries = district.boundaries;
new AMap.Polygon({
strokeWeight: 5,
path: bound,
fillOpacity: 0.8,
fillColor: "rgba(67, 112, 122,0.55)",
strokeColor: "#94c4ce",
})
);
this.map = new AMap.Map("center-map", { if (boundaries) {
mask, //
layers: this.common.isSkyMap self.drawCuiPingBase(boundaries);
? [imgLayer] } else {
: [new AMap.TileLayer.RoadNet], console.warn("翠屏区无边界数据");
zoom: this.zoom, }
zooms: [3, 16], } else {
scrollWheel: true, console.error("行政区查询失败: " + status);
center: that.center, }
// pitch: 10, // 0 - 83 });
viewMode: "3D", // },
resizeEnable: true, // drawCuiPingBase(boundaries) {
mapStyle: "amap://styles/darkblue", const mask = boundaries.map((boundary) => [boundary]);
features: ["bg", "road", "building", "point"] boundaries.forEach((boundary) => {
const polygon = new AMap.Polygon({
path: boundary,
strokeColor: "#333", // 线
strokeWeight: 3, // 线
fillColor: "#102C4F", //
fillOpacity: 0.7, //
}); });
this.map.add(polygon);
});
this.map.on("complete", () => { //
this.aggregationPoint(this.pointList); this.map.setMask(mask);
},
debounce(func, wait) {
let timeout;
return function (...args) {
const context = this;
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(context, args), wait);
};
},
loadGeoJSON() {
// 使 require GeoJSON
const geojsonData = require('@/assets/geojson/town_boundaries.geojson');
const colors = ['#33FFD450'];
//
const boundaries = geojsonData.features.map((feature) => {
const coordinates = feature.geometry.coordinates[0]; // Polygon
return coordinates[0].map((coord) => new AMap.LngLat(coord[0], coord[1])); // AMap
});
// this.map.setMask(boundaries);
//
geojsonData.features.forEach((feature, index) => {
const { properties, geometry } = feature;
const name = properties.name; //
const coordinates = geometry.coordinates[0]; //
const center = this.getPolygonCenter(coordinates); //
console.log('多边形中心点:', center);
const path = coordinates[0].map((coord) => new AMap.LngLat(coord[0], coord[1]));
path.push(path[0]); //
//
const polygon = new AMap.Polygon({
zIndex: 100,
// path: coordinates[0].map((coord) => new AMap.LngLat(coord[0], coord[1])), // AMap
path,
strokeColor: colors[index % colors.length], // 线
strokeWeight: 3, // 线
fillColor: '#0A7EA8', //
fillOpacity: 0.5, //
bubble: true, //
}); });
this.map.add(polygons); //
polygon.setMap(this.map);
if (name && center) {
const labelMarker = new AMap.Marker({
position: center,
zIndex: 2000,
clickable: true,
content: `
<div style="
font-size: 16px;
font-weight: bold;
color: #fff;
width: max-content;
">
${name}
</div>
`,
offset: new AMap.Pixel(-25, -25), //
});
// labelMarkerhover
labelMarker.on('mouseover', () => {
labelMarker.setContent(`
<div style="
font-size: 16px;
font-weight: bold;
color: #C6E1CA;
width: max-content;
">
${name}
</div>
`);
});
labelMarker.on('mouseout', () => {
labelMarker.setContent(`
<div style="
font-size: 16px;
font-weight: bold;
color: #fff;
width: max-content;
">
${name}
</div>
`);
});
// 使 labelMarker.on
labelMarker.on('click', () => {
console.log('点击:', name);
});
this.map.add(labelMarker);
}
});
},
//
addPoints() {
this.pointList.forEach((point) => {
const marker = new AMap.Marker({
position: point.position,
title: point.name,
});
marker.setMap(this.map);
}); });
}, },
//
getPolygonCenter(coordinates) {
if (!coordinates || !coordinates.length) return null;
let [lngSum, latSum] = [0, 0];
coordinates[0].forEach((coord, index) => {
if (Array.isArray(coord) && coord.length >= 2) {
const [lng, lat] = coord;
lngSum += lng;
latSum += lat;
} else {
console.warn(`无效的坐标 ${index}:`, coord); //
}
});
return [lngSum / coordinates[0].length, latSum / coordinates[0].length];
},
aggregationPoint(pointList) { aggregationPoint(pointList) {
const gridSize = 60; const gridSize = 60;
const countIcon = require("@/assets/mapIcon/count.png"); const countIcon = require("@/assets/mapIcon/count.png");
@ -346,6 +511,9 @@ export default {
this.$emit("currentPoint", data); this.$emit("currentPoint", data);
}, },
}, },
mounted() {
this.initMap();
},
}; };
</script> </script>

Loading…
Cancel
Save