My First Openlayers and Tile

知道openlayers有很久了但一直都没有用过,因之前一直都用geobeanV1!

现在是多元的时代:iphone、android、macos、linux、winX 正因为这样,想让地图业务支持更多平台, 故开始学习并用之。

因为让openlayers能跑起来之前geobean的tile地图.要把geobean的Datum:WGS84改为相对应openlayers的EPSG:102113。

openlayers代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<html>
<head>
<title>TileCache, from MetaCarta Labs</title>
<meta content='text/html; charset=utf-8' http-equiv='content-type'>
<meta content='initial-scale=1.0; maximum-scale=1.0; user-scalable=0;' name='viewport'>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript">
<!--
var map, layer;

function init(){
    map = new OpenLayers.Map( $('map'), {maxResolution:'auto'});
  // layer = new OpenLayers.Layer.WMS( "VMap0", 
  //          "http://labs.metacarta.com/wms-c/Basic.py?", {layers: 'basic', format: 'image/png' } );
  // layer = new OpenLayers.Layer.WMS( "cgg", 
  //         "/wms?", {layers: 'basic', format: 'image/png' } );

    layer = new OpenLayers.Layer.WMS( "cgg",
         "/wms?", {layers: 'basic', format: 'image/png' },{
            //projection : new OpenLayers.Projection('EPSG:900913'),
            projection : new OpenLayers.Projection('EPSG:102113'),
            singleTile : false,
            buffer : 0,
            ratio : 1
        } );


    map.addLayer(layer);
    // c = new OpenLayers.Control.LayerSwitcher();
    // map.addControl(c);
    map.addControl(new OpenLayers.Control.Permalink());
    if (!map.getCenter()) map.zoomToMaxExtent();
}
// -->
</script>
</head>
<body onload="init()">
<div id="map" style="width:512px;height:512px;margin:10px;border: 1px solid #888;"></div>
<!-- http://tilecache.osgeo.org/wms-c/Basic.py?LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326&BBOX=-180,-90,0,90&WIDTH=256&HEIGHT=256
http://labs.metacarta.com/wms-c/Basic.py?LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326&BBOX=-90,0,0,90&WIDTH=256&HEIGHT=256
http://labs.metacarta.com/wms-c/Basic.py?LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&SRS=EPSG%3A4326&BBOX=-45,0,0,45&WIDTH=256&HEIGHT=256
 -->

</body>
</html>
原文地址:http://dlj.bz/jyd92z

Comments