腾讯地图

This commit is contained in:
zhaofeiyang 2022-08-03 14:41:42 +08:00
parent 417dc199ed
commit f26bbdfcf2
6 changed files with 134375 additions and 35 deletions

17879
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"node-sass": "^4.14.1",
"node-sass": "^6.0.1",
"sass": "^1.54.0",
"sass-loader": "^7.3.1",
"vue-template-compiler": "^2.6.11"

115697
public/gljs1.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -8,6 +8,10 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css">
<script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js"></script>
<title><%= htmlWebpackPlugin.options.title %></title>
<script
charset="utf-8"
src="./gljs1.js"
></script>
</head>
<body>
<noscript>

View File

@ -1,8 +1,9 @@
<template>
<div id="app">
<!-- <index-stencil></index-stencil> -->
<index-gaode></index-gaode>
<!-- <index-gaode></index-gaode> -->
<!-- <index-gojs></index-gojs> -->
<index-tx></index-tx>
</div>
</template>
@ -10,12 +11,14 @@
import indexStencil from "./demo/index-stencil.vue";
import indexGaode from "./demo/index-gaode.vue";
import indexGojs from "./gojsDemo/index-gojs.vue";
import indexTx from "./demo/index-tx.vue";
export default {
name: 'App',
components: {
indexStencil,
indexGaode,
indexGojs
indexGojs,
indexTx
}
}
</script>

821
src/demo/index-tx.vue Normal file
View File

