Skip to content
Advertisement

Kinetic layer on top of Openlayers

I developed a canvas visualization of OpenStreetMaps by means of miscellaneous scripts and rendering algorithms from the internet. On top of this I have a Kinetic Stage which draws custom objects which cannot be drawn by the functionality of Openlayers.

Openlayers provides many functions which I want to use and therefore I’m trying to switch over to this framework. I’m currently stuck with the event propagation, because I don’t know how to propagate an event to Openlayers.

index.html

JavaScript

style.css

JavaScript

ol.js

JavaScript

main.js

JavaScript

Due to a higher z-index of the Kinetic Stage the event is recognized there. The event propagation is only stopped if a Kinetic Shape is hit!

Is there any suitable method in Openlayers which accepts events? (I found OpenLayers.Events.triggerEvent, but I didn’t succeed with it)

Advertisement

Answer

I came up with a solution which is almost satisfying. Only a few events have to be handled by the user. Replacing the TODO’s with

JavaScript

enables the drag&drop function on the map. Here is an example how to handle the mousewheel event:

JavaScript

The controls of OpenLayers cannot be used, because they only react on click events and not on mousedown ones. I tried to convert the mousedown event to a click one, but then the drag&drop didn’t work anymore. Thus, I did a workaround which raises only the controls to the top as follows:

JavaScript

So this is my first scratch solution, but I think there is potential to improve it …

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement