From 6fbafef4ad6a4f42aa105a33ae31b685aa3477fd Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 6 Mar 2014 22:43:10 +0100 Subject: [PATCH] Add a layer with real data to the example --- examples/modify-features.html | 7 ++++++- examples/modify-features.js | 28 ++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/examples/modify-features.html b/examples/modify-features.html index 09cc4b912a..9be79fe94a 100644 --- a/examples/modify-features.html +++ b/examples/modify-features.html @@ -26,6 +26,10 @@
+
@@ -33,8 +37,9 @@

Modify features example

-

Example of using the Modify interaction. Select a feature and drag the circle that appears when the cursor gets close to the selected geometry.

+

Example of using the Modify interaction.

+

Select a feature on the Test Data layer and drag the circle that appears when the cursor gets close to the selected geometry. On the Real data (topology) layer, editing adjacent countries that are selected preserves the topology.

See the modify-features.js source to see how this is done.

modify, edit, vector
diff --git a/examples/modify-features.js b/examples/modify-features.js index 2b07c3a59a..7e50855670 100644 --- a/examples/modify-features.js +++ b/examples/modify-features.js @@ -67,7 +67,7 @@ var styleFunction = (function() { }; })(); -var vectorSource = new ol.source.GeoJSON( +var testDataSource = new ol.source.GeoJSON( /** @type {olx.source.GeoJSONOptions} */ ({ object: { 'type': 'FeatureCollection', @@ -166,9 +166,18 @@ var vectorSource = new ol.source.GeoJSON( } })); +var testDataLayer = new ol.layer.Vector({ + source: testDataSource, + style: styleFunction +}); -var vectorLayer = new ol.layer.Vector({ - source: vectorSource, +var realDataSource = new ol.source.GeoJSON({ + projection: 'EPSG:3857', + url: 'data/geojson/countries.geojson' +}); + +var realDataLayer = new ol.layer.Vector({ + source: realDataSource, style: styleFunction }); @@ -246,7 +255,7 @@ var modify = new ol.interaction.Modify({ var map = new ol.Map({ interactions: ol.interaction.defaults().extend([select, modify]), - layers: [raster, vectorLayer], + layers: [raster, testDataLayer, realDataLayer], renderer: 'canvas', target: 'map', view: new ol.View2D({ @@ -254,3 +263,14 @@ var map = new ol.Map({ zoom: 2 }) }); + +$('#layer-select').change(function() { + select.getFeatures().clear(); + var index = $(this).children().index($(this).find(':selected')); + var layers = [testDataLayer, realDataLayer]; + var i, ii; + for (i = 0, ii = layers.length; i < ii; ++i) { + layers[i].setVisible(index == i); + } +}); +$('#layer-select').trigger('change');