1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <title>Split Feature Example</title>
5 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
6 <link rel="stylesheet" href="style.css" type="text/css" />
7 <script src="../lib/OpenLayers.js"></script>
8 <script type="text/javascript">
9 var map, vectors, split;
10 OpenLayers.Util.onImageLoadErrorColor = "transparent";
12 map = new OpenLayers.Map('map');
14 // give the features some style
15 var styles = new OpenLayers.StyleMap({
20 strokeColor: "#0099cc",
25 // add rules from the above lookup table
26 styles.addUniqueValueRules("default", "RP_TYPE", {
27 10: {strokeColor: "#000000", strokeWidth: 2},
28 12: {strokeColor: "#222222", strokeWidth: 2},
29 14: {strokeColor: "#444444", strokeWidth: 2},
30 16: {strokeColor: "#666666", strokeWidth: 2},
31 18: {strokeColor: "#888888", strokeWidth: 2},
32 19: {strokeColor: "#666666", strokeWidth: 1}
35 vectors = new OpenLayers.Layer.Vector("Lines", {
37 strategies: [new OpenLayers.Strategy.Fixed()],
38 protocol: new OpenLayers.Protocol.HTTP({
39 url: "data/roads.json",
40 format: new OpenLayers.Format.GeoJSON()
43 maxExtent: new OpenLayers.Bounds(
44 1549471.9221, 6403610.94, 1550001.32545, 6404015.8
51 map.addLayer(vectors);
53 map.addControl(new OpenLayers.Control.MousePosition());
55 var split = new OpenLayers.Control.Split({
58 aftersplit: function(event) {
59 flashFeatures(event.features);
63 map.addControl(split);
65 map.zoomToMaxExtent();
69 function flashFeatures(features, index) {
73 var current = features[index];
74 if(current && current.layer === vectors) {
75 vectors.drawFeature(features[index], "select");
77 var prev = features[index-1];
78 if(prev && prev.layer === vectors) {
79 vectors.drawFeature(prev, "default");
82 if(index <= features.length) {
83 window.setTimeout(function() {flashFeatures(features, index)}, 100);
89 <body onload="init()">
90 <h1 id="title">OpenLayers Split Feature Example</h1>
92 Demonstrates splitting of line features.
94 <div id="map" class="smallmap"></div>
96 The split control can be configured to listen for edits on any vector layer
97 or it can allow for creation of temporary sketch features. Modified or
98 newly drawn features will be used to split existing features on any target
99 layer. This example shows the split control configured to use temporary
100 sketches for the split.