|
@@ -1,88 +1,39 @@
|
|
|
|
|
+//html
|
|
|
<template>
|
|
<template>
|
|
|
- <div ref="mapContainer" class="map-container"></div>
|
|
|
|
|
|
|
+ <div id="container" style="overflow: hidden;"></div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, onMounted, reactive } from 'vue';
|
|
|
|
|
-// import mapStyle from '../mapStyle.json'
|
|
|
|
|
-// const mapContainer = ref(null);
|
|
|
|
|
|
|
|
|
|
-// const initMap = () => {
|
|
|
|
|
-// // Check if TMap is fully loaded
|
|
|
|
|
-// if (!window.TMap) {
|
|
|
|
|
-// console.error('TMap SDK not loaded!');
|
|
|
|
|
-// return;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// // Initialize map
|
|
|
|
|
-// const center = new TMap.LatLng(39.984104, 116.307503);
|
|
|
|
|
-// new TMap.Map(mapContainer.value, {
|
|
|
|
|
-// center: center,
|
|
|
|
|
-// zoom: 12,
|
|
|
|
|
-// styles: mapStyle
|
|
|
|
|
-// });
|
|
|
|
|
-// };
|
|
|
|
|
-//
|
|
|
|
|
-// const loadTMapSDK = () => {
|
|
|
|
|
-// // If already loaded, initialize directly
|
|
|
|
|
-// if (window.TMap) {
|
|
|
|
|
-// initMap();
|
|
|
|
|
-// return;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// // Dynamically load SDK
|
|
|
|
|
-// const script = document.createElement('script');
|
|
|
|
|
-// script.src = `https://map.qq.com/api/gljs?v=1.exp&key=TOOBZ-FUPEI-LGNGT-UEIAH-JXZB3-LDFFX`;
|
|
|
|
|
-// script.onload = initMap; // No need for TMap.ready()
|
|
|
|
|
-// document.head.appendChild(script);
|
|
|
|
|
-// };
|
|
|
|
|
|
|
+import { onMounted, reactive, ref , watch } from 'vue'
|
|
|
|
|
|
|
|
-const mapContainer = ref(null)
|
|
|
|
|
-let map = null
|
|
|
|
|
-let styleId = 'custom-style' // 自定义样式ID
|
|
|
|
|
-const props = reactive({
|
|
|
|
|
- bgColor: {
|
|
|
|
|
- type: String,
|
|
|
|
|
- default: '#f0f0f0' // 默认背景色
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
-// 初始化地图
|
|
|
|
|
|
|
+var center = ref(null)
|
|
|
|
|
+// 地图初始化
|
|
|
const initMap = () => {
|
|
const initMap = () => {
|
|
|
- if (!window.TMap) {
|
|
|
|
|
- console.error('腾讯地图JS API未加载')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- // 定义地图样式
|
|
|
|
|
- const style = new TMap.MapStyle({
|
|
|
|
|
- id: styleId,
|
|
|
|
|
- config: {
|
|
|
|
|
- styleJson: {
|
|
|
|
|
- version: "1.0",
|
|
|
|
|
- settings: {
|
|
|
|
|
- landColor: props.bgColor, // 陆地颜色
|
|
|
|
|
- waterColor: "#d4e6ff", // 水域颜色
|
|
|
|
|
- backgroundColor: props.bgColor // 背景颜色
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- // 创建地图实例
|
|
|
|
|
- map = new TMap.Map(mapContainer.value, {
|
|
|
|
|
- center: new TMap.LatLng(39.984120, 116.307484), // 北京坐标
|
|
|
|
|
- zoom: 12,
|
|
|
|
|
- styles: [style] // 应用自定义样式
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ //定义地图中心点坐标
|
|
|
|
|
+ center.value = new TMap.LatLng(30.589184, 114.29689)
|
|
|
|
|
+ //定义map变量,调用 TMap.Map() 构造函数创建地图
|
|
|
|
|
+
|
|
|
|
|
+ new TMap.Map(document.getElementById('container'), {
|
|
|
|
|
+ center: center.value,//设置地图中心点坐标
|
|
|
|
|
+ zoom: 7, //设置地图缩放级别
|
|
|
|
|
+ mapStyleId: 'style1', //设置地图样式
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-onMounted(() => {
|
|
|
|
|
- // loadTMapSDK();
|
|
|
|
|
|
|
+onMounted(()=>{
|
|
|
initMap()
|
|
initMap()
|
|
|
-});
|
|
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
-<style scoped>
|
|
|
|
|
-.map-container {
|
|
|
|
|
|
|
+
|
|
|
|
|
+<style>
|
|
|
|
|
+#container {
|
|
|
|
|
+ /*地图(容器)显示大小*/
|
|
|
width: 100%;
|
|
width: 100%;
|
|
|
- height: 820px;
|
|
|
|
|
|
|
+ height: 100%;
|
|
|
}
|
|
}
|
|
|
</style>
|
|
</style>
|