| 76 | | <html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 77 | | <head> |
|---|
| 78 | | <title>Select Feature Test</title> |
|---|
| 79 | | <style type="text/css"> |
|---|
| 80 | | body { |
|---|
| 81 | | font-size: 0.8em; |
|---|
| 82 | | } |
|---|
| 83 | | p { |
|---|
| 84 | | padding-top: 1em; |
|---|
| 85 | | } |
|---|
| 86 | | #map { |
|---|
| 87 | | margin: 1em; |
|---|
| 88 | | width: 512px; |
|---|
| 89 | | height: 512px; |
|---|
| 90 | | } |
|---|
| 91 | | </style> |
|---|
| 92 | | |
|---|
| 93 | | <script src="../../lib/OpenLayers.js"></script> |
|---|
| 94 | | <script type="text/javascript"> |
|---|
| 95 | | var map, selectControl1, selectControl2; |
|---|
| 96 | | |
|---|
| 97 | | function init() { |
|---|
| 98 | | map = new OpenLayers.Map('map'); |
|---|
| 99 | | var wmsLayer = new OpenLayers.Layer.WMS( |
|---|
| 100 | | "OpenLayers WMS", |
|---|
| 101 | | "http://labs.metacarta.com/wms/vmap0", |
|---|
| 102 | | {layers: 'basic'} |
|---|
| 103 | | ); |
|---|
| 104 | | var vectorLayer = new OpenLayers.Layer.Vector("Vector Layer"); |
|---|
| 105 | | var pointFeature = new OpenLayers.Feature.Vector( |
|---|
| 106 | | new OpenLayers.Geometry.Point(-50, -45) |
|---|
| 107 | | ); |
|---|
| 108 | | var polygonFeature = new OpenLayers.Feature.Vector( |
|---|
| 109 | | new OpenLayers.Geometry.Polygon([ |
|---|
| 110 | | new OpenLayers.Geometry.LinearRing([ |
|---|
| 111 | | new OpenLayers.Geometry.Point(-50,-50), |
|---|
| 112 | | new OpenLayers.Geometry.Point(-40,-50), |
|---|
| 113 | | new OpenLayers.Geometry.Point(-40,-40), |
|---|
| 114 | | new OpenLayers.Geometry.Point(-50,-50) |
|---|
| 115 | | ]) |
|---|
| 116 | | ]) |
|---|
| 117 | | ); |
|---|
| 118 | | vectorLayer.addFeatures([pointFeature, polygonFeature]); |
|---|
| 119 | | map.addLayers([wmsLayer, vectorLayer]); |
|---|
| 120 | | selectControl1 = new OpenLayers.Control.SelectFeature( |
|---|
| 121 | | vectorLayer, {geometryTypes: ['OpenLayers.Geometry.Point']} |
|---|
| 122 | | ); |
|---|
| 123 | | selectControl2 = new OpenLayers.Control.SelectFeature( |
|---|
| 124 | | vectorLayer, { |
|---|
| 125 | | geometryTypes: ['OpenLayers.Geometry.Polygon'], |
|---|
| 126 | | hover: true |
|---|
| 127 | | }); |
|---|
| 128 | | map.addControl(new OpenLayers.Control.MousePosition()); |
|---|
| 129 | | map.addControl(selectControl1); |
|---|
| 130 | | map.addControl(selectControl2); |
|---|
| 131 | | selectControl1.activate(); |
|---|
| 132 | | selectControl2.activate(); |
|---|
| 133 | | map.setCenter(new OpenLayers.LonLat(-45, -45), 4); |
|---|
| 134 | | } |
|---|
| 135 | | </script> |
|---|
| 136 | | </head> |
|---|
| 137 | | <body onload="init()"> |
|---|
| 138 | | <h1 id="title">Select Feature Test</h1> |
|---|
| 139 | | <div id="map"></div> |
|---|
| 140 | | <p> |
|---|
| 141 | | |
|---|
| 142 | | The map includes two select feature controls. The first one operates on |
|---|
| 143 | | geometries of type OpenLayers.Geometry.Point only and works on clicks. The |
|---|
| 144 | | second one operates on geometries of type OpenLayers.Geometry.Polygon and |
|---|
| 145 | | works on mouseover's. If you select the point geometry by clicking on it, |
|---|
| 146 | | it shouldn't be unselected when the mouse moves out if it. |
|---|
| 147 | | |
|---|
| 148 | | </p> |
|---|
| 149 | | </body> |
|---|
| 150 | | </html> |
|---|