zoukankan      html  css  js  c++  java
  • OpenLayers在多个矢量图层编辑要素

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <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>
        <script type="text/javascript">
            function init(){
                // Create map
            var map = new OpenLayers.Map("editing_vector");    
            var osm = new OpenLayers.Layer.OSM();        
            map.addLayer(osm);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            map.setCenter(new OpenLayers.LonLat(0, 0), 3);
    
            var vectorLayerA = new OpenLayers.Layer.Vector("Vector layer A");
            var vectorLayerB = new OpenLayers.Layer.Vector("Vector layer B");
            map.addLayers([vectorLayerA, vectorLayerB]);
    
            var editingToolbarControl = new OpenLayers.Control.EditingToolbar(vectorLayerA);
            map.addControl(editingToolbarControl);
                
            function layerAChanged(checked) {
                if(checked) {
                    var controls = editingToolbarControl.getControlsByClass("OpenLayers.Control.DrawFeature");
                    for(var i=0; i< controls.length; i++) {
                        controls[i].layer = vectorLayerA;
                    }
                }
            }
            function layerBChanged(checked) {
                if(checked) {
                    var controls = editingToolbarControl.getControlsByClass("OpenLayers.Control.DrawFeature");
                    for(var i=0; i< controls.length; i++) {
                        controls[i].layer = vectorLayerB;
                    }
                }
            }    
        }
        </script>
    </head>
    <body onload="init()">
    
        <form action="">
            Vector Layer A: <input id="rbA" type="radio"  onChange="layerAChanged" name="layer" value="layerA" checked/>
            Vector Layer B: <input id="rbB" type="radio"  onChange="layerBChanged" name="layer" value="layerB"/>
        </form>
        <div id="editing_vector" style=" 100%; height: 100%;"></div>
    </html>
  • 相关阅读:
    Vue路由重定向
    Vue使用rules对表单字段进行校验
    CSS Flex弹性布局实现Div
    Leetcode5 最长回文子串
    Java中char与String的相互转换
    [剑指offer] 替换空格
    Leetode最长回文串
    JavaScript 常用正则表达式集锦
    JavaScript 函数节流
    JavaScript target 与 currentTarget 区别
  • 原文地址:https://www.cnblogs.com/Jeely/p/11175688.html
Copyright © 2011-2022 走看看