The simple answer is Yes and the OpenLayers example you have found will do exactly what you are after.
I agree with your comment regarding WFS, although do not rule it out totally as you can restrict the amount of data that is served as Features onto your OpenLayers page uses different strategies, like bounding box. What this means is that not all the 3mill lines will be served to your web page only the ones that intersect the bounding box of your OpenLayers DIV box.
Having said that if all you want is a click and get info then definitely use WMS, its performance will be significantly better than a WFS.
To point you in the right directyion (not sure if you a newbie?) look at the GeoServer docs along with the OpenGeo GeoServer and OpenLayers workshops.http://workshops.opengeo.org/
If all of this is new then I have found the simplest way to get started is ot use the OpenGeo Suite, that way you do not need to figure out how to deploy GeoServer using Tomcat or similar.
Other options could be QGIS Cloud, GIS Cloud and similar where you load the data yourself to their host cloud storage, compose and map and then either embed or share that map.
Its a good way if you do not want to manage the servers yourself
Hope this helps you to get started
For WMS called from GeoServer v.2.11.0 with OpenLayers v.3.8.2 (check your versions):
name.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>WMS</title>
<!-- OpenLayers CSS v.3.8.2.-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.8.2/ol.min.css" type="text/css">
<!-- JQuery (v.1.11.4.)-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.css" type="text/css">
<!-- external css -->
<link rel="stylesheet" href="name.css">
<!-- Proj4 -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script>
<!-- Proj4~EPSG:5255 -->
<script src="http://epsg.io/5255.js"></script>
<style>
</style>
</head>
<body>
<div id="map"></div>
<!-- JavaScript -->
<!-- JQuery JS -->
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<!-- JQuery UI JS -->
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<!-- OpenLayers JS -->
<script src="http://openlayers.org/en/v3.8.2/build/ol-debug.js" type="text/javascript"></script>
<!-- OpenLayers JS v.3.8.2.-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.8.2/ol.min.js" type="text/javascript"></script>
<!-- external script -->
<script src="name.js"></script>
</body>
</html>
name.css: (do as you please)
html, body, #map{
width:100%; height:100%;
overflow: hidden;
}
#map{
position:absolute;
z-index:-1;
top:0; bottom:0;
}
.ol-control button{
border-radius: 50% !important;
}
name.js:
// I usually get defined EPSG from this site: http://spatialreference.org/, however it doesnt give me any vaild result for your projection...very strange, so I took it from this site as defined in html https://epsg.io/5255 ... copied code* and extent
var projection = new ol.proj.Projection({
code: 'EPSG: 5255', // *code says: 5261 ...try to see if this is right
extent: [-179106.47, 3835054.33, 1457898.22, 4881225.40]
});
// wms
// source
var layerSource = new ol.source.TileWMS({
url: 'http://yourIP/geoserver/nameOfWorkspace/wms',
params: {'VERSION': '1.3.0',
'LAYERS': 'nameOfWorkspace:nameOfLayer ',
'TILED': true,
'bbox': [number.number, number.number, number.number, number.number], // GeoServer bbox or extent in EPGS: 5255 - read from url in GeoServer WMS
'CRS': 'EPSG:5255',
'FORMAT': 'image/png8'},
serverType: 'geoserver',
});
// layer
var layerLayer = new ol.layer.Tile({
layer:'nameOfLayer',
visible: false,
preload: Infinity,
source: layerSource
});
// view
var olview = new ol.View({
projection: projection,
center: [number.number, number.number], // center calculated from ol3 with map.getView().getCenter();
extent: projection.getExtent(),
zoom: 1.5
})
// map
var map = new ol.Map({
target: 'map',
renderer: 'canvas', // Force the renderer to be used
view: olview,
layers: [layerLayer],
controls: ol.control.defaults(),
logo: false
});
Give feedback if it works or not!
Best Answer
Doesn't seem that OpenLayers provide any event to handle the clicks while drawing, but it can be done.
The map 'click' event recives all the clicks made on the map, so the problem is to distinguish those clicks done while drawing a feature. This can be achieved with the 'drawstart' and 'drawend' events from the 'Draw' interaction object. You can set a boolean variable to true when 'drawstart' is called, and to false when 'drawend' is called. Then, on the map 'click' event, check this variable to know if the click was made while drawing, and then, if it is, test whether the click is valid or invalid. If the click is invalid, call the 'removeLastPoint' method from the 'Draw' interaction object.
Here is a working fiddle can try. It only allows drawing inside the green box:
https://jsfiddle.net/o2vehqk8/
EDIT. I've forgot the asynchronous part... You can still call the async method inside the click event, and call the 'removeLastPoint' when the async method returns that the coordinate is invalid. The problem will be when the wms service is slow, so it has to avoid the user to draw while the point isn't still validated.