# ctCustomMap **Repository Path**: gao-weidong/ct-custom-map ## Basic Information - **Project Name**: ctCustomMap - **Description**: 使用maptalks地图工具构建的vue版本地图。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 2 - **Created**: 2021-11-16 - **Last Updated**: 2025-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ``` ``` # **ct-map文档** ## 一.功能标签概览 ```vue ``` 目前该 **VUE组件** 包含 **marker,海量marker,多边形,圆形,热力图,两点之间的连线,多点之间连线,轨迹,绘图控件** 等地图渲染能力。 ## 二.开始 ### **2.1 引入地图** 我们通过一个例子来说明如何创建一个简单的地图。下面是DEMO示例。 **(必须要为地图指定高度,否则无法显示;文档以后部分则不再重复指定 map-id与height)** ```html
``` ```javascript var vm = new Vue({ data: { mapId: 'mapId', }, }) ``` ```css .parent-map-container { margin: 5px; border: 10px inset; height: 900px; width: 500px; } ``` 地图效果: ![error](png/mapinit.png) 至此我们完成了一个完整的地图展示的例子,可以试着在地图区域按住鼠标右键进行拖动,地图的视角和旋转角度会随之改变。 #### 2.1.1 **指定层级和中心点** ```html
``` ![error](/png/mapinit.png) #### 2.1.2 概览、比例尺、Zoom 缩放等控件 ```html
``` ![error](/png/controller.png) #### 2.1.3 图层切换 ```html
``` ```javascript var vm = new Vue({ data: { layer: 'Baidu', //不指定 默认为百度, 目前 :Baidu Amap }, }) ``` *百度 Baidu* ![error](/png/baidulayter.png) *高德 Amap* ![error](/png/gdlayter.png) ### **2.2 Marker** ```html
``` ![error](/png/marker1.png) #### 2.2.1 自定义Marker——图片 ```html
``` ```javascript const myPng = require('@/assets/vue.png'); var vm = new Vue({ data: () => ({ iconSymbol: { markerFile: myPng, markerWidth: 30, // 图片宽 markerHeight: 30, // 图片高 markerOpacity: 1, // 图片透明度 }, }) }) ``` ![error](/png/custonmarker.png) #### 2.2.2 自定义Marker——文字 ```html
``` ```javascript var vm = new Vue({ data: () => ({ textSymbol: { textFaceName: 'sans-serif', textName: 'MapTalks', // 文字内容 textFill: 'red', // 文字颜色 textHorizontalAlignment: 'right', // 文字对齐方式 textSize: 20, // 字号 }, }) }) ``` ![error](/png/textmarker.png) #### 2.2.2 自定义Marker——文字 + 图片 ```html
``` ```javascript const myPng = require('@/assets/vue.png'); var vm = new Vue({ data: () => ({ iconTextSymbol: { markerFile: myPng, markerWidth: 30, // 图片大小 markerHeight: 30, // 图片大小 markerOpacity: 1, // 图片透明度 textFaceName: 'sans-serif', textName: 'MapTalks', textFill: 'rgb(230 46 156)', textHorizontalAlignment: 'bottom', textSize: 20, }, }) }) ``` ![error](/png/icontextmarker.png) ### **2.3 海量 Marker** ```html
``` ```javascript const myPng = require('@/assets/vue.png'); var vm = new Vue({ data: () => ({ multiMarker1000: [], iconSymbol: { markerFile: myPng, markerWidth: 30, // 图片大小 markerHeight: 30, // 图片大小 markerOpacity: 1, // 图片透明度 }, }), methods: { createManyPoint() { for (let i = 0; i < 1000; i += 1) { const x = 126.6172 + Math.random() * 0.1 - Math.random() * 0.1; const y = 45.78064 + Math.random() * 0.1 - Math.random() * 0.1; this.multiMarker1000.push([x, y]); } }, }, mounted() { this.createManyPoint(); } }) ``` ![error](/png/multimarker.png) ### 2.4 Cluster 聚合 ```html
``` ```javascript const myPng = require('@/assets/vue.png'); var vm = new Vue({ data: () => ({ multiMarker1000: [], }), methods: { createManyPoint() { for (let i = 0; i < 1000; i += 1) { const x = 126.6172 + Math.random() * 0.1 - Math.random() * 0.1; const y = 45.78064 + Math.random() * 0.1 - Math.random() * 0.1; this.multiMarker1000.push([x, y]); } }, }, mounted() { this.createManyPoint(); } }) ``` ![error](/png/clustermarker.png) ### **2.5 Polygon 多边形** ```html
``` ```javascript var vm = new Vue({ data: () => ({ polygonPointGroup3: [ [ [126.59219, 45.78986], [126.60318, 45.79488], [126.60112, 45.78339], ], ], polygonSymbol3: { lineColor: '#34495e', lineWidth: 4, polygonFill: 'rgb(135,196,240)', // '#1bbc9b' 'rgb(135,196,240)' polygonOpacity: 1, textName: 'polygon', textFill: 'rgb(230 46 156)', }, }), }) ``` ![error](/png/polygon.png) ### 2.6 Circle 圆形 ```html
``` ```javascript var vm = new Vue({ data: () => ({ circleCenter3: [126.57337, 45.76436], circleSymbol3: { textName: 'circle-center', lineColor: 'grey', lineWidth: 3, polygonFill: '#1bbc9b', polygonOpacity: 1, }, radius: 500 // 半径米 }), }) ``` ![error](/png/circle.png) ### 2.7 Heat 热力图 ```html
``` ```javascript var vm = new Vue({ data: () => ({ heatData: [ [126.52975, 45.74962, 0.1], // x,y,权重 [126.54846, 45.7501, 0.5], [126.56821, 45.75022, 1], ], }), methods: { createManyPoint() { for (let i = 0; i < 1000; i += 1) { const x = 126.6172 + Math.random() * 0.1 - Math.random() * 0.1; const y = 45.78064 + Math.random() * 0.1 - Math.random() * 0.1; this.heatData.push([x, y, 0.1]); } }, }, mounted() { this.createManyPoint(); } }) ``` ![error](/png/heat.png) ### 2.8 Link 连线(两点) ```html
``` ```javascript var vm = new Vue({ data: () => ({ lineType: 'arc', // 有弧度的线 pointPair1: [[126.52494, 45.73597], [126.55911, 45.73549]], pointPair2: [[126.57852, 45.73621], [126.60788, 45.73681]], pointPair3: [[126.62677, 45.73956], [126.69512, 45.73932]], linkSymbol1: { lineColor: '#1bbc9b', // 线的颜色 lineWidth: 1, // 线宽度 }, linkSymbol2: { lineColor: 'red', lineWidth: 3, }, linkSymbol3: { lineColor: 'red', lineWidth: 3, }, }), }) ``` ![error](/png/link.png) ### 2.9 Line 连线(多点相连) ```html
``` ```javascript var vm = new Vue({ data: () => ({ pointOfLine: [ [126.51922, 45.72297], [126.53644, 45.72854], [126.55362, 45.72051], [126.56993, 45.72758], ], }), }) ``` ![error](/png/line.png) ### 2.10 Track 轨迹点移动 ```html
``` ```javascript var vm = new Vue({ data: () => ({ track: [ [126.52474, 45.71304], [126.56244, 45.71126], [126.58693, 45.71572], [126.60084, 45.70133], [126.57302, 45.69318], [126.52769, 45.69402], ], iconSymbol: { markerFile: myPng1, markerWidth: 30, // 图片大小 markerHeight: 30, // 图片大小 markerOpacity: 1, // 图片透明度 }, }), }) ``` ![error](/png/track.png) ### 2.11 Draw Controller 绘图控件 ```html
``` ![error](/png/drawcontroller.png) ## 三. Symbol 属性 对于地图元素的样式对象 `Symbol` 有以下属性: - opacity - shadowBlur - shadowColor - shadowOffsetX - shadowOffsetY | **Marker** | Text | Polygons and Lines | | :-----------------------: | :---------------------: | :----------------: | | markerOpacity | textPlacement | lineColor | | markerWidth | textFaceName | lineWidth | | markerHeight | textFont | lineDasharray | | markerDx | textWeight | lineOpacity | | markerDy | textStyle | lineJoin | | markerHorizontalAlignment | textSize | lineCap | | markerVerticalAlignment | textFill | linePatternFile | | markerPlacement | textOpacity | lineDx | | markerRotation | textHaloFill | lineDy | | | textHaloRadius | | | markerFile | textHaloOpacity | polygonFill | | | textWrapWidth | polygonOpacity | | markerType | textWrapCharacter | polygonPatternFile | | markerFill | textLineSpacing | | | markerFillPatternFile | textHorizontalAlignment | | | markerFillOpacity | textVerticalAlignment | | | markerLineColor | textAlign | | | markerLineWidth | textRotation | | | markerLineOpacity | textDx | | | markerLineDasharray | textDy | | | markerLinePatternFile | | | | | | | | markerPath | | | | markerPathWidth | | | | markerPathHeight | | | `Symbol` 类别和 几何图形 ( Markers, Polygons, Lines) 的应用规则 | Symbol 类别 | 可以被应用于 | | :----------: | :----------------------: | | Marker | Markers, Polygons, Lines | | Text | Markers, Polygons, Lines | | Line | Polygons, Lines | | Polygon | Polygons | ------ Symbol Properties ### All ##### opacity `float` Default Value : `1` The overall opacity of the geometry. ------ ##### shadowBlur `number` Default Value : `0` level of the shadow around the geometry, see [MDN's explanation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/shadowBlur) ------ ##### shadowColor `color` Default Value : `black` color of the shadow around the geometry, a CSS style color ------ ##### shadowOffsetX `float` Default Value : `0` A float specifying the distance that the shadow will be offset in horizontal distance. ------ ##### shadowOffsetY `float` Default Value : `0` A float specifying the distance that the shadow will be offset in vertical distance. ### Marker Common Properties ##### markerOpacity `Number` Default Value: `1` (The stroke-opacity and fill-opacity of the marker.) The overall opacity of the marker. ------ ##### markerWidth `float` Default Value: `10` for Vector Marker and `none` for others The width of the marker. ------ ##### markerHeight `float` Default Value: `10` for Vector Marker and `none` for others The height of the marker. ------ ##### markerDx `float` Default Value: `0` *(Marker will not be displaced.)* Displace marker by fixed amount, in pixels, +/- along the X axis. A positive value will shift the marker right. ------ ##### markerDy `float` Default Value: `0` *(Marker will not be displaced.)* Displace marker by fixed amount, in pixels, +/- along the Y axis. A positive value will shift the marker down. ------ ##### markerHorizontalAlignment `keyword` ``` left middle right ``` Default Value: `middle` for markerFile, `middle` or `top` for different markerType The marker's horizontal alignment from it's centerpoint. ------ ##### markerVerticalAlignment `keyword` ``` top middle bottom ``` Default Value: `bottom` for markerFile, `middle` or `bottom` for different markerType The marker's vertical alignment from it's centerpoint. ------ ##### markerPlacement `keyword` ``` point vertex line vertex-first vertex-last ``` Default Value: `point` *(Place markers at the center point (centroid) of the geometry.)* Attempt to place markers on a point, in the center of a polygon, or if markerPlacement:line, then multiple times along a line. Vertex places on the vertexes of polygons or lines. The 'vertex-first' and 'vertex-last' options can be used to place markers at the first or last vertex of lines or polygons. ------ ##### markerRotation `float` Default Value : `none` *(Marker will not rotate)* The degree that marker rotates around marker's placing point. The rotation begins at right side of X-axis (0 degree) and is in a counterclockwise direction. ### Image Marker ##### markerFile `string` Default Value: `none` A file that this marker shows at each placement. If no file is given, it may throw an error of failing to create any symbolizer. Values of `markerFile` can be anything that HTML Image element supported: - URL: `http://www.foo.com/foo.png` or `images/foo.png` - Base64: A png: `data:image/png;base64,iVBORw0..` or a SVG: `data:image/svg+xml;base64,PD94bWwgdm..` ### Vector Marker ##### markerType `keyword` ``` ellipse cross x diamond bar square triangle pin pie ``` The vector marker's shape. ------ ##### markerFill `color` Default Value: `blue` *(The marker fill color is blue.)* The color of the area of the marker. ------ ##### markerFillPatternFile `string` Default Value: `none` Image to use as a repeated pattern fill within a marker. Any format that HTML Image can accept. ------ ##### markerFillOpacity `float` Default Value: `1` *(Color is fully opaque.)* The fill opacity of the marker. ------ ##### markerLineColor `color` Default Value: `black` *(The marker will be drawn with a black outline.)* The color of the stroke around the marker. ------ ##### markerLineWidth `float` Default Value: `1` *(The marker will be drawn with an outline of 1 pixels wide.)* The width of the stroke around the marker, in pixels. This is positioned on the boundary, so high values can cover the area itself. ------ ##### markerLineOpacity `float` Default Value: `1` *(Color is fully opaque.)* The opacity of marker's stroke. ------ ##### markerLineDasharray `numbers` Default Value: `none` *(The line will be drawn without dashes.)* A pair of length values [a,b], where (a) is the dash length and (b) is the gap length respectively. More than two values are supported for more complex patterns. ------ ##### markerLinePatternFile `string` Default Value: `none` An image file to be repeated and warped along marker's line. Any format that HTML Image can accept. ------ ##### markerPath `string|object|objects` Default Value: ''none`` A SVG path or pathes to define the marker's shape, if set it will override **markerType**. Possible values: - Path string: `M8 23l0 0 0 0 0 0 0 0 0 0c-4,-5 -8,-10 -8,-14 0,-5 4,-9 8,-9l0 0 0 0c4,0 8,4 8,9 0,4 -4,9 -8,14z M5,9 a3,3 0,1,0,0,-0.9Z` - A Path Object with Style Properties (same with SVG): ``` { 'path' : 'M8 23l0 0 0 0 0 0 0 0 0 0c-4,-5 -8,-10 -8,-14 0,-5 4,-9 8,-9l0 0 0 0c4,0 8,4 8,9 0,4 -4,9 -8,14z M5,9 a3,3 0,1,0,0,-0.9Z', 'fill' : '#DE3333', 'stroke' : '#000' } ``` - An Array of Path Objects: ``` [ {transform:"matrix(1,0,0,1,200,200)", path:"M-122.304 84.285C-122.304 84.285 -122.203 86.179 -123.027 86.16C-123.851 86.141 -140.305 38.066 -160.833 40.309C-160.833 40.309 -143.05 32.956 -122.304 84.285z","stroke-width":"0.172",stroke:"#000",fill:"#fff"}, {transform:"matrix(1,0,0,1,200,200)", path:"M-118.774 81.262C-118.774 81.262 -119.323 83.078 -120.092 82.779C-120.86 82.481 -119.977 31.675 -140.043 26.801C-140.043 26.801 -120.82 25.937 -118.774 81.262z","stroke-width":"0.172",stroke:"#000",fill:"#fff"} ] ``` ------ ##### markerPathWidth `float` Default Value: `80` *(The markerPath's width is 10 pixels.)* Applied to **markerPath**, width property of the generated SVG element, like the width in `