Hi everyone,
I come back with a problem I have and I tried to find an answer several weeks
ago
Thanks Hareck for help, but I still can't solve it.
here is my problem:
I have a map with a image as basic layer and default min and max coordinates
calculated in meters. I want to display this coordinates based on mouse
position.
I have a formula for transform from mouse position in lon, lat:
<?php
$ldisplayLon = round($mouseX * ($maxLon-$minLon)/$imageWidth+$minLon);
$ldisplayLat = round($mousey * ($maxLat-$minLat)/$imageHeight+$minLat);
?>
I know:
var minLon = 57360; /* left margin */
var maxLon = 90064; /* right margin */
var minLat = 65575; /* bottom margin */
var maxLat = 98279; /* top margin */
var imageWidth = 510; /* basicLayer width */
var imageHeight = 510; /* basicLayer height */
I guess it have something to do with Proj4js.defs["myown"], but I'm no expert
in it.
here is my code:
--------------------------------------------------------------------------------
<html>
<head>
<title>OpenLayers Test</title>
<script type="text/javascript" src="js/OpenLayers.js"></script>
<script type="text/javascript" src="js/proj4js-combined.js"></script>
<script defer="defer" type="text/javascript">
/* Variables */
var map;
var minLon = 57360; /* left margin */
var maxLon = 90064; /* right margin */
var minLat = 65575; /* bottom margin */
var maxLat = 98279; /* top margin */
var imageWidth = 510; /* basicLayer width */
var imageHeight = 510; /* basicLayer height */
Proj4js.defs["EPSG:31468"] = "+proj=tmerc +lat_0=0 +lon_0=12 +k=1 +x_0=4500000
+y_0=0 +ellps=bessel +datum=potsdam +units=m +no_defs";
Proj4js.defs["EPSG:4326"] = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
";
var map_ctrl = [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.MousePosition({prefix: "Lon,Lat ",
displayProjection: new OpenLayers.Projection('EPSG:31468'), numDigits: 0,
emptyString:'?,?'})
];
function init(){
/* Creating the Map Viewer */
/*In order to create the viewer, you must first create a map. The
OpenLayers.Map constructor requires one argument: This argument must either be
an HTML Element, or the ID of an HTML element. This is the element in which the
map will be placed.*/
map = new OpenLayers.Map("map", {
controls: map_ctrl,
projection: new OpenLayers.Projection('EPSG:31468'),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
maxResolution: 'auto',
units: 'meters',
numZoomLevels: 6
});
/*Map Constructor*/
/* The next step to creating a viewer is to add a layer to the Map.
OpenLayers supports many different data sources, from WMS to Yahoo! Maps to
WorldWind. */
var basicMapLayer = new OpenLayers.Layer.Image(
"Map Image",
"images/maps/MapImage.jpg",
new OpenLayers.Bounds(0, 0, 510, 510),
new OpenLayers.Size(510, 510),
{wrapDateLine: true}
);
/* Adding an Multipoint Vector Layer */
var monuments = new OpenLayers.Layer.Vector("Monuments", {
styleMap: new OpenLayers.StyleMap({
strokeColor: "blue",
strokeOpacity: 1,
strokeWidth: 1,
fontColor: "#ffffff",
fontSize: "12px",
fillColor: "blue",
fillOpacity: 0.5,
pointRadius: 6,
label : "${name}",
labelAlign: "lt",
fontColor: "white",
})
});
var point_3 = new OpenLayers.Geometry.Point(62, 146);
var point_3_Feature = new OpenLayers.Feature.Vector(point_3);
point_3_Feature.attributes = {
name: "Well",
}
var point_2 = new OpenLayers.Geometry.Point(463, 201);
var point_2_Feature = new OpenLayers.Feature.Vector(point_2);
point_2_Feature.attributes = {
name: "Cathedral",
}
// create a point feature
var point_1 = new OpenLayers.Geometry.Point(11, 45);
var point_1_Feature = new OpenLayers.Feature.Vector(point_1);
point_1_Feature.attributes = {
name: "City Hall",
}
var monumentsFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.MultiPoint([point_3, point_2, point_1]),
{externalGraphic: 'img/marker.png', graphicHeight: 1, graphicWidth: 1});
monuments.addFeatures([point_1_Feature, point_2_Feature, point_3_Feature]);
/* Layer Constructor */
/* In order to display the map, you must set a center and zoom level. In
order to zoom to fit the map into the window, you can use the zoomToMaxExtent
function, which will zoom as close as possible while still fitting the full
extents within the window. */
map.addLayers([basicMapLayer, monuments]);
map.zoomToMaxExtent();
}
</script>
</head>
<body onLoad="init()">
<div style="width:100%; height:100%; border:#000 1px solid;
background:#143750;" id="map"></div>
</body>
</html>
--------------------------------------------------------------------------------
any help is apreciated,
thanks._______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users