OpenLayers onmousedown load image

2019-09-05 08:38发布

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!

1条回答
Luminary・发光体
2楼-- · 2019-09-05 09:05

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.

查看更多
登录 后发表回答