[OpenLayers-Users] SelectFeature and navigation
ontwerp at limotec.be
ontwerp at limotec.be
Mon Aug 20 01:04:47 PDT 2012
Hi
I found the sollution. It wasn’t the navigation control that did it but the dragfeature control. I added this to the dragfeature:
dragFeature.handlers['drag'].stopDown = false;
dragFeature.handlers['drag'].stopUp = false;
dragFeature.handlers['drag'].stopClick = false;
dragFeature.handlers['feature'].stopDown = false;
dragFeature.handlers['feature'].stopUp = false;
dragFeature.handlers['feature'].stopClick = false;
Now everything works.
greetings
Ruben
From: Alexandre Dubé
Sent: Friday, August 17, 2012 7:57 PM
To: ontwerp at limotec.be
Cc: openlayers-users at lists.osgeo.org
Subject: Re: [OpenLayers-Users] SelectFeature and navigation
Hi,
At this point, I don't know what could be the cause of this behavior. Could you provide a small live demo showing the issue ?
Alexandre
On 12-08-17 09:14 AM, ontwerp at limotec.be wrote:
Hi
The code is below.
The problem is that after a pan or zoom the onSelect function of the SelectFeature is no longer called. DragFeature still works.
<script src="@Url.Content("~/Scripts/OpenLayers/OpenLayers.debug.js")"></script>
<script>
var map;
var groundPLan;
var icon;
var markers;
var clickedMarker = null;
function init() {
groundPLan = new OpenLayers.Layer.XYZ(
'GroundPlan',
'@Url.Content("~/Maps/" + ViewBag.Id)/${z}/${x}/${y}.jpg',
{
attribution: "© Limotec",
sphericalMercator: false,
wrapDateLine: false,
transitionEffect: 'resize',
buffer: 1,
numZoomLevels: 5
}
);
map = new OpenLayers.Map('map_canvas', { controls: [] });
map.addLayer(groundPLan);
map.addControl(new OpenLayers.Control.Attribution());
map.addControl(new OpenLayers.Control.Navigation({ dragPanOptions: { enableKinetic: true} }));
map.setCenter(new OpenLayers.LonLat(0, 0), 2);
map.div.oncontextmenu = function noContextMenu(e) {
var lonlat = map.getLonLatFromPixel(new OpenLayers.Pixel(e.layerX, e.layerY));
$("#lat").val(lonlat.lon);
$("#lng").val(lonlat.lat);
$("#detList").dialog("open");
return false;
};
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
markers = new OpenLayers.Layer.Vector("Markers",
{
renderOptions: { yOrdering: true },
renderers: renderer
}
);
map.addLayer(markers);
var dragFeature = new OpenLayers.Control.DragFeature(markers);
dragFeature.onComplete = function (feature, pixel) {
var id = feature.geometry.id;
id = id.replace('Det_', '');
var lonLat = map.getLonLatFromPixel(pixel);
$.post(
'@Url.Action( "MoveDet", "Api" )',
{ id: id, lat: lonLat.lon, lng: lonLat.lat }
);
}
map.addControl(dragFeature);
dragFeature.activate();
var clickFeature = new OpenLayers.Control.SelectFeature(markers);
clickFeature.handlers.feature.stopDown = false;
clickFeature.onSelect = function (feature) {
var id = feature.geometry.id;
id = id.replace('Det_', '');
$.post('@Url.Action("GetDetectorById", "Api")',
{ detId: id },
function (data) {
if (data.Id != null) {
clickedMarker = feature;
$("#lat").val(data.X);
$("#lng").val(data.Y);
OpenDetector(data.Id, data.InTest, data.InService, data.Name);
} else {
alert(data);
}
}
);
}
map.addControl(clickFeature);
clickFeature.activate();
}
function SetMarkerIcon(det, type) {
var lat = parseFloat(det.Lat);
var lng = parseFloat(det.Lng);
var id = "";
if (type != "optical") {
id = "fire_" + det.Id;
} else {
id = "detIcon_" + det.Id;
}
var marker = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lat, lng));
marker.style = {
externalGraphic: '@Url.Content("~/Images/Icons/Optical.png")',
graphicOpacity: 1.0,
graphicWidth: 30,
graphicHeight: 30,
graphicYOffset: -15,
graphicXOffset: -15,
cursor: 'pointer',
backgroundGraphic: '@Url.Content("~/Images/Icons/Optical_Shadow.png")',
backgroundXOffset: -12,
backgroundYOffset: -12,
graphicZIndex: 11,
backgroundGraphicZIndex: 10
}
marker.url = '@Url.Action("MoveDet", "Api")';
marker.geometry.id = "Det_" + det.Id;
markers.addFeatures(marker);
}
$(document).ready(function () {
init();
});
</script>
greetings
Ruben
From: Alexandre Dubé
Sent: Friday, August 17, 2012 2:53 PM
To: openlayers-users at lists.osgeo.org
Subject: Re: [OpenLayers-Users] SelectFeature and navigation
Hi Ruben,
Would you please provide more details, like a live short demo showing the issue or paste some code ? The SelectFeature control doesn't deactivates itself after a pan or zoom, so we need to find out why it does in your case.
To help you find out what the issue is, you can minimize your code step by step. This nice article mentions a lot about this, I'd suggest you read it first :
http://docs.openlayers.org/help/minimize.html
Best regards,
Alexandre
On 12-08-17 04:27 AM, ontwerp at limotec.be wrote:
Hello
When the map is loaded the selectfeature works, but after a pan or zoom it doesn’t. It seems that the selectfeature is deactivated after pan or zoom.
Is there a way to reactivate the selectfeature after a pan or zoom?
greetings
Ruben
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
Alexandre Dubé
Mapgears
www.mapgears.com
------------------------------------------------------------------------------
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users
--
Alexandre Dubé
Mapgears
www.mapgears.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120820/4ba32605/attachment-0001.html>
More information about the Users
mailing list