Search code examples
openlayers-3onmousedownloadimage

OpenLayers onmousedown load image


I was looking at this example of openLayers ( http://openlayers.org/en/v3.14.1/examples/custom-interactions.html?q=custom ) and I was wondering how can I load a small image like the one in the example on mouse down on the map? I tried several things but couldn't figure it out. Any ideas?

Thanks!


Solution

  • The example you link to uses custom interactions to drag existing features around the map - this code is very useful and I used it to work out how to drag markers around my map.

    However, there is a simpler way to add the markers in the first place, which is to use the map's singleclick event handler:

    map.on("singleclick", function(event) {
        // Add icon here...
    })
    

    I've put a complete example here, showing how I did it:

    http://www.freytag.org.uk/pages/2016/03/06/openlayers-addfeature.html

    Once you've got that working, you can use the custom interactions in the OL3 example to then drag those markers around the map.