0

i saw your code to create a buffer around a point. on the link: How to add a buffer on a point in OpenLayers 3

in following code..

var pointFeature = new ol.Feature(
new ol.geom.Point([0,0])
);
  1. How can I pass the coordinate of a point where a user click on map.

  2. I have 2 layer in my map which holds the different features with in it. I want to create buffer on a particular layer which will be given by user.

  3. I have one popUp implemented on map.onclick already. And somehow i have implemented buffer also on map's click event(separately).

How can I manage both popUp and Buffer on map's click event?

0

Openlayers has its own implementation of events, so you need to add event handler on click as you've probably done since you mention it in 3 (example here). Map click event has its own coordinates, which you can access by evt.coordinate. However click coordinates will slightly differ from the point coordinate, to access that you should use forEachFeatureAtPixel, some tutorial here. This function is called for every feature that intersect the pixel user clicked, and passes the feature and corresponding layer. For point buffer I would suggest to create Circle Geometry with center on the point, and some radius. To your final question i would make something like this:

var radius = 5000;//the distance of the buffer
map.on('click', function(e){
  var feat = map.forEachFeatureAtPixel(e.pixel, function(feature, layer) {
      //if feature is in the layer you want
      return feature;
    });
  var point = feat.getGeometry().getCoordinates();
  var buffer = new ol.Feature({geometry:new ol.geom.Circle(point,radius)});
  myLayer.getSource().addFeature(buffer)//add the buffer to some source
  content.innerHTML = '<p>You clicked here:</p><code>' + hdms + '</code>'; 
  //based on the example of popup i have mentioned
  overlay.setPosition(point);
})
  • thanks to reply. i have added a vector layer named "vectorLayer1" on the map that contains only polygon features. Further i added point data from taking a CSV file from user, on the map in another vector layer named "vectorLayer2". – Reema Gupta Jul 6 '18 at 12:26
0

thanks to reply. i have added a vector layer named "vectorLayer1" on the map that contains only polygon features. Further i added point data from taking a CSV file from user, on the map in another vector layer named "vectorLayer2". I have created a buffer of some radius around map.onclick . Now i want to highlight the points which are lying inside that buffer (By providing some distinct icon style to the point lying inside the buffer) by returning the feature from vector layer named "vectorLayer2". the below code returns the point feature from vector layer named "vectorLayer1".
Is there any way to pass a particular layer in the below code. map.on('click', function(e){ var feat = map.forEachFeatureAtPixel(e.pixel, function(feature, layer) { //if feature is in the layer you want return feature; });
I am trying to get the extent of buffer at first, then i want to check for the points which lies with in the buffer, so that some icon style can be given to them. i tried the below code for intersecting points, but it doesn't return anything.how can i achieve that, kindly guide me in proper direction. //(SELECT FEATURES BEFORE ADDING CIRCLE TO PREVENT THE CIRCLE FROM BEING SELECTED) vectorSource2.forEachFeatureIntersectingExtent(ext, function(features) { selectedFeatures.push(features); please suggest me something to do this.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • kindly tell me how to highlight the points which are lying inside that buffer – Reema Gupta Jul 6 '18 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.