[OpenLayers-Users] Add layers drawing points
Lucas Eskopinski
eskopinski at gmail.com
Fri Apr 17 21:44:39 EDT 2009
Hi,
I have a problem adding WMS Layer (from GeoServer) and creating points with OpenLayers. When I change the zoom level, the point that was on a road (layer WMS from GeoServer) appears elsewhere and not on the road.
I think it is a distortion problem in the map window, it presents different projection behaviors for diffent zoom levels.
http://img19.imageshack.us/img19/3610/figura01.png
http://img19.imageshack.us/img19/4426/figura02.png
My configuration:
- PostGIS: my table : SRID: 4326
...CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 4326)
- GeoServer: my layer: SRS: 4326
...SRS handling: Force declared SRS (native will be ignored)
- OpenLayers: srs: 'EPSG:4326'
layer = new OpenLayers.Layer.WMS(
"topp:ruas_rs - Tiled", "http://localhost:8080/geoserver/wms",
{
layers: 'topp:ruas_rs', styles: '', height: '550', width: '350', srs: 'EPSG:4326', format: format, tiled: 'true', tilesOrigin : "-51.31199340820311,-30.310599613189684"
},
{buffer: 0}
);
----------------
var SinglePoint = OpenLayers.Class.create();
SinglePoint.prototype = OpenLayers.Class.inherit(OpenLayers.Handler.Point, {
createFeature: function(evt) {
this.control.layer.removeFeatures(this.control.layer.features);
OpenLayers.Handler.Point.prototype.createFeature.apply(this, arguments);
}
});
var start_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
start_style.externalGraphic = "images/start.png";
start_style.graphicWidth = 18;
start_style.graphicHeight = 26;
start_style.graphicYOffset = -26;
start_style.graphicOpacity = 1;
var stop_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
stop_style.externalGraphic = "images/stop.png";
stop_style.graphicWidth = 18;
stop_style.graphicHeight = 26;
stop_style.graphicYOffset = -26;
stop_style.graphicOpacity = 1;
var result_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
result_style.strokeWidth = 3;
result_style.strokeColor = "#ff0000";
result_style.fillOpacity = 0;
start = new OpenLayers.Layer.Vector("Start point", {style: start_style});
stop = new OpenLayers.Layer.Vector("End point", {style: stop_style});
result = new OpenLayers.Layer.Vector("Routing results", {style: result_style});
map.addLayers([layer, start, stop, result]);
// controls
controls = {
start: new OpenLayers.Control.DrawFeature(start, SinglePoint),
stop: new OpenLayers.Control.DrawFeature(stop, SinglePoint)
}
for (var key in controls) {
map.addControl(controls[key]);
}
function compute() {
var startPoint = start.features[0];
var stopPoint = stop.features[0];
if (startPoint && stopPoint) {
var result = {
startpoint: startPoint.geometry.x + ' ' + startPoint.geometry.y,
finalpoint: stopPoint.geometry.x + ' ' + stopPoint.geometry.y,
method: OpenLayers.Util.getElement('method').value, region: "teste", srid: "4326"
};
var request = OpenLayers.Request.GET({
url: "http://localhost:8080/application-test/RoutingServlet",
params: result, headers: {"Content-Type": "text/plain"},
callback: displayRoute
});
}
}
function displayRoute(response) {
if (response && response.responseXML) {
// erase the previous results
result.removeFeatures(result.features);
var edges = response.responseXML.getElementsByTagName('edge');
var features = [];
for (var i = 0; i < edges.length; i++) {
var wkt = (edges[i].getElementsByTagName('wkt')[0].text);
var geometry = parser.read(wkt);
result.addFeatures(geometry);
}
}
}
Sorry, but my English is not so good.
Thanks.
Lucas Eskopinski.
--
View this message in context: http://n2.nabble.com/Add-layers-drawing-points-tp2653881p2653881.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
More information about the Users
mailing list