@ -0,0 +1,821 @@
<template>
<div>
<div class="tools-bar" style="position: absolute;z-index: 10001;">
<el-popover placement="bottom" width="200" class="el-po" trigger="click">
<div ref="stencilContainer" class="x6-stencil"></div>
<i class="el-icon-s-operation opt-btn" slot="reference"></i>
</el-popover>
</div>
<div class="content" :style="{ height: contentHeight }">
<!-- <div ref="stencilContainer" class="x6-stencil"></div> -->
<div class="middle-box">
<div ref="container" class="x6-content" :style="{ height: contentHeight }" id="container"></div>
<div id="map-container11" class="mp-view" :style="{ height: contentHeight }"></div>
</div>
</div>
</div>
</template>
<script>
import { Graph, Shape, Addon, Path } from '@antv/x6';
const { Stencil } = Addon
const { Rect, Circle } = Shape
import AMapLoader from '@amap/amap-jsapi-loader';
export default {
data() {
return {
contentHeight: '0px', //x6
mapHeight: "200px", //
center: { lng: 0, lat: 0 },//
zoom: 3,//
graph: undefined,//x6
stencil: undefined,//x6
projection: undefined,//projection
map: null,//
data: {
//
nodes: [
{
id: 'node1', // String
x: 0, // Number x
y: 0, // Number y
width: 80, // Number width
height: 40, // Number height
label: 'hello', // String
},
{
id: 'node2', // String
x: 160, // Number x
y: 180, // Number y
width: 80, // Number width
height: 40, // Number height
label: 'world', // String
},
],
//
edges: [
{
source: 'node1', // String id
target: 'node2', // String id
},
],
}
}
},
mounted() {
this.init()
this.initCell()
this.initGraph();
this.initStencil()
this.initGaodeMap();
this.graph.disableMouseWheel();//
this.graph.zoom(0);//
},
methods: {
onRender() {
//
//
const container = this.$refs.container
const ports = container.querySelectorAll(
'.x6-port-body',
)
//
this.graph.getNodes().forEach((node) => {
let mapPoint = node.store.data.mapPoint
//
var lnglat = new TMap.LatLng(mapPoint.lat,mapPoint.lng)
var pixel = this.map.projectToContainer(lnglat);
let x6postion=this.graph.pageToLocal(pixel.round().x, pixel.round().y)
node.position(x6postion.x, x6postion.y);
})
},
init() {
this.contentHeight = document.documentElement.clientHeight - 45 + "px";
this.mapHeight = document.documentElement.clientHeight - 45 + "px";
},
//
initCell() {
//
const ports = {
groups: {
top: {
position: 'top',
attrs: {
circle: {
r: 4,
magnet: true,
stroke: '#5F95FF',
strokeWidth: 1,
fill: '#fff',
style: {
visibility: 'hidden',
},
},
},
},
right: {
position: 'right',
attrs: {
circle: {
r: 4,
magnet: true,
stroke: '#5F95FF',
strokeWidth: 1,
fill: '#fff',
style: {
visibility: 'hidden',
},
},
},
},
bottom: {
position: 'bottom',
attrs: {
circle: {
r: 4,
magnet: true,
stroke: '#5F95FF',
strokeWidth: 1,
fill: '#fff',
style: {
visibility: 'hidden',
},
},
},
},
left: {
position: 'left',
attrs: {
circle: {
r: 4,
magnet: true,
stroke: '#5F95FF',
strokeWidth: 1,
fill: '#fff',
style: {
visibility: 'hidden',
},
},
},
},
},
items: [
{
group: 'top',
},
{
group: 'right',
},
{
group: 'bottom',
},
{
group: 'left',
},
],
}
//
Graph.registerNode(
'custom-rect',
{
inherit: 'rect',
width: 66,
height: 36,
attrs: {
body: {
strokeWidth: 1,
stroke: '#5F95FF',
fill: '#EFF4FF',
},
text: {
fontSize: 12,
fill: '#262626',
},
},
ports: { ...ports },
},
true,
)
},
//
initGaodeMap() {
this.$nextTick(() => {
let map = new TMap.Map('map-container11', {
zoom: 12, //
center: new TMap.LatLng(39.984104, 116.307503),//
keyboardShortcuts: false, //
scrollwheel: false,
scrollable:false,
doubleClickZoom:false
});
var mapContainer = document.getElementById('container');
var x6 = document.getElementsByClassName("x6-content");
console.log(mapContainer)
// SVG - DOMOverlay
function SvgMarker(options) {
TMap.DOMOverlay.call(this, options);
}
SvgMarker.prototype = new TMap.DOMOverlay();
//
SvgMarker.prototype.onInit = function (options) {
this.options = options.options;
this.map = options.map;
};
SvgMarker.prototype.createDOM = function () {
let svg = x6[0];
svg.setAttribute('width', '100%');
svg.setAttribute('height', '100%');
svg.style.cssText = 'position:absolute;top:0px;left:0px;height:1000px';
return svg;
};
window.SvgMarker = SvgMarker;
//
console.log(123);
console.log(132)
var marker = new SvgMarker({
map,
options: [
{
position: new TMap.LatLng(39.96030543872138, 116.25809083213608),
id: 0,
},
]
});
marker.on('mouseenter', function (e) {
e.setAttribute('style', 'fill: red;stroke:red; opacity:0.9;');
});
marker.on('mouseleave', function (e) {
e.setAttribute('style', 'fill: blue;stroke:#FFFFFF;opacity:0.9;');
});
// svgsvg
map.on('resize', function () {
document.getElementById('svgDom').setAttribute('width', mapContainer.offsetWidth);
document.getElementById('svgDom').setAttribute('height', mapContainer.offsetHeight);
})
this.map = map;
this.map.on('pan', (e) => {
this.onRender();
// console.log(this.dataNodes);
});
this.map.on('dragend', (e) => {
this.onRender();
});
// this.graph.fromJSON(dataNodes);
let graph = this.graph;
//
// dataNodes.nodes[0].wx11 = graph.localToPage(0, 0).x;
// dataNodes.nodes[0].wy11 = graph.localToPage(0, 0).y;
// dataNodes.nodes[1].wx11 = graph.localToPage(0, 180).x;
// dataNodes.nodes[1].wy11 = graph.localToPage(0, 180).y;
// //
// dataNodes.nodes[0].address = this.map.unprojectFromContainer({ x: dataNodes.nodes[0].wx11, y: dataNodes.nodes[0].wy11 });
// dataNodes.nodes[1].address = this.map.unprojectFromContainer({ x: dataNodes.nodes[1].wx11, y: dataNodes.nodes[1].wy11 });
// this.dataNodes = dataNodes;
})
},
floatEqual(num1, num2) {
return Math.abs(num1 - num2) < Number.EPSILON;
},
//
initGraph() {
console.log("x6图层", this.$refs.container)
console.log("地图地图", this.map)
this.graph = new Graph({
container: this.$refs.container,
background: {//
color: 'transport', //
},
grid: {//
size: 10, // 10px
visible: true, //
},
panning: {//
enabled: true, //
// modifiers: 'shift', //
},
// mousewheel: {//
// enabled: true,
// modifiers: ['ctrl'],
// guard(e){//
// return true
// }
// },
snapline: true,//线
selecting: {///
enabled: true,///
// rubberband: true,//
showNodeSelectionBox: true,//
},
resizing: true,//
highlighting: {//
//
magnetAdsorbed: {
name: 'stroke',
args: {
attrs: {
//fill: '#5F95FF',
stroke: '#5F95FF',
},
},
},
//
embedding: {
name: 'stroke',
args: {
padding: -1,
attrs: {
stroke: '#73d13d',
},
},
},
},
connecting: {//线
//20
snap: {
radius: 20,
},
allowBlank: false,//
allowNode: false,//
allowEdge: false,//
anchor: 'center',// anchor
connectionPoint: 'anchor',//
router: {// vertices
name: 'manhattan',
args: {
padding: 1,
},
},
connector: {//
name: 'rounded',
args: {
radius: 8,
},
},
createEdge() {//
return new Shape.Edge({
attrs: {
line: {
//stroke: '#A2B1C3',
stroke: 'green',
strokeWidth: 3,
targetMarker: {
name: 'block',
width: 12,
height: 8,
},
},
},
zIndex: 20,
})
},
validateConnection({ targetMagnet }) {//
return !!targetMagnet
},
},
//
embedding: {
enabled: true,//
findParent(node) {// findParent
const bbox = node.node.getBBox()
return this.getNodes().filter((node) => {
// data.parent true
const data = node.getData()
if (data && data.canBeParent) {
const targetBBox = node.getBBox()
return bbox.isIntersectWithRect(targetBBox)
}
return false
})
}
},
//
translating: {
restrict(view) {
if (view) {
const cell = view.cell
if (cell.isNode()) {
const parent = cell.getParent()
if (parent) {
return parent.getBBox()
}
}
}
return null
},
},
});
//this.graph.fromJSON(this.data)
//
//
this.graph.on('node:mouseenter', (e) => {
const container = this.$refs.container
const ports = container.querySelectorAll(
'.x6-port-body',
)
this.showPorts(ports, true)
this.showNodeTool(e.node, true)
//
this.changeMapDrag(false)
})
//
this.graph.on('node:mouseleave', (e) => {
const container = this.$refs.container
const ports = container.querySelectorAll(
'.x6-port-body',
)
this.showPorts(ports, false)
this.showNodeTool(e.node, false)
//
// this.changeMapDrag(true)
// this.map.ismoved1 = false;
// setTimeout(() => {
// this.map.ismoved1 = true;
// }, 100);
})
//线线
this.graph.on('edge:mouseenter', (e) => {
this.showEdgeTool(e.edge, true)
})
//线线
this.graph.on('edge:mouseleave', (e) => {
this.showEdgeTool(e.edge, false)
})
//
this.graph.on('node:change:parent', ({ node }) => {
node.attr({
body: {
stroke: 'none',
fill: '#47C769',
},
label: {
text: '节点-过程',
},
})
})
//
this.graph.on('node:added', (args) => {
//
this.pixelToPoint(args.node, args.node.store.data.position)
})
//
this.graph.on('node:click', (args) => {
this.map.ismoved1 = false;
// this.map.ismoved1 = false;
// args.e.stopPropagation();
//
// this.pixelToPoint(args.node, args.node.store.data.position)
})
//
this.graph.on('node:change:position', (args) => {
//
// this.pixelToPoint(args.node, args.node.store.data.position)
})
this.graph.on('node:mouseup', (args) => {
//
this.pixelToPoint(args.node, args.node.store.data.position)
})
//
// this.graph.on('translate', ({ tx, ty }) => {
// console.log("tx",tx)
// //console.log("ty",ty)
// this.mapScrollBy(tx,ty)
// })
this.graph.on('blank:mousedown', (e) => {
// this.changeMapDrag(true);
})
this.graph.on('edge:click', (e) => {
console.log("dasd");
// e.stopPropagation();
// this.map.ismoved1 = false;
// setTimeout(() => {
// this.map.ismoved1 = true;
// },50);
})
//
this.graph.on('blank:mouseup', async (args) => {
this.map.ismoved1 = false;
//this.onRender();
// setTimeout(() => {
// this.map.ismoved1 = true;
// }, 200);
})
//
this.graph.on('blank:click', async ({ view, e }) => {
// this.map.ismoved1 = true;
// setTimeout(() => {
// this.map.ismoved1 = true;
// }, 200);
})
//
this.graph.on('node:mousedown', async ({ view, e }) => {
// this.map.ismoved1 = false;
// setTimeout(() => {
// this.map.ismoved1 = true;
// }, 50);
});
//
this.graph.on('node:mousemove', async ({ view, e }) => {
this.map.ismoved1 = false;
// setTimeout(() => {
// this.map.ismoved1 = true;
// }, 50);
});
this.graph.on('blank:mousedown', async ({ view, e }) => {
this.map.ismoved1 = true;
this.changeMapDrag(true);
//this.map.ismoved1 = false;
// this.map.ismoved1 = false;
// setTimeout(() => {
// this.map.ismoved1 = true;
// }, 50);
});
//线
this.graph.on('edge:mousedown', async ({ view, e }) => {
this.map.ismoved1 = false;
//this.map.ismoved1 = false;
// this.map.ismoved1 = false;
// setTimeout(() => {
// this.map.ismoved1 = true;
// }, 50);
});
//
this.graph.on('blank:mousewheel', (e) => {
console.log(this.graph.zoom());
console.log(e);
if (e.delta == -1) {
if (this.graph.zoom() == 5) {
this.graph.zoom(-2.5)
this.map.setZoom(13)
}
else if (this.graph.zoom() == 2.5) {
this.graph.zoom(-1.5);
this.map.setZoom(12)
}
else if (this.graph.zoom() == 1) {
this.graph.zoom(-0.5)
this.map.setZoom(11)
}
else if (this.graph.zoom() == 0.5) {
this.graph.zoom(-0.25)
this.map.setZoom(10)
}
else if (this.graph.zoom() == 0.25) {
this.graph.zoom(-0.05)
this.map.setZoom(9)
}
else if (this.graph.zoom() == 0.2) {
this.graph.zoom(-0.1)
this.map.setZoom(8)
}
else if (this.graph.zoom() == 0.1) {
this.graph.zoom(-0.05)
this.map.setZoom(7)
}
else if (this.graph.zoom() == 0.05) {
this.graph.zoom(-0.025)
this.map.setZoom(6)
}
else if (this.graph.zoom() == 0.025) {
this.graph.zoom(-0.015)
this.map.setZoom(5)
}
}
if (e.delta == 1) {
if (this.graph.zoom() == 2.5) {
this.graph.zoom(2.5)
this.map.setZoom(14)
}
else if (this.graph.zoom() == 1) {
this.graph.zoom(1.5)
this.map.setZoom(13)
}
else if (this.graph.zoom() == 0.5) {
this.graph.zoom(0.5)
this.map.setZoom(12)
}
else if (this.graph.zoom() == 0.25) {
this.graph.zoom(0.25)
this.map.setZoom(11)
}
else if (this.graph.zoom() == 0.2) {
this.graph.zoom(0.05)
this.map.setZoom(10)
}
else if (this.graph.zoom() == 0.1) {
this.graph.zoom(0.1)
this.map.setZoom(9)
}
else if (this.graph.zoom() == 0.05) {
this.graph.zoom(0.05)
this.map.setZoom(8)
}
else if (this.graph.zoom() == 0.025) {
this.graph.zoom(0.025)
this.map.setZoom(7)
}
else if (this.floatEqual(this.graph.zoom(), 0.01)) {
this.graph.zoom(0.015)
this.map.setZoom(6)
}
}
this.onRender();
// setTimeout(() => {
// this.onRender();
// }, 1000);
})
},
//Stencil
initStencil() {
this.stencil = new Stencil({
target: this.graph,//
stencilGraphWidth: 200,//
stencilGraphHeight: 80,//
groups: [
{
name: 'group1',//
title: '元素',//
collapsable: false,// true
},
],
})
//Stencil
this.$refs.stencilContainer.appendChild(this.stencil.container)
//
const process = this.graph.createNode({
shape: 'custom-rect',
label: '过程',
zIndex: 10,
attrs: {
body: {
stroke: 'none',
fill: '#3199FF',
},
},
})
const node = this.graph.createNode({
shape: 'custom-rect',
label: '节点',
zIndex: 1,
data: {
canBeParent: true,
},
})
//
this.stencil.load([process, node], 'group1')
},
///
showPorts(ports, show) {
ports.forEach(port => {
port.style.visibility = show ? 'visible' : 'hidden'
});
},
///
showNodeTool(node, show) {
if (show) {
node.addTools({
name: 'button-remove',
args: {
x: '100%',
y: 0,
offset: { x: -3, y: 3 },
},
})
} else {
node.removeTools()
}
},
//线/
showEdgeTool(edge, show) {
if (show) {
edge.addTools({
name: 'button-remove',
args: { distance: -40 },
})
} else {
edge.removeTools()
}
},
//
pixelToPoint(node, position) {
//x6
console.log(position);
let pmpostion=this.graph.localToPage(position.x, position.y);
console.log(pmpostion);
let ePoint =this.map.unprojectFromContainer({x:pmpostion.x, y:pmpostion.y});
console.log(ePoint)
//let ePoint = this.map.containerToLngLat(new AMap.Pixel(position.x, position.y))
//node
node.store.data.mapPoint = ePoint
console.log("新位置数据", node)
},
//
mapScrollBy(tx, ty) {
this.projection.panBy(tx, ty)
},
///
changeMapDrag(canDrag) {
// this.map.setStatus({
// dragEnable: canDrag
// })
this.map.setDraggable(canDrag)
}
}
}
</script>
<style lang="scss" scoped>
.tools-bar {
height: 45px;
line-height: 45px;
background: #fff;
display: flex;
.opt-btn {
margin-top: 4px;
font-size: 35px;
}
}
.content {
display: flex;
.x6-stencil {
width: 250px;
}
.middle-box {
width: 100%;
position: relative;
.x6-content {
width: 100%;
position: absolute;
z-index: 1;
}
.mp-view {
width: 100%;
position: absolute;
z-index: 2;
}
}
}
.el-popover {
height: 500px;
overflow: auto;
}
</style>
<style>
.el-popover {
height: 120px;
overflow: auto;
}
</style>