Get rid of ol.FeatureOverlay

This also introduces a wrapX option to the Draw, Modify and Select
interaction.
This commit is contained in:
Andreas Hocevar
2015-06-09 13:25:51 +02:00
parent 54da473991
commit 53d5d8c1d9
28 changed files with 177 additions and 676 deletions

View File

@@ -1,11 +1,13 @@
goog.require('ol.FeatureOverlay');
goog.require('ol.Collection');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.events.condition');
goog.require('ol.interaction.Draw');
goog.require('ol.interaction.Modify');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.source.MapQuest');
goog.require('ol.source.Vector');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
@@ -24,11 +26,9 @@ var map = new ol.Map({
})
});
// The features are not added to a regular vector layer/source,
// but to a feature overlay which holds a collection of features.
// This collection is passed to the modify and also the draw
// interaction, so that both can add or modify features.
var featureOverlay = new ol.FeatureOverlay({
var features = new ol.Collection();
var featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector({features: features}),
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
@@ -48,7 +48,7 @@ var featureOverlay = new ol.FeatureOverlay({
featureOverlay.setMap(map);
var modify = new ol.interaction.Modify({
features: featureOverlay.getFeatures(),
features: features,
// the SHIFT key must be pressed to delete vertices, so
// that new vertices can be drawn at the same position
// of existing vertices
@@ -62,7 +62,7 @@ map.addInteraction(modify);
var draw; // global so we can remove it later
function addInteraction() {
draw = new ol.interaction.Draw({
features: featureOverlay.getFeatures(),
features: features,
type: /** @type {ol.geom.GeometryType} */ (typeSelect.value)
});
map.addInteraction(draw);

View File

@@ -1,12 +1,13 @@
goog.require('ol.Feature');
goog.require('ol.FeatureOverlay');
goog.require('ol.Geolocation');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.control');
goog.require('ol.geom.Point');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.source.OSM');
goog.require('ol.source.Vector');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
@@ -85,7 +86,9 @@ geolocation.on('change:position', function() {
new ol.geom.Point(coordinates) : null);
});
var featuresOverlay = new ol.FeatureOverlay({
var featuresOverlay = new ol.layer.Vector({
map: map,
features: [accuracyFeature, positionFeature]
source: new ol.source.Vector({
features: [accuracyFeature, positionFeature]
})
});

View File

@@ -1,5 +1,4 @@
goog.require('ol.Feature');
goog.require('ol.FeatureOverlay');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.geom.Point');
@@ -102,12 +101,14 @@ for (i = 0; i < featureCount; i += 30) {
overlayFeatures.push(clone);
}
var featureOverlay = new ol.FeatureOverlay({
var featureOverlay = new ol.layer.Vector({
map: map,
source: new ol.source.Vector({
features: overlayFeatures
}),
style: new ol.style.Style({
image: icons[iconCount - 1]
}),
features: overlayFeatures
})
});
map.on('click', function(evt) {

View File

@@ -1,6 +1,5 @@
goog.require('ol.Attribution');
goog.require('ol.Feature');
goog.require('ol.FeatureOverlay');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.control');
@@ -180,7 +179,8 @@ map.on('postcompose', function(evt) {
}
});
var featureOverlay = new ol.FeatureOverlay({
var featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector(),
map: map,
style: new ol.style.Style({
image: new ol.style.Circle({
@@ -203,7 +203,7 @@ document.getElementById('time').addEventListener('input', function() {
if (highlight === undefined) {
highlight = new ol.Feature(new ol.geom.Point(coordinate));
feature.set('highlight', highlight);
featureOverlay.addFeature(highlight);
featureOverlay.getSource().addFeature(highlight);
} else {
highlight.getGeometry().setCoordinates(coordinate);
}

View File

@@ -1,9 +1,9 @@
goog.require('ol.FeatureOverlay');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.format.GeoJSON');
goog.require('ol.layer.Image');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.source.ImageVector');
goog.require('ol.source.MapQuest');
goog.require('ol.source.Vector');
@@ -42,7 +42,8 @@ var map = new ol.Map({
})
});
var featureOverlay = new ol.FeatureOverlay({
var featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector(),
map: map,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
@@ -71,10 +72,10 @@ var displayFeatureInfo = function(pixel) {
if (feature !== highlight) {
if (highlight) {
featureOverlay.removeFeature(highlight);
featureOverlay.getSource().removeFeature(highlight);
}
if (feature) {
featureOverlay.addFeature(feature);
featureOverlay.getSource().addFeature(feature);
}
highlight = feature;
}

View File

@@ -24,7 +24,9 @@ var vector = new ol.layer.Vector({
})
});
var select = new ol.interaction.Select();
var select = new ol.interaction.Select({
wrapX: false
});
var modify = new ol.interaction.Modify({
features: select.getFeatures()

View File

@@ -1,4 +1,3 @@
goog.require('ol.FeatureOverlay');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.format.GeoJSON');
@@ -60,7 +59,8 @@ var map = new ol.Map({
var highlightStyleCache = {};
var featureOverlay = new ol.FeatureOverlay({
var featureOverlay = new ol.layer.Vector({
source: new ol.source.Vector(),
map: map,
style: function(feature, resolution) {
var text = resolution < 5000 ? feature.get('name') : '';
@@ -106,10 +106,10 @@ var displayFeatureInfo = function(pixel) {
if (feature !== highlight) {
if (highlight) {
featureOverlay.removeFeature(highlight);
featureOverlay.getSource().removeFeature(highlight);
}
if (feature) {
featureOverlay.addFeature(feature);
featureOverlay.getSource().addFeature(feature);
}
highlight = feature;
}