Hi all,
I am using Openlayer 2.10 and Mapserver 5.6. <br><br>
I would like to project a shapefile with lon/lat values to EPSG:900913, and on top of that, creating a vector layer, where I can add new features. However, I am having trouble to get it to work. <br><br>
The map shows up, but the Line I draw is no where to be found on the map, and the mouse position control seems to be showing lon/lat values, but somewhat off by a few degrees. <br><br>
If I use EPSG:4326 throughout, everything works, but of course the map's shape is skewed due to different projections.<br><br>
It appears to be a mismatch of things somewhere, but I haven't been able to figure it out. Thanks for your help.<br><br>
Here are my codes:<br><br>
1. Client side:<br>
<textarea rows=63 cols=100>
<html>
<head>
<script language="JavaScript" src="/testapp/proj4js/proj4js-compressed.js"></script>
<script language="JavaScript" src="/testapp/lib/OpenLayers.js" ></script>
<script type="text/javascript" >
var map;
function init2()
{
map = new OpenLayers.Map( 'map', {projection: new OpenLayers.Projection("EPSG:900913")} );
var layer = new OpenLayers.Layer.MapServer( "test",
"http://localhost/cgi-bin/mapserv.exe",
{layer: 'CHN_adm1',
mode: 'map',
map: 'D:/project_data/mapfiles/china_adm.map'
},
{singleTile: true,
isBaseLayer: true
}
);
map.addLayer(layer);
                        
        //add another layer
        var vectorLayer = new OpenLayers.Layer.Vector("My Vector");
        vectorLayer.id="layer1";
        var layerProj = new OpenLayers.Projection("EPSG:4326");
        map.addLayer(vectorLayer);
map.setCenter(new OpenLayers.LonLat(90, 40), 4);
map.addControl( new OpenLayers.Control.LayerSwitcher() );
var p = new OpenLayers.Geometry.Point(90, 40);
        var p2 = new OpenLayers.Geometry.Point(100, 20);
        var line = new OpenLayers.Geometry.LineString([p,p2]);
        line.transform(layerProj, map.getProjectionObject());
        var transed = line.getVertices()[0];
        alert("transformed p=" + transed.x + "," + transed.y);
        var feature = new OpenLayers.Feature.Vector(line);
        feature.id="feat1";
                        
        vectorLayer.addFeatures([feature]);
//now adding the selection controls
var mousePosition = new OpenLayers.Control.MousePosition();
this.map.addControl(mousePosition);
}
</script>
</head>
<body onLoad="init2()">
This is my map page. <br>
<div id="map" style="width:1000px;height:600px;border: 1px solid black" ></div>
</body>
</html>
</textarea>
<br>
2.MapServer Mapfile:<br>
<textarea cols=100 rows=42>
MAP
IMAGETYPE PNG
SIZE 1200 800
EXTENT        73 15 135 54
SHAPEPATH "D:/project_data/shapefiles/CHN_adm"
IMAGECOLOR 255 255 255
UNITS meters
CONFIG "PROJ_LIB" "C:/ms4w/ms4w/proj/nad/"
PROJECTION
        "init=epsg:900913"
END
FONTSET        "D:/project_data/fontset/fonts.list"
##################################################################
LAYER
NAME CHN_adm1
DATA         CHN_adm1
STATUS ON
TYPE POLYGON
UNITS meters
LABELITEM        "NAME_1"
PROJECTION
        "init=epsg:4326"
END
CLASS
NAME "xxxx"
STYLE
COLOR 20 20 20
        SIZE        3
END
END
END
# End of LAYER DEFINITIONS -------------------------------
END # All map files must come to an end j
</textarea>
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1803224.n2.nabble.com/vector-feature-transform-problems-tp6817013p6817013.html">vector feature transform problems</a><br/>
Sent from the <a href="http://osgeo-org.1803224.n2.nabble.com/OpenLayers-Users-f1822463.html">OpenLayers Users mailing list archive</a> at Nabble.com.<br/>