feat: 样式修改、地图采用js
This commit is contained in:
parent
c5c713c908
commit
ad97e3ba02
|
@ -1,4 +1,4 @@
|
||||||
<script setup lang="ts">
|
<script setup>
|
||||||
import maplibregl from "maplibre-gl";
|
import maplibregl from "maplibre-gl";
|
||||||
import "maplibre-gl/dist/maplibre-gl.css";
|
import "maplibre-gl/dist/maplibre-gl.css";
|
||||||
import * as turf from "@turf/turf";
|
import * as turf from "@turf/turf";
|
||||||
|
@ -7,58 +7,70 @@ import "@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css";
|
||||||
|
|
||||||
const mapContainer = useTemplateRef("mapContainer");
|
const mapContainer = useTemplateRef("mapContainer");
|
||||||
|
|
||||||
const map = ref<maplibregl.Map>();
|
/**
|
||||||
|
* @type {Ref<maplibregl.Map>}
|
||||||
|
*/
|
||||||
|
const map = ref();
|
||||||
|
|
||||||
const {feature} = useApi();
|
const { feature } = useApi();
|
||||||
|
|
||||||
MapboxDraw.constants.classes.CANVAS = 'maplibregl-canvas';
|
MapboxDraw.constants.classes.CANVAS = "maplibregl-canvas";
|
||||||
MapboxDraw.constants.classes.CONTROL_BASE = 'maplibregl-ctrl';
|
MapboxDraw.constants.classes.CONTROL_BASE = "maplibregl-ctrl";
|
||||||
MapboxDraw.constants.classes.CONTROL_PREFIX = 'maplibregl-ctrl-';
|
MapboxDraw.constants.classes.CONTROL_PREFIX = "maplibregl-ctrl-";
|
||||||
MapboxDraw.constants.classes.CONTROL_GROUP = 'maplibregl-ctrl-group';
|
MapboxDraw.constants.classes.CONTROL_GROUP = "maplibregl-ctrl-group";
|
||||||
MapboxDraw.constants.classes.ATTRIBUTION = 'maplibregl-ctrl-attrib';
|
MapboxDraw.constants.classes.ATTRIBUTION = "maplibregl-ctrl-attrib";
|
||||||
|
|
||||||
MapboxDraw.lib.theme.find((x: any) => x.id === 'gl-draw-lines').paint['line-dasharray'] = [0.2, 2]
|
|
||||||
|
|
||||||
|
MapboxDraw.lib.theme.find((x) => x.id === "gl-draw-lines").paint[
|
||||||
|
"line-dasharray"
|
||||||
|
] = [0.2, 2];
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!mapContainer.value) return;
|
if (!mapContainer.value) return;
|
||||||
map.value = new maplibregl.Map({
|
map.value = new maplibregl.Map({
|
||||||
container: mapContainer.value, // container id
|
container: mapContainer.value, // container id
|
||||||
style: "https://demotiles.maplibre.org/style.json", // style URL
|
style: "https://demotiles.maplibre.org/style.json", // style URL
|
||||||
center: [0, 0], // starting position [lng, lat]
|
center: [116.405285, 39.904989], // starting position [lng, lat]
|
||||||
zoom: 12, // starting zoom
|
zoom: 4, // starting zoom
|
||||||
});
|
});
|
||||||
// map.value.removeControl(map.value._controls[0]);
|
map.value.removeControl(map.value._controls[0]);
|
||||||
const draw = new MapboxDraw({
|
const draw = new MapboxDraw({
|
||||||
displayControlsDefault: false,
|
displayControlsDefault: false,
|
||||||
controls: {
|
controls: {
|
||||||
|
point: true,
|
||||||
|
line_string: true,
|
||||||
polygon: true,
|
polygon: true,
|
||||||
trash: true
|
trash: true,
|
||||||
}
|
// combine_features: true,
|
||||||
})
|
// uncombine_features: true,
|
||||||
|
},
|
||||||
const updateArea = (e: any) => {
|
|
||||||
const data = draw.getAll();
|
|
||||||
console.log(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
map.value.addControl(draw, "top-right");
|
|
||||||
map.value.on('draw.create', updateArea);
|
|
||||||
map.value.on('draw.delete', updateArea);
|
|
||||||
map.value.on('draw.update', updateArea);
|
|
||||||
map.value.on('draw.selectionchange', (e: any) => {
|
|
||||||
console.log(e)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const {data, status} = await feature.list<any>({page: 1, size: 10});
|
const updateArea = (e) => {
|
||||||
if (status.value !== 'success') return;
|
const data = draw.getAll();
|
||||||
let jsonData = turf.featureCollection(data.value.data.map((x: any) => turf.feature(x.geometry, {
|
console.log(data);
|
||||||
id: x.id,
|
};
|
||||||
name: x.name
|
|
||||||
})));
|
map.value.addControl(draw, "top-right");
|
||||||
|
map.value.on("draw.create", updateArea);
|
||||||
|
map.value.on("draw.delete", updateArea);
|
||||||
|
map.value.on("draw.update", updateArea);
|
||||||
|
map.value.on("draw.selectionchange", (e) => {
|
||||||
|
console.log(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
const { data, status } = await feature.list({ page: 1, size: 10 });
|
||||||
|
if (status.value !== "success") return;
|
||||||
|
let jsonData = turf.featureCollection(
|
||||||
|
data.value.data.map((x) =>
|
||||||
|
turf.feature(x.geometry, {
|
||||||
|
id: x.id,
|
||||||
|
name: x.name,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
console.log(jsonData);
|
console.log(jsonData);
|
||||||
|
|
||||||
map.value.addSource("data", {type: "geojson", data: jsonData});
|
map.value.addSource("data", { type: "geojson", data: jsonData });
|
||||||
map.value.addLayer({
|
map.value.addLayer({
|
||||||
id: "data-symbol",
|
id: "data-symbol",
|
||||||
type: "symbol",
|
type: "symbol",
|
||||||
|
@ -81,10 +93,10 @@ onMounted(async () => {
|
||||||
"fill-opacity": 0.5,
|
"fill-opacity": 0.5,
|
||||||
"fill-outline-color": "#FF0000", // 添加边界线颜色
|
"fill-outline-color": "#FF0000", // 添加边界线颜色
|
||||||
},
|
},
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div ref="mapContainer" class="w-full h-full"/>
|
<div ref="mapContainer" class="w-full h-full" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -6,7 +6,6 @@ const handleMenuChange = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -55,7 +54,7 @@ const route = useRoute();
|
||||||
aria-label="close sidebar"
|
aria-label="close sidebar"
|
||||||
class="drawer-overlay"
|
class="drawer-overlay"
|
||||||
></label>
|
></label>
|
||||||
<ul class="menu bg-base-300 text-base-content min-h-full w-56 p-2">
|
<ul class="menu bg-base-300 text-base-content h-full w-56 p-2">
|
||||||
<li>
|
<li>
|
||||||
<a href="/" :class="route.path === '/' ? 'active' : ''"
|
<a href="/" :class="route.path === '/' ? 'active' : ''"
|
||||||
><Icon name="material-symbols:home-outline-rounded" />首页</a
|
><Icon name="material-symbols:home-outline-rounded" />首页</a
|
||||||
|
@ -74,14 +73,16 @@ const route = useRoute();
|
||||||
<li><a>Sidebar Item 2</a></li>
|
<li><a>Sidebar Item 2</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<main class="drawer-content flex-auto overflow-x-hidden overflow-y-auto bg-base-100">
|
<main
|
||||||
<section class="min-h-full relative p-4 pb-8">
|
class="drawer-content flex-auto relative p-4 pb-0 overflow-hidden bg-base-100 flex flex-col"
|
||||||
<Breadcrumbs />
|
>
|
||||||
|
<Breadcrumbs />
|
||||||
|
<section class="flex-auto overflow-y-auto overflow-x-hidden">
|
||||||
<slot />
|
<slot />
|
||||||
<footer class="absolute bottom-0 w-full h-4 my-2 text-center text-xs">
|
|
||||||
©powered by maptile
|
|
||||||
</footer>
|
|
||||||
</section>
|
</section>
|
||||||
|
<footer class="mt-auto w-full h-8 py-2 text-center text-xs">
|
||||||
|
©powered by maptile
|
||||||
|
</footer>
|
||||||
</main>
|
</main>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1326,7 +1326,6 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmmirror.com/@mapbox/geojson-normalize/-/geojson-normalize-0.0.1.tgz",
|
"resolved": "https://registry.npmmirror.com/@mapbox/geojson-normalize/-/geojson-normalize-0.0.1.tgz",
|
||||||
"integrity": "sha512-82V7YHcle8lhgIGqEWwtXYN5cy0QM/OHq3ypGhQTbvHR57DF0vMHMjjVSQKFfVXBe/yWCBZTyOuzvK7DFFnx5Q==",
|
"integrity": "sha512-82V7YHcle8lhgIGqEWwtXYN5cy0QM/OHq3ypGhQTbvHR57DF0vMHMjjVSQKFfVXBe/yWCBZTyOuzvK7DFFnx5Q==",
|
||||||
"license": "ISC",
|
|
||||||
"bin": {
|
"bin": {
|
||||||
"geojson-normalize": "geojson-normalize"
|
"geojson-normalize": "geojson-normalize"
|
||||||
}
|
}
|
||||||
|
@ -1356,7 +1355,6 @@
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"resolved": "https://registry.npmmirror.com/@mapbox/mapbox-gl-draw/-/mapbox-gl-draw-1.5.0.tgz",
|
"resolved": "https://registry.npmmirror.com/@mapbox/mapbox-gl-draw/-/mapbox-gl-draw-1.5.0.tgz",
|
||||||
"integrity": "sha512-uchQbTa8wiv6GWWTbxW1g5b8H6VySz4t91SmduNH6jjWinPze7cjcmsPUEzhySXsYpYr2/50gRJLZz3bx7O88A==",
|
"integrity": "sha512-uchQbTa8wiv6GWWTbxW1g5b8H6VySz4t91SmduNH6jjWinPze7cjcmsPUEzhySXsYpYr2/50gRJLZz3bx7O88A==",
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mapbox/geojson-area": "^0.2.2",
|
"@mapbox/geojson-area": "^0.2.2",
|
||||||
"@mapbox/geojson-normalize": "^0.0.1",
|
"@mapbox/geojson-normalize": "^0.0.1",
|
||||||
|
@ -1371,8 +1369,7 @@
|
||||||
"node_modules/@mapbox/mapbox-gl-draw/node_modules/@mapbox/point-geometry": {
|
"node_modules/@mapbox/mapbox-gl-draw/node_modules/@mapbox/point-geometry": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmmirror.com/@mapbox/point-geometry/-/point-geometry-1.1.0.tgz",
|
"resolved": "https://registry.npmmirror.com/@mapbox/point-geometry/-/point-geometry-1.1.0.tgz",
|
||||||
"integrity": "sha512-YGcBz1cg4ATXDCM/71L9xveh4dynfGmcLDqufR+nQQy3fKwsAZsWd/x4621/6uJaeB9mwOHE6hPeDgXz9uViUQ==",
|
"integrity": "sha512-YGcBz1cg4ATXDCM/71L9xveh4dynfGmcLDqufR+nQQy3fKwsAZsWd/x4621/6uJaeB9mwOHE6hPeDgXz9uViUQ=="
|
||||||
"license": "ISC"
|
|
||||||
},
|
},
|
||||||
"node_modules/@mapbox/node-pre-gyp": {
|
"node_modules/@mapbox/node-pre-gyp": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
|
@ -6069,14 +6066,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/call-bound": {
|
"node_modules/call-bound": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmmirror.com/call-bound/-/call-bound-1.0.3.tgz",
|
"resolved": "https://registry.npmmirror.com/call-bound/-/call-bound-1.0.4.tgz",
|
||||||
"integrity": "sha512-YTd+6wGlNlPxSuri7Y6X8tY2dmm12UMH66RpKMhiX6rsk5wXXnYgbUcOt8kiS31/AjfoTOvCsE+w8nZQLQnzHA==",
|
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"call-bind-apply-helpers": "^1.0.1",
|
"call-bind-apply-helpers": "^1.0.2",
|
||||||
"get-intrinsic": "^1.2.6"
|
"get-intrinsic": "^1.3.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
|
|
|
@ -5,7 +5,7 @@ definePageMeta({
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="h-[600px] bg-red-200">
|
<div class="w-full h-full relative">
|
||||||
<Map />
|
<Map />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue