Skip to content

Instantly share code, notes, and snippets.

@pgiraud
Last active May 27, 2016 11:49
Show Gist options
  • Save pgiraud/476aac6a6917ac92212f to your computer and use it in GitHub Desktop.
Save pgiraud/476aac6a6917ac92212f to your computer and use it in GitHub Desktop.
Mobile application - Performance comparison
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>Select features example</title>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.10.1/ol.css" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.11.1/ol.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<style>
html, body {
padding: 0;
margin: 0;
}
html, body, .map {
height: 100%;
width: 100%;
overflow: scroll;
-webkit-overflow-scrolling: touch;
}
.toggle {
position: absolute;
top: 0;
right: 0;
z-index: 2;
}
#table {
position: absolute;
background-color: white;
top: 0;
left: 0;
}
</style>
</head>
<body ng-controller="MainController as ctrl">
<div id="map" class="map" ng-show="ctrl.map">
</div>
<div id="table" class="table" ng-show="!ctrl.map">
<div>
Number of features: {{ ctrl.features.length }}
</div>
<table class="table table-bordered table-striped">
<tr>
<th>
<a href="#" ng-click="ctrl.sortType = 'FID_BBK'; ctrl.sortReverse = !ctrl.sortReverse">
FID_BBK
<span ng-show="ctrl.sortType == 'FID_BBK' && !ctrl.sortReverse" class="fa fa-caret-down"></span>
<span ng-show="ctrl.sortType == 'FID_BBK' && ctrl.sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
<th>
<a href="#" ng-click="ctrl.sortType = 'kategorie'; ctrl.sortReverse = !ctrl.sortReverse">
kategorie
<span ng-show="ctrl.sortType == 'kategorie' && !ctrl.sortReverse" class="fa fa-caret-down"></span>
<span ng-show="ctrl.sortType == 'kategorie' && ctrl.sortReverse" class="fa fa-caret-up"></span>
</a>
</th>
</tr>
<tr ng-repeat="feature in ctrl.features | orderBy:ctrl.sortType:ctrl.sortReverse">
<td>{{ feature.FID_BBK }}</td>
<td>{{ feature.kategorie }}</td>
<td>
<a href="#" ng-click="ctrl.edit(feature.feature)">
Edit
</a>
</td>
</tr>
</table>
</div>
<button ng-click="ctrl.map = !ctrl.map" class="toggle btn btn-default">Toggle map / table</button>
<script src="index.js"></script>
</body>
</html>
angular.module('app', [])
.controller('MainController', function($scope) {
var swissProjection = new ol.proj.Projection({
code: 'EPSG:21781',
extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864],
units: 'm'
});
ol.proj.addProjection(swissProjection);
var geojsonFormat = new ol.format.GeoJSON();
var vector = new ol.layer.Vector({
maxResolution: 0.8,
source: new ol.source.Vector({
url: 'intersect_BBK_Sicherheit_253_Dissolved.geojson',
format: new ol.format.GeoJSON({
defaultDataProjection: swissProjection
})
}),
updateWhileInteracting: true
});
var map = new ol.Map({
layers: [vector],
target: 'map',
view: new ol.View({
projection: swissProjection,
center: [642239, 264010],
zoom: 12
})
});
this.map = true;
vector.once('change', angular.bind(this, function() {
$scope.$apply(angular.bind(this, function() {
var features = [];
vector.getSource().getFeatures().forEach(function(feature) {
features.push({
'FID_BBK': feature.get('FID_BBK'),
'kategorie': feature.get('kategorie'),
'feature': feature
});
});
this.features = features;
}));
}));
var modifyFeatures = new ol.Collection();
var overlayStyle = (function() {
var styles = {};
styles['Polygon'] = [
new ol.style.Style({
fill: new ol.style.Fill({
color: [255, 0, 0, 0.5]
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: [255, 255, 255, 1],
width: 5
})
}),
new ol.style.Style({
stroke: new ol.style.Stroke({
color: [255, 0, 0, 1],
width: 3
})
})
];
styles['MultiPolygon'] = styles['Polygon'];
return function(feature, resolution) {
return styles[feature.getGeometry().getType()];
};
})();
var select = new ol.interaction.Select({
features: modifyFeatures,
style: overlayStyle
});
map.addInteraction(select);
var modify = new ol.interaction.Modify({
features: modifyFeatures
});
map.addInteraction(modify);
this.edit = function(feature) {
this.map = true;
map.getView().fit(feature.getGeometry().getExtent(), map.getSize());
modifyFeatures.clear();
modifyFeatures.push(feature);
};
});
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment