---
title: "关于openlayers显示wms地图的说明"
author: "Aaron2010"
date: "2012-03-28T09:11:26Z"
tags: []
categories: ["Web前端"]
slug: "openlayers-wms"
draft: false
lastmod: "2012-03-28T09:12:43Z"
id: 1465610
url: "https://aaron2010.iteye.com/blog/1465610"
---

昨天接到项目经理的活：把页面上的flex形式的地图换成用openlayers形式展现。  
因为对openlayers比较的陌生，所以立马去参照以前的项目，但是看完后发现了，以前的项目都是加载本地瓦片图层，我现在要直接加载ArcGIS中的WMS服务。现成的东西不能参考，只能到g.cn上找找资料了。  
后来发现，openlayers提供了直接加载GIS的WMS服务图层，研究完例子，写下了下面的代码。测试可以显示所需要的地图。

/\**  
\* 初始化  
\*/  
var map;  
initMap = function()  
{  
var opt = {  
projection    : new OpenLayers.Projection("EPSG:4326"),  
units         : "degrees",  
maxResolution : 0.0439453125,  
numZoomLevels : 6,  
maxExtent     : new OpenLayers.Bounds(117.8, 27, 123.4, 31.4),  
controls      : \[new OpenLayers.Control.MouseToolbar()]  
};  
             
            map = new OpenLayers.Map("mapdiv",opt);  
            var wms = new OpenLayers.Layer.WMS(  
            "zhejiang",  
             "http://rw-6d2c888d0cb1/arcgis/services/zhejiang/MapServer/WMSServer?",  
            {layers:'0,1,2,3,4,5'}  
            );  
            map.addLayer(wms);  
            map.zoomToMaxExtent(opt.maxExtent);            
};

上面显示成蓝色字体的链接就是openlayers要访问的wms服务。至于原理或者openlayers整体的说明，我现在还没有理解透彻，研究一番之后再给大家上博客。