11<template >
2- <div class =" map-container with-marker" :class =" ['marker-icon-' + markerIcon, isDirty ? '' : 'is-not-dirty']" >
3- <ol-map ref =" map" @click =" setDirty" :load-tiles-while-animating =" true" :load-tiles-while-interacting =" true"
4- :style =" mapStyles" >
5- <ol-view
6- @centerChanged =" onCenterChanged"
7- :center =" center"
8- :rotation =" rotation"
9- :zoom =" zoom"
10- :projection =" projection"
11- />
2+ <div class =" map-container" >
3+ <ol-map ref =" map" :load-tiles-while-animating =" true" :load-tiles-while-interacting =" true" :style =" mapStyles" >
4+ <ol-view :center =" center" :rotation =" rotation" :zoom =" zoom" :projection =" projection" />
125
136 <ol-tile-layer >
147 <ol-source-osm />
158 </ol-tile-layer >
169
10+ <ol-vector-layer >
11+ <ol-source-vector :projection =" projection" >
12+ <ol-feature v-if =" hasInitValue" >
13+ <ol-geom-point :coordinates =" [initValue.longitude, initValue.latitude]" />
14+ </ol-feature >
15+
16+ <template v-if =" ! isReadonly " >
17+ <ol-interaction-modify v-if =" isDirty" @modifyend =" onModifyEnd" />
18+ <ol-interaction-draw v-else type =" Point" @drawend =" onDrawEnd" />
19+ </template >
20+ </ol-source-vector >
21+
22+ <ol-style >
23+ <ol-style-icon :src =" markerIcon" :anchor =" [0.5, 1]" :scale =" 0.1" />
24+ </ol-style >
25+ </ol-vector-layer >
26+
27+
1728 <ol-zoom-control v-if =" withZoomControl" />
1829 <ol-zoomslider-control v-if =" withZoomSlider" />
1930 <ol-fullscreen-control v-if =" withFullScreenControl" />
@@ -33,6 +44,10 @@ export default {
3344 data () {
3445 return {
3546 isDirty: false ,
47+ initValue: {
48+ longitude: null ,
49+ latitude: null
50+ },
3651 fieldValue: {
3752 longitude: null ,
3853 latitude: null
@@ -42,6 +57,10 @@ export default {
4257 computed: {
4358 isReadonly () {
4459 return this .readonly === true
60+ },
61+
62+ hasInitValue () {
63+ return this .initValue .latitude && this .initValue .longitude
4564 }
4665 },
4766 methods: {
@@ -59,6 +78,10 @@ export default {
5978 ])
6079
6180 this .center = lonLat
81+ this .initValue = {
82+ longitude: lonLat[0 ],
83+ latitude: lonLat[1 ]
84+ }
6285
6386 this .setValue (lonLat[1 ], lonLat[0 ])
6487 }
@@ -70,8 +93,20 @@ export default {
7093 }
7194 },
7295
73- onCenterChanged (center ) {
74- this .setValue (center[1 ], center[0 ])
96+ onDrawEnd (evt ) {
97+ const coordinate = evt .feature ? .getGeometry ().getCoordinates ()
98+
99+ if (Array .isArray (coordinate)) {
100+ this .setValue (coordinate[1 ], coordinate[0 ])
101+ }
102+ },
103+
104+ onModifyEnd (evt ) {
105+ const coordinate = evt .features ? .getArray ()[0 ].getGeometry ().getCoordinates ()
106+
107+ if (Array .isArray (coordinate)) {
108+ this .setValue (coordinate[1 ], coordinate[0 ])
109+ }
75110 },
76111
77112 setDirty () {
0 commit comments