Skip to content

Commit c9889ba

Browse files
committed
Merge pull request #194 from ageblade/master
fix(marker): Improve draggable marker support for static image
2 parents ead5fe5 + 7eb676e commit c9889ba

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/directives/marker.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ angular.module('openlayers-directive').directive('olMarker', function($log, $q,
109109
coord = coord.map(function(v) {
110110
return parseInt(v, 10);
111111
});
112+
} else {
113+
coord = ol.proj.transform(coord, proj, 'EPSG:4326');
112114
}
113-
coord = ol.proj.transform(coord, proj, 'EPSG:4326');
114115

115116
if (evt.type === 'pointerdown') {
116117
// Get feature under mouse if any
@@ -124,7 +125,11 @@ angular.module('openlayers-directive').directive('olMarker', function($log, $q,
124125
return;
125126
}
126127
map.getTarget().style.cursor = 'pointer';
127-
pickOffset = [coord[0] - pickProperties.lon, coord[1] - pickProperties.lat];
128+
if (proj === 'pixel') {
129+
pickOffset = [coord[0] - pickProperties.coord[0], coord[1] - pickProperties.coord[1]];
130+
} else {
131+
pickOffset = [coord[0] - pickProperties.lon, coord[1] - pickProperties.lat];
132+
}
128133
evt.preventDefault();
129134
} else if (pickOffset && pickProperties) {
130135
if (evt.type === 'pointerup') {
@@ -136,8 +141,13 @@ angular.module('openlayers-directive').directive('olMarker', function($log, $q,
136141
evt.preventDefault();
137142
scope.$apply(function() {
138143
// Add current delta to marker initial position
139-
pickProperties.lon = coord[0] - pickOffset[0];
140-
pickProperties.lat = coord[1] - pickOffset[1];
144+
if (proj === 'pixel') {
145+
pickProperties.coord[0] = coord[0] - pickOffset[0];
146+
pickProperties.coord[1] = coord[1] - pickOffset[1];
147+
} else {
148+
pickProperties.lon = coord[0] - pickOffset[0];
149+
pickProperties.lat = coord[1] - pickOffset[1];
150+
}
141151
});
142152
}
143153
}
@@ -336,8 +346,13 @@ angular.module('openlayers-directive').directive('olMarker', function($log, $q,
336346
marker.set('marker', properties);
337347
markerLayer.getSource().addFeature(marker);
338348
} else {
339-
var requestedPosition = ol.proj.transform([properties.lon, properties.lat], data.projection,
340-
map.getView().getProjection());
349+
var requestedPosition;
350+
if (properties.projection === 'pixel') {
351+
requestedPosition = properties.coord;
352+
} else {
353+
requestedPosition = ol.proj.transform([properties.lon, properties.lat], data.projection,
354+
map.getView().getProjection());
355+
}
341356

342357
if (!angular.equals(marker.getGeometry().getCoordinates(), requestedPosition)) {
343358
var geometry = new ol.geom.Point(requestedPosition);

0 commit comments

Comments
 (0)