Why not ask your question on the new OpenStreetMap Community Forum?

Following problem: My base layer is a OpenLayers.Layer.OSM.Osmarender layer. I draw a line with OpenLayers.Geometry.LineString in a second vector layer. With the Openlayer SelectFeature I want to select this line. But this is only possible at the startpoint and the endpoint. Is this a bug in the openlayer source?

This is my example: Click on the blue thick line selects the line only at startpoint and endpoint.

<title>OpenLayers Example</title>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript"src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>

<div style="width:100%; height:100%" id="map"></div>
<script defer="defer" type="text/javascript">

//create map
var options = {
            projection: new OpenLayers.Projection("EPSG:900913"),
    displayProjection: 'EPSG:4326',
    units: "m",
    maxResolution: 156543.0339,
    maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,
                                      20037508.34, 20037508.34),
            controls: [new OpenLayers.Control.PanZoom(), 
                       new OpenLayers.Control.Navigation(),
                       new OpenLayers.Control.MousePosition({"numDigits": 8,
                         displayProjection: new  OpenLayers.Projection("EPSG:4326"),emptyString:"outside the map"}),
map = new OpenLayers.Map('map', options);

// create OSM layer
osm_osma = new OpenLayers.Layer.OSM.Osmarender('OpenStreetMap Osmarender',
    {minZoomLevel: 0,
     maxZoomLevel: 100,
     isBaseLayer: true
var lonlat=transformLonLat("8.3191929972096", "49.015806343698", false);
map.setCenter(lonlat, 17);

//create vector-layer
// Layerstyle
var vlayer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
vlayer_style.fillOpacity = 0.6;
vlayer_style.fillColor = "green";
vlayer_style.strokeWidth = 6;
vlayer_style.strokeColor = "blue";
vlayer_style.strokeOpacity = 1;

var select_style = OpenLayers.Util.extend({}, vlayer_style);
select_style.fillOpacity = 0.6;
select_style.strokeWidth = 10;
select_style.strokeColor = "black";
select_style.fillColor = "black";
vlayer_style.strokeOpacity = 1;

var vStyleMap = new OpenLayers.StyleMap( {
   "default" :vlayer_style,
   "select" :select_style
var vlayer = new OpenLayers.Layer.Vector("vlayer", {styleMap: vStyleMap});

//create SelectFeatures
var selectControl=new OpenLayers.Control.SelectFeature(vlayer,{displayClass: "selectButton", title: 'Select Ways', 
onSelect:selected, onUnselect:unselected,toggle:false,clickout:true,multiple:false,
hover:false,toggleKey:"ctrlKey", multipleKey:"shiftKey",geometryTypes: ["OpenLayers.Geometry.LineString"],
callbacks: {
    'over': feature_hover,
    'out': feature_hover_out

//Draw Linestring
var waypoint_lon="8.3096336042805";
var waypoint_lat="49.016608500028";
var lonlat=transformLonLat(waypoint_lon, waypoint_lat, false);      
var point=new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
var arrPoint =[];

lonlat=transformLonLat(waypoint_lon, waypoint_lat, false);      
point=new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);

var line = new OpenLayers.Geometry.LineString(arrPoint);    
var lineF = new OpenLayers.Feature.Vector(line,null);


function transformLonLat(lon, lat, anzeige) {
var lonlat1 = null;
if (anzeige==true)
    lonlat1=new OpenLayers.LonLat(lon, lat).transform(
            new OpenLayers.Projection("EPSG:900913"), // Spherical Mercator Projection
            new OpenLayers.Projection("EPSG:4326") // WGS 1984,
    lonlat1=new OpenLayers.LonLat(lon, lat).transform(
            new OpenLayers.Projection("EPSG:4326"), // WGS 1984,
            new OpenLayers.Projection("EPSG:900913") // Spherical Mercator Projection
return lonlat1;

function feature_hover( feature ){ 
    feature.layer.div.style.cursor = "crosshair";

function feature_hover_out( feature ){ 
    feature.layer.div.style.cursor = "";

function selected (obj) {

function unselected (obj) {  

asked 06 Jan '12, 08:20

stafy's gravatar image

accept rate: 0%

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 06 Jan '12, 08:20

question was seen: 8,436 times

last updated: 06 Jan '12, 08:20

powered by OSQA