<el-option
v-for="item in TextWeightArray"
:key="item"
:label="item"
:value="item"
</el-option>
</el-select>
</el-form-item>
<el-form-item label="大小">
<el-input v-model="polygon.TextSize">
<span slot="append">px</span>
</el-input>
</el-form-item>
<el-form-item label="x偏移量">
<el-input v-model="polygon.TextOffsetX"> </el-input>
</el-form-item>
<el-form-item label="y偏移量">
<el-input v-model="polygon.TextOffsetY"> </el-input>
</el-form-item>
<el-form-item label="外框颜色">
<el-color-picker
v-model="polygon.TextColor"
></el-color-picker>
</el-form-item>
<el-form-item label="外框宽度">
<el-input v-model="polygon.TextOutlineColor"></el-input>
</el-form-item>
</el-tab-pane>
</el-tabs>
</el-card>
</el-col>
</el-row>
</el-form>
</div>
</template>
<style scoped>
.featruesStyle_BOX {
display: flex;
justify-content: space-between;
height: 800px;
.featruesStyle-demo {
width: 50%;
height: 800px;
.formClass {
width: 50%;
>>> .el-card__header {
padding: 10px;
font-size: 12px;
font-weight: bold;
>>> .el-card__body,
.el-main {
padding: 5px;
</style>
初始化公共方法和变量
let pointFeature = new Feature({
geometry: new Point(
transform(
[104.06576156616212, 30.657443157369386],
"EPSG:4326",
"EPSG:3857"
name: "Point Feature",
lineFeature = new Feature({
geometry: new LineString([
transform(
[104.06576156616212, 30.657443157369386],
"EPSG:4326",
"EPSG:3857"
transform(
[105.44677734375001, 28.86147544303663],
"EPSG:4326",
"EPSG:3857"
name: "Line Feature",
polygonFeature = new Feature({
geometry: new Polygon([
transform(
[104.20738220214845, 30.833966831300685],
"EPSG:4326",
"EPSG:3857"
transform(
[104.23150062561037, 30.84214707744351],
"EPSG:4326",
"EPSG:3857"
transform(
[104.22454833984376, 30.67368532516591],
"EPSG:4326",
"EPSG:3857"
transform(
[104.08550262451172, 30.668739135911846],
"EPSG:4326",
"EPSG:3857"
transform(
[104.20738220214845, 30.833966831300685],
"EPSG:4326",
"EPSG:3857"
name: "Line Feature",
function createText(
TextAglin,
TextBaseline,
TextFont,
FillColor,
TextColor,
TextOutlineColor,
TextOffsetX,
TextOffsetY,
TextRotation,
TextWeight,
TextSize,
feature
return new Text({
textAlign: TextAglin,
textBaseline: TextBaseline,
font: `${TextWeight} ${TextSize}px ${TextFont}`,
text: feature.get("name"),
fill: new Fill({ color: FillColor }),
stroke: new Stroke({ color: TextColor, width: TextOutlineColor }),
offsetX: TextOffsetX,
offsetY: TextOffsetY,
rotation: (TextRotation / 180) * Math.PI,
function createPointStyleFn(feature, Point) {
let { Size, FillColor, StrokeColor, StrokeWidth } = Point;
return new Style({
image: new CircleStyle({
radius: Size,
fill: new Fill({ color: FillColor }),
stroke: new Stroke({ color: StrokeColor, width: StrokeWidth }),
text: createText(Point, feature),
function createLineStyleFn(feature, Line) {
let { StrokeColor, StrokeWidth } = Line;
return new Style({
stroke: new Stroke({ color: StrokeColor, width: StrokeWidth }),
text: createText(Line, feature),
function createPolygonStyleFn(feature, Polygon) {
let { FillColor, StrokeColor, StrokeWidth } = Polygon;
return new Style({
fill: new Fill({ color: FillColor }),
stroke: new Stroke({ color: StrokeColor, width: StrokeWidth }),
text: createText(Polygon, feature),
Vue-data 初始化
data() {
return {
form: {},
activePoint: "first_Point",
activeLine: "first_Line",
activePolygon: "first_Polygon",
map: null,
vectorPoints: null,
vectorLine: null,
vectorPolygon: null,
polygon: {
FillColor: "#aa3300",
StrokeColor: "#f00",
StrokeWidth: "2",
TextAglin: "center",
TextBaseline: "middle",
TextRotation: 0,
TextFont: "Arial",
TextWeight: "normal",
TextSize: "12",
TextOffsetX: "0",
TextOffsetY: "0",
TextColor: "#0ff",
TextOutlineColor: "3",
point: {
Size: 10,
FillColor: "#aa3300",
StrokeColor: "#f00",
StrokeWidth: "2",
TextAglin: "center",
TextBaseline: "middle",
TextRotation: 0,
TextFont: "Arial",
TextWeight: "normal",
TextSize: "12",
TextOffsetX: "0",
TextOffsetY: "0",
TextColor: "#0ff",
TextOutlineColor: "3",
line: {
StrokeColor: "#f00",
StrokeWidth: "2",
TextAglin: "center",
TextBaseline: "middle",
TextRotation: 0,
TextFont: "Arial",
TextWeight: "normal",
TextSize: "12",
TextOffsetX: "0",
TextOffsetY: "0",
TextColor: "#0ff",
TextOutlineColor: "3",
TextWeightArray: ["normal", "bold", "bolder"],
pointTextFontArray: ["Arial", "Courier New", "Verdana"],
TextAglinArray: ["center", "end", "left", "right", "start"],
TextBaselineArray: [
"alphabetic",
"bottom",
"hanging",
"ideographic",
"middle",
"top",
Map 初始化
mounted() {
let { point, polygon, line } = this;
let vectorPoints = new VectorLayer({
source: new VectorSource({
features: [pointFeature],
style: createPointStyleFn(pointFeature, point),
vectorLine = new VectorLayer({
source: new VectorSource({
features: [lineFeature],
style: createLineStyleFn(lineFeature, line),
vectorPolygon = new VectorLayer({
source: new VectorSource({
features: [polygonFeature],
style: createPolygonStyleFn(polygonFeature, polygon),
let map = new Map({
layers: [gaodeMapLayer, vectorPoints, vectorLine, vectorPolygon],
view: new View({
center: transform([104.065735, 30.659462], "EPSG:4326", "EPSG:3857"),
zoom: 9,
minZoom: 1,
maxZoom: 21,
rotation: 0,
target: "featruesStyle",
this.vectorPoints = vectorPoints;
this.vectorLine = vectorLine;
this.vectorPolygon = vectorPolygon;
this.map = map;
methods: {
PonitUp() {
let { point, vectorPoints } = this;
vectorPoints.setStyle(createPointStyleFn(pointFeature, point));
LineUp() {
let { line, vectorLine } = this;
vectorLine.setStyle(createLineStyleFn(lineFeature, line));
polygonUp() {
let { polygon, vectorPolygon } = this;
vectorPolygon.setStyle(createPolygonStyleFn(polygonFeature, polygon));
复制代码