• OpenLayers修改要素


    <!DOCTYPE html>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <title>修改要素</title>
        <link rel="stylesheet" href="./OpenLayers-2.12/theme/default/style.css" type="text/css" />
        <script src="./OpenLayers-2.12/lib/OpenLayers.js"></script>
        <link rel="stylesheet" href="./css/style.css" type="text/css">
        <style type="text/css">
            #controls {
                width: 612px;
            }
            #controlToggle {
                padding-left: 1em;
            }
            #controlToggle li {
                list-style: none;
            }
        </style>
        <script type="text/javascript">
            var map, vectors, controls;
            function init(){
                map = new OpenLayers.Map('map');
                var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
                    "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'}); 
                OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
    
                // allow testing of specific renderers via "?renderer=Canvas", etc
                var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
                renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
    
                vectors = new OpenLayers.Layer.Vector("Vector Layer", {
                    renderers: renderer
                });
    
                map.addLayers([wms, vectors]);
                map.addControl(new OpenLayers.Control.LayerSwitcher());
                map.addControl(new OpenLayers.Control.MousePosition());
                
                if (console && console.log) {
                    function report(event) {
                        console.log(event.type, event.feature ? event.feature.id : event.components);
                    }
                    vectors.events.on({
                        "beforefeaturemodified": report,
                        "featuremodified": report,
                        "afterfeaturemodified": report,
                        "vertexmodified": report,
                        "sketchmodified": report,
                        "sketchstarted": report,
                        "sketchcomplete": report
                    });
                }
                controls = {
                    point: new OpenLayers.Control.DrawFeature(vectors,
                                OpenLayers.Handler.Point),
                    line: new OpenLayers.Control.DrawFeature(vectors,
                                OpenLayers.Handler.Path),
                    polygon: new OpenLayers.Control.DrawFeature(vectors,
                                OpenLayers.Handler.Polygon),
                    regular: new OpenLayers.Control.DrawFeature(vectors,
                                OpenLayers.Handler.RegularPolygon,
                                {handlerOptions: {sides: 5}}),
                    modify: new OpenLayers.Control.ModifyFeature(vectors)
                };
                
                for(var key in controls) {
                    map.addControl(controls[key]);
                }
                
                map.setCenter(new OpenLayers.LonLat(0, 0), 3);
                document.getElementById('noneToggle').checked = true;
            }
            
            function update() {
                // reset modification mode
                controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
                var rotate = document.getElementById("rotate").checked;
                if(rotate) {
                    controls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE;
                }
                var resize = document.getElementById("resize").checked;
                if(resize) {
                    controls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE;
                    var keepAspectRatio = document.getElementById("keepAspectRatio").checked;
                    if (keepAspectRatio) {
                        controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
                    }
                }
                var drag = document.getElementById("drag").checked;
                if(drag) {
                    controls.modify.mode |= OpenLayers.Control.ModifyFeature.DRAG;
                }
                if (rotate || drag) {
                    controls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
                }
                controls.modify.createVertices = document.getElementById("createVertices").checked;
                var sides = parseInt(document.getElementById("sides").value);
                sides = Math.max(3, isNaN(sides) ? 0 : sides);
                controls.regular.handler.sides = sides;
                var irregular =  document.getElementById("irregular").checked;
                controls.regular.handler.irregular = irregular;
            }
    
            function toggleControl(element) {
                for(key in controls) {
                    var control = controls[key];
                    if(element.value == key && element.checked) {
                        control.activate();
                    } else {
                        control.deactivate();
                    }
                }
            }
            
        </script>
      </head>
      <body onload="init()">
        <div id="map" class="smallmap"></div>
        <div id="controls">
            <ul id="controlToggle">        
                    <input type="radio" name="type" value="none" id="noneToggle"
                           onclick="toggleControl(this);" checked="checked" />
                    <label for="noneToggle">导航</label>
                    <input type="radio" name="type" value="point" id="pointToggle" onclick="toggleControl(this);" />
                    <label for="pointToggle">画点</label>           
                    <input type="radio" name="type" value="line" id="lineToggle" onclick="toggleControl(this);" />
                    <label for="lineToggle">画线</label>          
                    <input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
                    <label for="polygonToggle">画多边形</label>
                    <input type="radio" name="type" value="regular" id="regularToggle" onclick="toggleControl(this);" />
                    <label for="regularToggle">画规则多边形</label>
                    <label for="sides"> - 边</label>
                    <input id="sides" type="text" size="2" maxlength="2"
                           name="sides" value="5" onchange="update()" />
                            <input id="irregular" type="checkbox"
                                   name="irregular" onchange="update()" />
                            <label for="irregular">不规则</label>
                </li>
                <li>
                    <input type="radio" name="type" value="modify" id="modifyToggle"
                           onclick="toggleControl(this);" />
                    <label for="modifyToggle">修改功能</label>
                    <ul>
                            <input id="createVertices" type="checkbox" checked
                                   name="createVertices" onchange="update()" />
                            <label for="createVertices">允许创建顶点</label>
                            <input id="rotate" type="checkbox"
                                   name="rotate" onchange="update()" />
                            <label for="rotate">允许旋转</label>
                            <input id="resize" type="checkbox"
                                   name="resize" onchange="update()" />
                            <label for="resize">允许调整大小</label>
                            (<input id="keepAspectRatio" type="checkbox"
                                   name="keepAspectRatio" onchange="update()" checked="checked" />
                            <label for="keepAspectRatio">保持宽高比例</label>)
                            <input id="drag" type="checkbox"
                                   name="drag" onchange="update()" />
                            <label for="drag">允许拖动</label>
                    </ul>
                </li>
            </ul>
        </div>
        
      </body>
    </html>
  • 相关阅读:
    [bzoj1064][Noi2008]假面舞会
    [bzoj1503][NOI2004]郁闷的出纳员
    [bzoj1758][Wc2010]重建计划
    [bzoj1588][HNOI2002]营业额统计
    [bzoj2423][HAOI2010]最长公共子序列
    [3.26福建四校联考]
    [51nod1238]最小公倍数之和V3
    [bzoj2301] [HAOI2011]Problem b
    [hdu5608]function
    [51nod1239欧拉函数之和]
  • 原文地址:https://www.cnblogs.com/Jeely/p/11175697.html
Copyright © 2020-2023  润新知