习惯了GoogleMap API的开发,大家都希望能够利用这种开发方式,来做一些html静态页面开发,或者是PHP页面开发,我们不用再去关心究竟服务器如何管理与开发。
这里我们利用SuperMap iServer 2.0的JS SDK来配置一个允许在线开发的环境,过程较为简单:
1、我们利用SuperMap iServer自带的Demo Handler来响应请求,那么这里我们简单修改一下demo/scripts/SuperMap.Include.js文件,加入Demo所在服务器的IP地址,如下:
SuperMap.Include.js
1 var ipAddr = "http://127.0.0.1:7080/demo/";
2 function _IncludeScript(inc){
3 var script='<'+'script type="text/javascript" src="' + ipAddr +'scripts/'+inc+'"'+'><'+'/script>';
4 document.writeln(script);
5 }
6
7 function _IncludeStyle(inc){
8 var style='<'+'link type="text/css" rel="stylesheet" href="'+ ipAddr + 'styles/'+inc+'"'+' />';
9 document.writeln(style);
10
2 function _IncludeScript(inc){
3 var script='<'+'script type="text/javascript" src="' + ipAddr +'scripts/'+inc+'"'+'><'+'/script>';
4 document.writeln(script);
5 }
6
7 function _IncludeStyle(inc){
8 var style='<'+'link type="text/css" rel="stylesheet" href="'+ ipAddr + 'styles/'+inc+'"'+' />';
9 document.writeln(style);
10
这样就可以使网页能正确引用到所有的脚本库文件;
2、除了静态页面,其他应用调用时会出现跨域问题,那么在这里,为Tomcat中的ROOT文件夹下加入跨域配置文件,如下:
clientaccesspolicy.xml
3、启动GIS服务器和Web服务器,自己写个静态页面测试一下吧 1 <?xml version="1.0" encoding="utf-8"?>
2 <access-policy>
3 <cross-domain-access>
4 <policy>
5 <allow-from>
6 <domain uri="*"/>
7 </allow-from>
8 <grant-to>
9 <resource path="/" include-subpaths="true"/>
10 </grant-to>
11 </policy>
12 </cross-domain-access>
13 </access-policy>
14
15
2 <access-policy>
3 <cross-domain-access>
4 <policy>
5 <allow-from>
6 <domain uri="*"/>
7 </allow-from>
8 <grant-to>
9 <resource path="/" include-subpaths="true"/>
10 </grant-to>
11 </policy>
12 </cross-domain-access>
13 </access-policy>
14
15
test.html
1 <html>
2 <head>
3 <link href="http://127.0.0.1:7080/demo/styles/main.css" rel="stylesheet"></link>
4 <link href="http://127.0.0.1:7080/demo/styles/page.css" rel="stylesheet"></link>
5 <script language='javascript' src='http://127.0.0.1:7080/demo/scripts/SuperMap.Include2.js'></script>
6 <script type="text/javascript" src="http://127.0.0.1:7080/demo/scripts/page_resource_zh.js"></script>
7 <script type="text/javascript" src="http://127.0.0.1:7080/demo/scripts/page.js"></script>
8 </head>
9 <!--这里偷懒,利用了SuperMap自带的page.js方法,当然里面也做了部分修改,就是写明Handler地址和GIS服务地址即可-->
10 <body onload="onPageLoad()">
11 <div id="mapcontrol1Div" style="position: absolute; top:109px; left: 216px;799;height:629"></div>
12 </body>
13 </html
2 <head>
3 <link href="http://127.0.0.1:7080/demo/styles/main.css" rel="stylesheet"></link>
4 <link href="http://127.0.0.1:7080/demo/styles/page.css" rel="stylesheet"></link>
5 <script language='javascript' src='http://127.0.0.1:7080/demo/scripts/SuperMap.Include2.js'></script>
6 <script type="text/javascript" src="http://127.0.0.1:7080/demo/scripts/page_resource_zh.js"></script>
7 <script type="text/javascript" src="http://127.0.0.1:7080/demo/scripts/page.js"></script>
8 </head>
9 <!--这里偷懒,利用了SuperMap自带的page.js方法,当然里面也做了部分修改,就是写明Handler地址和GIS服务地址即可-->
10 <body onload="onPageLoad()">
11 <div id="mapcontrol1Div" style="position: absolute; top:109px; left: 216px;799;height:629"></div>
12 </body>
13 </html
Over