OpenLayers onmousedown load image

我是研究僧i 提交于 2019-12-13 06:44:55

问题


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:


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.



来源:https://stackoverflow.com/questions/35826118/openlayers-onmousedown-load-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!