Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon arrow direction on Streetview map control #338

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/app/g3w-ol/controls/streetviewcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,30 @@ const StreetViewControl = function(options={}) {
this._panorama = null;
this._map = null;
this._projection = null;
this._lastposition = null;
/**
* Object contain previuos data referred to :
* - rotation: for array rotation
* - resolution: map view resolution
* - position: lat lng of streetview
* @type {{rotation: null, position: null, resolution: null}}
*/
this.cached = {
position: [0, 0],
resolution: null,
rotation: null
};
Comment on lines +42 to +53
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some tests, but even so the position seems to me to be often wrong (ie. not so deterministic)

this._streetViewFeature = new ol.Feature();
const streetVectorSource = new ol.source.Vector({features: []});
this.active = false;
this._layer = new ol.layer.Vector({
source: streetVectorSource,
style(feature) {
style: (feature, resolution) => {
const coordinates = feature.getGeometry().getCoordinates();
this._lastposition = this._lastposition ? this._lastposition : coordinates;
const dx = coordinates[0] - this._lastposition[0];
const dy = coordinates[1] - this._lastposition[1];
const rotation = -Math.atan2(dy, dx);
if (null === this.cached.resolution || this.cached.resolution === resolution) {
const dx = coordinates[0] - this.cached.position[0];
const dy = coordinates[1] - this.cached.position[1];
this.cached.rotation = -Math.atan2(dy, dx);
}
const styles = [
new ol.style.Style({
text: new ol.style.Text({
Expand All @@ -64,11 +76,12 @@ const StreetViewControl = function(options={}) {
new ol.style.Style({
image: new ol.style.Icon({
src: '/static/client/images/streetviewarrow.png',
rotation
rotation: this.cached.rotation
})
})
];
this._lastposition = coordinates;
this.cached.position = coordinates;
this.cached.resolution = resolution;
return styles
}
});
Expand Down Expand Up @@ -116,7 +129,6 @@ proto.setPosition = function(position) {
pitch: 0,
heading: 0
});

self._panorama.setPosition(data.location.latLng);
}
}).then(response => {
Expand Down