From 8c66c4773dba920e5b95fd8704712796b7fa93ea Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Fri, 14 Apr 2017 18:22:23 +0000
Subject: [PATCH] Fix cursor pointer change on hovering over active element

---
 map.html |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/map.html b/map.html
index 0f16846..fd15e24 100644
--- a/map.html
+++ b/map.html
@@ -66,6 +66,18 @@
 	}
 }
 
+function popupHide() {
+	popup.setPosition(undefined);
+	popup_feature_id = null;
+}
+
+function popupShow(coordinates, id) {
+	popup.setPosition(coordinates);
+	if(id) {
+		popup_feature_id = id;
+	}
+}
+
 function init() {
 	if(!window.jQuery) {
 		fail(lang.jquery_not_loaded);
@@ -107,8 +119,8 @@
 	});
 	
 	// display popup on click
-	map.on('singleclick', function(evt) {
-		var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature) { return feature; });
+	map.on('singleclick', function(e) {
+		var feature = map.forEachFeatureAtPixel(e.pixel, function(feature) { return feature; });
 		if(feature) {
 			var coordinates = feature.getGeometry().getCoordinates();
 			
@@ -120,21 +132,17 @@
 				addParaWithText(popup_element, vehicle_type.num + ' ' + vehicle_type.type);
 			}
 			
-			popup.setPosition(coordinates);
-			popup_feature_id = feature.getId();
+			popupShow(coordinates, feature.getId());
 		} else {
-			popup.setPosition(undefined);
-			popup_feature_id = null;
+			popupHide();
 		}
 	});
 
 	// change mouse cursor when over marker
 	map.on('pointermove', function(e) {
-		var pixel = map.getEventPixel(e.originalEvent);
-		var hit = map.hasFeatureAtPixel(pixel);
-		var target = map.getTarget();
-		if(target.style)
-			target.style.cursor = hit ? 'pointer' : '';
+		var hit = map.hasFeatureAtPixel(e.pixel);
+		var target = map.getTargetElement();
+		target.style.cursor = hit ? 'pointer' : '';
 	});
 }
 
@@ -196,7 +204,8 @@
 						stroke: new ol.style.Stroke({color: color_type, width: 2}),
 						points: 3,
 						radius: 12,
-						rotation: Math.PI * 2.0 * vehicle.heading / 360.0,
+						rotation: Math.PI * parseFloat(vehicle.heading) / 180.0,
+						rotateWithView: true,
 						angle: 0
 					}),
 					text: new ol.style.Text({
@@ -208,8 +217,10 @@
 				vehicles_source.addFeature(vehicle_feature);
 			} else {
 				vehicle_feature.setProperties(vehicle);
-				if(popup_feature_id == vehicle.id) {
-					popup.setPosition(vehicle_feature.getGeometry().getCoordinates());
+				vehicle_feature.getStyle().getImage().setRotation(Math.PI * parseFloat(vehicle.heading) / 180.0);
+				
+				if(popup_feature_id == vehicle_feature.getId()) {
+					popupShow(vehicle_feature.getGeometry().getCoordinates());
 				}
 			}
 		}

--
Gitblit v1.9.1