Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. // Feature Selection
  2. select = new OpenLayers.Layer.Vector("Selection", {
  3. styleMap: new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
  4. });
  5. map.addLayers([select]);
  6.  
  7. selectControl = new OpenLayers.Control.GetFeature({
  8. protocol: OpenLayers.Protocol.WFS.fromWMSLayer(PointsLayer),
  9. box: true,
  10. hover: false,
  11. multipleKey: "shiftKey",
  12. toggleKey: "ctrlKey"
  13. });
  14. selectControl.events.register("featureselected", this, function (e) {
  15. // How do I popup a window with feature info, is it here??
  16. select.addFeatures([e.feature]);
  17. });
  18. selectControl.events.register("featureunselected", this, function (e) {
  19. select.removeFeatures([e.feature]);
  20. });
  21. map.addControl(selectControl);
  22. selectControl.activate();
  23.  
  24. // Register click event to get features
  25. map.events.register('click', map, function (e) {
  26.  
  27. var url = baseLayer.getFullRequestString({
  28. REQUEST: "GetFeatureInfo",
  29. EXCEPTIONS: "application/vnd.ogc.se_xml",
  30. BBOX: map.getExtent().toBBOX(),
  31. X: e.xy.x,
  32. Y: e.xy.y,
  33. INFO_FORMAT: 'text/html',
  34. LAYERS: map.layers[0].params.LAYERS + "," +
  35. map.layers[1].params.LAYERS,
  36. QUERY_LAYERS: map.layers[0].params.LAYERS + "," +
  37. map.layers[1].params.LAYERS,
  38. WIDTH: map.size.w,
  39. HEIGHT: map.size.h
  40. });
  41.  
  42. function handler(request) {
  43.  
  44. answer = request.responseText.length;
  45.  
  46. if (answer <= 1)
  47. {
  48. var strTemp = "<HTML><BODY>ERROR RETRIEVING FEATURE</BODY></HTML>";
  49. open_new_window(strTemp);
  50. }
  51. else
  52. {
  53. //open_new_window(url);
  54. open_new_window(request.responseText);
  55. }
  56.  
  57. }
  58.  
  59. var request = OpenLayers.Request.GET({
  60. url: url,
  61. callback: handler
  62. });
  63.  
  64. });
  65.  
  66. function open_new_window(windowText)
  67. {
  68. new_window = open("", "Feature Window", "width=300,height=170,left=10,top=10");
  69.  
  70. // open new document
  71. new_window.document.open();
  72.  
  73. // Text of the new document
  74. new_window.document.write(windowText);
  75.  
  76. // close the document
  77. new_window.document.close();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement