<!DOCTYPE HTML><html xmlns="http://www.w3.org/1999/xhtml"><meta charset="UTF-8"><head><title>SuperMap iClient JavaScript:TiledDynamicRESTLayer</title> ...
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<meta charset="UTF-8">
<head>
<title>SuperMap iClient JavaScript:TiledDynamicRESTLayer</title>
<script src="./libs/SuperMap.Include.js"></script>
<script type="text/javascript">
var map, local, layer, vectorLayer,vectorLayer1,markerLayer,drawLine,
drawPolygon, lineLayer, polygonLayer,layerCorp,mousePosition,ids,centerLon,centerLat,presentScale, x1, y1,isdrag=false,
style = {
strokeColor: "#304DBE",
strokeWidth: 1,
fillColor: "#304DBE",
fillOpacity: "0.8"
},url = "http://192.168.1.19:8190/iserver/services/map-nanjing4/rest/maps/NanjingMapCorp",//靜態切片地圖
styleline = {
strokeColor: "#304DBE",
strokeWidth: 2,
pointerEvents: "visiblePainted",
fillColor: "#304DBE",
fillOpacity: 0.8
},url2 = "http://192.168.1.19:8190/iserver/services/data-nanjing4/rest/data/datasources/nanjingmap/datasets/T_CCP_LABEL_CORP2";//數據更新
function init() {
layer = new SuperMap.Layer.TiledDynamicRESTLayer("底圖", url, {transparent: true, cacheEnabled: false, redirect: true},
{scales:[1/5120000,1/2560000,1/1280000,1/640000,1/320000,1/160000,1/80000,1/40000,1/20000,1/10000,1/5000,1/2500]});
layer.events.on({"layerInitialized":addLayer});
vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
vectorLayer1 = new SuperMap.Layer.Vector("Vector Layer1");
markerLayer = new SuperMap.Layer.Markers("Markers");
//新建線矢量圖層
lineLayer = new SuperMap.Layer.Vector("lineLayer");
//對線圖層應用樣式style(前面有定義)
lineLayer.style = styleline;
//新建面矢量圖層
polygonLayer = new SuperMap.Layer.Vector("polygonLayer");
//對面圖層應用樣式style(前面有定義)
polygonLayer.style = styleline;
//創建畫線控制,圖層是lineLayer;這裡DrawFeature(圖層,類型,屬性);multi:true在將要素放入圖層之前是否現將其放入幾何圖層中
drawLine = new SuperMap.Control.DrawFeature(lineLayer, SuperMap.Handler.Path, { multi: true });
/*
註冊featureadded事件,觸發drawCompleted()方法
例如註冊"loadstart"事件的單獨監聽
events.on({ "loadstart": loadStartListener });
*/
drawLine.events.on({"featureadded": drawCompletedline});
//創建畫面控制,圖層是polygonLayer
drawPolygon = new SuperMap.Control.DrawFeature(polygonLayer, SuperMap.Handler.Polygon);
drawPolygon.events.on({"featureadded": drawCompletedline});
//多邊形查詢
drawPolygon2 = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Polygon);
drawPolygon2.events.on({"featureadded": drawCompleted});
//幾何圓查詢
drawPolygon1 = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.RegularPolygon,{handlerOptions:{sides:50}});
drawPolygon1.events.on({"featureadded": drawCompleted});
//頁面滑鼠移動控制項
mousePosition = new SuperMap.Control.MousePosition({emptyString:"0,0"});
mousePosition.numDigits=16;
map = new SuperMap.Map("map",{controls: [
new SuperMap.Control.ScaleLine(),
new SuperMap.Control.PanZoomBar({isShow: true}),
mousePosition,
new SuperMap.Control.OverviewMap(),
new SuperMap.Control.LayerSwitcher({'ascending':false}),
new SuperMap.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
}),
drawPolygon1,drawPolygon2,drawLine, drawPolygon]
});
}
function addLayer() {
map.addLayers([layer,vectorLayer,vectorLayer1, markerLayer,lineLayer, polygonLayer]);
map.setCenter(new SuperMap.LonLat(118.7263097340030100, 32.0086077019304014),10);
}
// 處理異常,彈出
function processFailed(e) {
alert(e.error.errorMsg);
}
// 清除頁面標記
function clearFeatures() {
vectorLayer.removeAllFeatures();
vectorLayer1.removeAllFeatures();
lineLayer.removeAllFeatures();
polygonLayer.removeAllFeatures();
markerLayer.clearMarkers();
}
//清除上次的滑鼠效果
function clearDrawGeometry(){
drawLine.deactivate();
drawPolygon.deactivate();
drawPolygon1.deactivate();
drawPolygon2.deactivate();
}
function closeInfoWin(){//關閉視窗--標記彈出
if(infowin){
try{
infowin.hide();//隱藏窗體對象
infowin.destroy();//消毀窗體對象
}
catch(e){
}
}
}
//關閉視窗--修改彈出
function closeInfoWin2(){
if(infowin2){
try{
infowin2.hide();//隱藏窗體對象
infowin2.destroy();//消毀窗體對象
}
catch(e){
}
}
}
//關閉視窗--添加彈出
function closeAddPoiPopup(){
if(addPoiPopup){
try{
addPoiPopup.hide();//隱藏窗體對象
addPoiPopup.destroy();//消毀窗體對象
}
catch(e){
}
}
}
//清除當前選擇的marker
function clearMarker() {
var marker = this;
marker.destroy();
}
//................................................點擊彈出.................................................................
//點擊標記彈出
var infowin = null;
function openInfoWin(){
closeInfoWin();//關閉之前打開的視窗。
var marker = this;
var lonlat = marker.lonlat;
var corp = marker.sm_capital.split(",");
var picturenum = corp[5];
var id = corp[6];
var infowinHtml='<div>企業名稱:<input type="text" id="njEnterpriseName" style="width:180px;" value="'+ corp[0] +'">'
+ '</br>企業地址:<input type="text" id="njEnterpriseAdd" style="width:180px;" value="'+ corp[1] +'">'
+ '</br>企業電話:<input type="text" id="njEnterpriseTel" style="width:180px;" value="'+ corp[2] +'">'
+ '</br><a href="#" onclick="enterpriseInfomation('+ corp[3] +','+ corp[4] +')">詳細信息</a>'
+' <a href="#" onclick="editSelectedFeature('+ id + ',' + lonlat.lon + ',' + lonlat.lat +')">修改</a>'
+' <a href="#" onclick="deleteSelectedFeatureById('+ id +')">刪除</a>'
+'</div>';
var size = new SuperMap.Size(44, 33);
var offset = new SuperMap.Pixel(0, -size.h);
var icon = new SuperMap.Icon("./theme/images/marker.png", size, offset);
var popup = new SuperMap.Popup.FramedCloud("popwin",
new SuperMap.LonLat(lonlat.lon,lonlat.lat),
null,
infowinHtml,
icon,
true);
infowin = popup;
map.addPopup(popup);
}
//..............................................SQL查詢..............................................................
//查詢--企業名稱
function queryBySQL() {
clearFeatures();
var pop = document.getElementById("pop").value;
//var area = document.getElementById("area").value;
if (pop==null || pop=="")
{
alert("請輸入");
return;
}
vectorLayer.removeAllFeatures();
var queryParam, queryBySQLParams, queryBySQLService;
queryParam = new SuperMap.REST.FilterParameter({
name: "T_CCP_LABEL_CORP2@nanjingmap",
attributeFilter: "CORP_NAME LIKE '%" + pop + "%'"
}),
queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
queryParams: [queryParam]
}),
queryBySQLService = new SuperMap.REST.QueryBySQLService(url, {
eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}});
queryBySQLService.processAsync(queryBySQLParams);
}
// 查詢--企業ID
function queryBySQL2() {
clearFeatures();
var bob = document.getElementById("bob").value;
//var area = document.getElementById("area").value;
if (bob==null || bob=="")
{
alert("請輸入");
return;
}
vectorLayer.removeAllFeatures();
var queryParam, queryBySQLParams, queryBySQLService;
queryParam = new SuperMap.REST.FilterParameter({
name: "T_CCP_LABEL_CORP2@nanjingmap",
attributeFilter: "SMID = " + bob
}),
queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
queryParams: [queryParam]
}),
queryBySQLService = new SuperMap.REST.QueryBySQLService(url, {
eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}});
queryBySQLService.processAsync(queryBySQLParams);
}
// 處理查詢結果
function processCompleted(queryEventArgs) {
var i, j, feature,
result = queryEventArgs.result;
if (result && result.recordsets) {
for (i=0; i<result.recordsets.length; i++) {
if (result.recordsets[i].features.length>0) {
for (j=0; j<result.recordsets[i].features.length; j++) {
var feature = result.recordsets[i].features[j];
var point = feature.geometry;
if(point.CLASS_NAME == SuperMap.Geometry.Point.prototype.CLASS_NAME){
var size = new SuperMap.Size(44, 33),
offset = new SuperMap.Pixel(-(size.w/2), -size.h),
icon = new SuperMap.Icon("./theme/images/marker.png", size, offset);
var marker = new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon);
marker.sm_capital = feature.attributes.CORP_NAME + ","
+ feature.attributes.ADDR + ","
+ feature.attributes.TEL + ","
+ feature.attributes.CORP_ORG + ","
+ feature.attributes.CORP_ID + ","
+ feature.attributes.PICTURE+ ","
+ feature.attributes.SMID;
marker.events.on({//註冊點擊事件的處理方法
"rightclick":clearMarker,
"dblclick":openInfoWin,
"scope": marker
});
//查詢出來的結果只有一個時支持拖動
if(result.recordsets[i].features.length == 1){
//註冊事件
marker.events.register("mousedown",marker,function(e){
isdrag = true;
//得到marker的經緯度坐標
var lon = marker.lonlat;
//將經緯度坐標轉換成屏幕坐標
var pixel = map.getPixelFromLonLat(lon);
//取整
tx = parseInt(pixel.x);
ty = parseInt(pixel.y);
//獲取marker相對滑鼠的位置
x1 = marker ? e.clientX : event.clientX;
y1 = marker ? e.clientY : event.clientY;
});
}
markerLayer.addMarker(marker);
if (j==0){
map.panTo(new SuperMap.LonLat(point.x, point.y));
map.zoomTo(10);
}
}else{
feature.style = style;
vectorLayer1.addFeatures(feature);
}
}
}else{
alert("未查詢到結果!");
}
}
}
}
//................................................畫圖查詢................................................................
//畫多邊形
function drawGeometry2() {
//先清除上次的顯示結果
clearFeatures();
drawPolygon2.activate();
}
//畫圓
function drawGeometry1() {
//先清除上次的顯示結果
clearFeatures();
drawPolygon1.activate();
}
// 圓形查詢
function drawCompleted(drawGeometryArgs) {
getScale();
//清除上次的滑鼠效果
clearDrawGeometry();
var feature = new SuperMap.Feature.Vector();
feature.geometry = drawGeometryArgs.feature.geometry,
feature.style = style;
vectorLayer.addFeatures(feature);
var queryParam, queryByGeometryParameters, queryService;
queryParam = new SuperMap.REST.FilterParameter({name: "T_CCP_LABEL_CORP2@nanjingmap"});
queryByGeometryParameters = new SuperMap.REST.QueryByGeometryParameters({
queryParams: [queryParam],
geometry: drawGeometryArgs.feature.geometry,
spatialQueryMode: SuperMap.REST.SpatialQueryMode.INTERSECT
});
queryService = new SuperMap.REST.QueryByGeometryService(url, {
eventListeners: {
"processCompleted": processCompleted,
"processFailed": processFailed
}
});
queryService.processAsync(queryByGeometryParameters);
}
//...............................................測量..........................................................................
//距離測量
function distanceMeasure(){
clearFeatures();
drawLine.activate();
}
//面積測量
function areaMeasure(){
clearFeatures();
drawPolygon.activate();
}
//測量--繪完觸發事件
function drawCompletedline(drawGeometryArgs) {
//清除上次的滑鼠效果
clearDrawGeometry();
//獲得圖層幾何對象
var geometry = drawGeometryArgs.feature.geometry,
measureParam = new SuperMap.REST.MeasureParameters(geometry), /* MeasureParameters:量算參數類。 客戶端要量算的地物間的距離或某個區域的面積*/
myMeasuerService = new SuperMap.REST.MeasureService(url); //量算服務類,該類負責將量算參數傳遞到服務端,並獲取服務端返回的量算結果
myMeasuerService.events.on({ "processCompleted": measureCompleted });
//對MeasureService類型進行判斷和賦值,當判斷出是LineString時設置MeasureMode.DISTANCE,否則是MeasureMode.AREA
if (geometry.CLASS_NAME.indexOf("LineString") > -1) {
myMeasuerService.measureMode = SuperMap.REST.MeasureMode.DISTANCE;
} else {
myMeasuerService.measureMode = SuperMap.REST.MeasureMode.AREA;
}
myMeasuerService.processAsync(measureParam); //processAsync負責將客戶端的量算參數傳遞到服務端。
}
//測量結束調用事件
function measureCompleted(measureEventArgs) {
var distance = measureEventArgs.result.distance,
area = measureEventArgs.result.area,
unit = measureEventArgs.result.unit;
if (distance != -1) {
alert("量算結果:"+distance + "米");
} else if (area != -1) {
alert("量算結果:"+ area + "平方米");
}
}
// .......................................插入數據..................................................................
//執行添加地物
function addFeatureCompleted(geometryDate) {
var temp = geometryDate.split(",");
var geometry;
geometry = new SuperMap.Geometry.Point(temp[0], temp[1]);
var name = document.getElementById("enterpriseName").value;
var add = document.getElementById("enterpriseAdd").value;
var tel = document.getElementById("enterpriseTel").value;
closeAddPoiPopup();
var editFeatureParameter,
editFeatureService,
features = {
fieldNames:["CORP_NAME","SMUSERID","TEL","ADDR"],
fieldValues:[name,1,tel,add],
geometry:geometry
};
editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
features: [features],
editType: SuperMap.REST.EditType.ADD,
returnContent:true
});
editFeatureService = new SuperMap.REST.EditFeaturesService(url2, {
eventListeners: {
"processCompleted": addFeaturesProcessCompleted,
"processFailed": processFailed
}
});
editFeatureService.processAsync(editFeatureParameter);
}
//添加成功
function addFeaturesProcessCompleted(editFeaturesEventArgs) {
ids = editFeaturesEventArgs.result.IDs,
resourceInfo = editFeaturesEventArgs.result.resourceInfo;
if(ids === null && resourceInfo === null) return;
if((ids && ids.length > 0) || (resourceInfo && resourceInfo.succeed)) {
alert("新增成功");
getCenterLonLat();
getScale();
//重新載入圖層
clearFeatures();
map.removeLayer(layer,true);
layer = new SuperMap.Layer.TiledDynamicRESTLayer("底圖", url, {transparent: true, cacheEnabled: false, redirect: true},
{scales:[1/5120000,1/2560000,1/1280000,1/640000,1/320000,1/160000,1/80000,1/40000,1/20000,1/10000,1/5000,1/2500]});
layer.events.on({"layerInitialized":reloadLayer});
}else {
alert("新增失敗");
}
}
//.......................................點擊標註.....................................................
function markPOI() {
//先清除上次的顯示結果
clearFeatures();
//清除上次的滑鼠效果
clearDrawGeometry();
map.events.on({"click":addPOIHandler});
}
function addPOIHandler(arg,geometry){
clientX = arg.clientX;
clientY = arg.clientY;
//獲取瀏覽器頁面的寬度和高度
var clientWidth = document.body.clientWidth;
var clientHeight = document.body.clientHeight;
//獲取地圖的高度和寬度
var mapWidth = map.size.w;
var mapHeight = map.size.h;
//當前point的經緯度坐標=傳入坐標-(當前頁面高度-地圖的高度)
var px = new SuperMap.Pixel(clientX-(clientWidth-mapWidth),clientY-(clientHeight-mapHeight));
var point = map.getLonLatFromPixel(px);
var x = clientX-(clientWidth-mapWidth);
var y = clientY-(clientHeight-mapHeight);
map.events.unregister("click",map,addPOIHandler);
addPOI(x,y);
}
var addPoiPopup = null;
function addPOI(x,y)
{ //獲取滑鼠位置
var my_mouse = document.getElementById("SuperMap.Control.MousePosition_57");
var num = my_mouse.innerHTML.split(',');
var infomation=num[0].trim()+","+num[1].trim();
var infowinHtml="";
infowinHtml += '<div id="addInfo" class="infowindowTitle" style="width:270px;height:200px;"><div class="mapInfo"><h4>添加企業</h4>';
infowinHtml +='<ul class="comInfo"><li>企業名稱:<input type="text" id="enterpriseName" value=""></li>';
infowinHtml +='<li>企業地址:<input type="text" id="enterpriseAdd" style="width:180px;" value=""></li>';
infowinHtml +='<li>企業電話:<input type="text" id="enterpriseTel" style="width:180px;" value=""></li>';
infowinHtml +='<li><input type="button" value="保 存" onclick=addFeatureCompleted("'+infomation+'") ></li>';
infowinHtml +='</ul>';
infowinHtml += '</div> </div>';
//*********************
//點擊後pop彈窗
addPoiPopup = new SuperMap.Popup.FramedCloud("popwin",new SuperMap.LonLat(num[0],num[1]),null,infowinHtml,null,true);
map.addPopup(addPoiPopup,true);
var size = new SuperMap.Size(44,33);
var offset = new SuperMap.Pixel(-(size.w/2), -size.h);
var icon = new SuperMap.Icon('./theme/images/marker.png', size, offset);
var marker = new SuperMap.Marker(new SuperMap.LonLat(num[0],num[1]),icon);
marker.events.on({//註冊點擊事件的處理方法
"rightclick":clearMarker,
"dblclick":openInfoWin2,
"scope": marker
});
//註冊事件
marker.events.register("mousedown",marker,function(e){
isdrag = true;
//得到marker的經緯度坐標
var lon = marker.lonlat;
//將經緯度坐標轉換成屏幕坐標
var pixel = map.getPixelFromLonLat(lon);
//取整
tx = parseInt(pixel.x);
ty = parseInt(pixel.y);
//獲取marker相對滑鼠的位置
x1 = marker ? e.clientX : event.clientX;
y1 = marker ? e.clientY : event.clientY;
});
markerLayer.addMarker(marker);
info = "";
}
//點擊標記彈出
var infowin2 = null;
function openInfoWin2(){
closeInfoWin2();//關閉之前打開的視窗。
var marker = this;
if(confirm("確定清除該標記?"))
{
//如果是true
alert("你按了確定,那就是返回true");
marker.destroy();
}
else
{
//否則
alert("你按了取消,那就是返回false");
}
var lonlat = marker.lonlat;
//queryIdBySQL(lonlat.lon,lonlat.lat);
var infowinHtml="";
infowinHtml += '<div id="updateInfo" class="infowindowTitle" style="width:270px;height:200px;"><div class="mapInfo"><h4>修改企業</h4>';
infowinHtml +='<ul class="comInfo"><li>企業名稱:<input type="text" id="updateEnterpriseName" value="'+'"></li> ';
infowinHtml +='<li>企業地址:<input type="text" id="updateEnterpriseAdd" style="width:180px;" value="'+'"></li>';
infowinHtml +='<li>企業電話:<input type="text" id="updateEnterpriseTel" style="width:180px;" value="'+'"></li>';
infowinHtml +='<li><input type="button" value="保 存" onclick=updateSelectedFeature() >'+ '</li> ';
infowinHtml +=' <input type="button" value="刪 除" onclick=deleteSelectedFeature() >'+ '</li></ul>';
infowinHtml += '</div> </div>';
var size = new SuperMap.Size(44, 33);
var offset = new SuperMap.Pixel(-(size.w/2), -size.h);
//var offset = new SuperMap.Pixel(0, -size.h);
var icon = new SuperMap.Icon("./theme/images/marker.png", size, offset);
var popup = new SuperMap.Popup.FramedCloud("popwin",
new SuperMap.LonLat(lonlat.lon,lonlat.lat),
null,
infowinHtml,
icon,
true);
infowin = popup;
map.addPopup(popup);
}
//..........................................移動標記....................................................................
//marker移動方法
function movemouse(e)
{
//滑鼠的實時位置
if (isdrag)
{
var x2,y2,marker,tempSm_capital;
if(markerLayer.markers.length==1){
marker = markerLayer.markers[0];
tempSm_capital = marker.sm_capital;
}
//獲取滑鼠的實時位置
x2 = marker ? tx + e.clientX - x1 : tx + event.clientX - x1;
y2 = marker ? ty + e.clientY - y1 : ty + event.clientY - y1;
//轉為屏幕坐標
var pix = new SuperMap.Pixel(x2,y2);
//屏幕坐標轉為經緯度坐標
var lon1 = map.getLonLatFromPixel(pix);
//將此前的marker坐標清理
markerLayer.clearMarkers();
//var offset = new SuperMap.Pixel(x2,y2);
var size = new SuperMap.Size(44, 33);
var offset = new SuperMap.Pixel(-(size.w/2), -size.h);
var icon = new SuperMap.Icon('./theme/images/marker.png',size, offset);
marker = new SuperMap.Marker(lon1,icon);
marker.sm_capital = tempSm_capital;
marker.events.on({//註冊點擊事件的處理方法
"rightclick":clearMarker,
"dblclick":openInfoWin,
"scope": marker
});
//註冊事件
marker.events.register("mousedown",marker,function(e){
isdrag = true;
var lon = marker.lonlat;
var pixel = map.getPixelFromLonLat(lon);
tx = parseInt(pixel.x);
ty = parseInt(pixel.y);
x1 = marker ? e.clientX : event.clientX;
y1 = marker ? e.clientY : event.clientY;
});
markerLayer.addMarker(marker);
}
}
document.onmousemove=movemouse;
document.onmouseup=new Function("isdrag=false");
//..........................................修改....................................................................
function editSelectedFeature(id,tmplon,tmplat) {
if(id == null || id == ""
|| tmplon == null || tmplon == ""
|| tmplat == null || tmplat == ""){
return;
}
var editFeatureParameter,
editFeatureService,
features,
njEnterpriseName=document.getElementById("njEnterpriseName").value,
njEnterpriseAdd=document.getElementById("njEnterpriseAdd").value,
njEnterpriseTel=document.getElementById("njEnterpriseTel").value;
if(njEnterpriseName == null || njEnterpriseName == ""
|| njEnterpriseAdd == null || njEnterpriseAdd == ""
|| njEnterpriseTel == null || njEnterpriseTel == ""){
alert("請輸入!");
return;
}
closeInfoWin();
var geometry = new SuperMap.Geometry.Point(tmplon, tmplat);
features = {
fieldNames:["CORP_NAME","SMUSERID","TEL","ADDR"],
fieldValues:[njEnterpriseName,1,njEnterpriseTel,njEnterpriseAdd],
geometry:geometry
};
features.geometry.id = id;
editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
features: [features],
editType: SuperMap.REST.EditType.UPDATE
});
editFeatureService = new SuperMap.REST.EditFeaturesService(url2, {
eventListeners: {
"processCompleted": updateFeaturesProcessCompleted,
"processFailed": processFailed
}
});
editFeatureService.processAsync(editFeatureParameter);
}
//更新地物完成
function updateFeaturesProcessCompleted(editFeaturesEventArgs) {
if(editFeaturesEventArgs.result.resourceInfo.succeed) {
alert("更新成功");
//重新載入圖層
getCenterLonLat();
getScale();
//重新載入圖層
clearFeatures();
map.removeLayer(layer,true);
layer = new SuperMap.Layer.TiledDynamicRESTLayer("底圖", url, {transparent: true, cacheEnabled: false, redirect: true},
{scales:[1/5120000,1/2560000,1/1280000,1/640000,1/320000,1/160000,1/80000,1/40000,1/20000,1/10000,1/5000,1/2500]});
layer.events.on({"layerInitialized":reloadLayer});
}
else {
alert("更新失敗");
}
}
//..........................................刪除....................................................................
//刪除選中地物
function deleteSelectedFeature() {
closeInfoWin2();
if(ids === null || typeof ids === "undefined") return;
var editFeatureParameter,
editFeatureService;
editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
IDs: ids,
editType: SuperMap.REST.EditType.DELETE
});
editFeatureService = new SuperMap.REST.EditFeaturesService(url2, {
eventListeners: {
"processCompleted": deleteFeaturesProcessCompleted,
"processFailed": processFailed
}
});
editFeatureService.processAsync(editFeatureParameter);
}
//刪除選中地物
function deleteSelectedFeatureById(id) {
closeInfoWin();
if(id === null || typeof id === "undefined") return;
var tempIds = [id];
var editFeatureParameter,
editFeatureService;
editFeatureParameter = new SuperMap.REST.EditFeaturesParameters({
IDs: tempIds,
editType: SuperMap.REST.EditType.DELETE
});
editFeatureService = new SuperMap.REST.EditFeaturesService(url2, {
eventListeners: {
"processCompleted": deleteFeaturesProcessCompleted,
"processFailed": processFailed
}
});
editFeatureService.processAsync(editFeatureParameter);
}
//刪除地物完成
function deleteFeaturesProcessCompleted(editFeaturesEventArgs) {
if(editFeaturesEventArgs.result.resourceInfo.succeed) {
alert("刪除成功");
getCenterLonLat();
getScale();
//重新載入圖層
clearFeatures();
map.removeLayer(layer,true);
layer = new SuperMap.Layer.TiledDynamicRESTLayer("底圖", url, {transparent: true, cacheEnabled: false, redirect: true},
{scales:[1/5120000,1/2560000,1/1280000,1/640000,1/320000,1/160000,1/80000,1/40000,1/20000,1/10000,1/5000,1/2500]});
layer.events.on({"layerInitialized":reloadLayer});
}
else {
alert("刪除失敗");
}
}
//....................................................................................................................
function reloadLayer(){
map.addLayers([layer,vectorLayer,vectorLayer1, markerLayer,lineLayer, polygonLayer]);
map.setCenter(new SuperMap.LonLat(centerLon, centerLat),presentScale);
}
//......................................................................................................................
//..........................................顯示當前中心點....................................................................
function getCenterLonLat(){
var piont = map.getCenter();
centerLon = piont.lon;
centerLat = piont.lat;
document.getElementById("centerPoint").value =centerLon + ":" + centerLat;
}
//..........................................顯示當前比例尺....................................................................
function getScale(){
var scale = map.getScale().toFixed(7);
if(scale==(1/160000).toFixed(7)){
presentScale = 5;
}
else if(scale==(1/80000).toFixed(7)){
presentScale = 6;
}
else if(scale==(1/40000).toFixed(7)){
presentScale = 7;
}
else if(scale==(1/20000).toFixed(7)){
presentScale = 8;
}
else if(scale==(1/10000).toFixed(7)){
presentScale = 9;
}
else if(scale==(1/5000).toFixed(7)){
presentScale = 10;
}
else if(scale==(1/2500).toFixed(7)){
presentScale = 11;
}
else if(scale==(1/320000).toFixed(7)){
presentScale = 4;
}
else if(scale==(1/640000).toFixed(7)){
presentScale = 3;
}
else if(scale==(1/1280000).toFixed(7)){
presentScale = 2;
}
else if(scale==(1/2560000).toFixed(7)){
presentScale = 1;
}
else if(scale==(1/5120000).toFixed(7)){
presentScale = 0;
}
else{
presentScale = 8;
}
document.getElementById("scale").value =presentScale;
}
function checkLeave()
{
getCenterLonLat();
getScale();
}
</script>
</head>
<body onload="init()" onbeforeunload="checkLeave()">
<div id="top" style="width:100%;height:100px;">江蘇地圖</div>
<div id="map" style="position:absolute;left:1px;right:0px;width:90%;height:80%;" >
</div>
<div id="query" style="position:absolute;right:0px;right:0px;width:10%;height:80%;">
<table>
<tr align="left">
<td>條件查詢</td>
</tr>
<tr align="left">
<td>**********************************************</td>
</tr>
<tr align="left">
<td>企業名稱:<input id="pop" type="text" value=""/></td>
</tr>
<tr align="left">
<td><a class="btn green mini" onclick="queryBySQL()" data-func="addC" href="#">查詢</a>
<a class="btn green mini" onclick="clearFeatures()" data-func="addC" href="#">清除</a>
</td>
</tr>
<tr align="left">
<td>**********************************************</td>
</tr>
<tr align="left">
<td>企業ID:<input id="bob" type="text" value=""/></td>
</tr>
<tr align="left">
<td><a class="btn green mini" onclick="queryBySQL2()" data-func="addC" href="#">查詢</a></td>
</tr>
<tr align="left">
<td>**********************************************</td>
</tr>
<tr align="left">
<td><a class="btn green mini" onclick="drawGeometry1()" data-func="addC" href="#">查詢(圓)</a></td>
</tr>
<tr align="left">
&