supermap使用小結

来源:http://www.cnblogs.com/jiangze-blog/archive/2017/11/16/7844623.html
-Advertisement-
Play Games

<!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="保&nbsp;存" 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="保&nbsp;存" onclick=updateSelectedFeature() >'+ '</li>   ';
    infowinHtml +='   <input type="button" value="刪&nbsp;除" 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">
          &

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • # new Vue({ vue所有的數據都是放到data裡面的 # data:{ vue對象的數據 # a:1,對象 # b:[] , # } # methods:{vue對象的方法 # dosomthing: function() # { # this.a ++ # console.log(thi... ...
  • 目錄 前言 搭建項目及其它準備工作 創建資料庫 創建Koa2項目 安裝項目其它需要包 清除冗餘文件並重新規劃項目目錄 配置文件 規劃示例路由,並新建相關文件 實現數據訪問和業務邏輯相關方法 編寫mysql-helper.js 編寫數據訪問方法 規劃業務邏輯返回值 編寫業務邏輯 註冊 登錄 首頁 安全 ...
  • 目前,電腦已深入到社會生活的各個領域,由其是Web前端應用,其應用已不再僅僅局限於科學計算,而更多的是用於控制,管理及數據處理等非數值計算領域。電腦是一門研究用電腦進行信息表示和處理的科學。這裡面涉及到兩個問題:信息的表示,信息的處理。 ...
  • JS中0為false,字元串‘0’為true ...
  • 1、本地電腦沒有關聯過Git,打開git bush輸入$ ssh-keygen -t rsa -C "[email protected](自己GitHub的郵箱)",創建SSH Key。 2、在我的電腦C盤裡面找到.ssh文件夾。打開公鑰id_rsa.pub文件,複製裡面的內容。 3、進入GItHub ...
  • 基於Bootstrap表單驗證 GitHub地址:https://github.com/chentangchun/FormValidate 使用方式: 1.CSS樣式 ...
  • #node.js:概念介紹及安裝 # python伺服器、php ->aphche、java ->tomcat、 iis # 它是一個可以運行JAVASCRIPTR 的運行環境 # 它可以作為後端語言(websocket \ ) # 強大的包管理工具npm,可以使用它安裝插件 # VUE框架是基於n... ...
  • formatDuring: function(mss) { var days = parseInt(mss / (1000 * 60 * 60 * 24)); var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))... ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...