add labels to Station map

This commit is contained in:
oliver 2016-02-02 10:33:17 +01:00
commit f0ea809813
2 changed files with 38 additions and 12 deletions

View file

@ -12,9 +12,19 @@
floatval($station['latitude']) floatval($station['latitude'])
); );
$coordinates[] = $coordinate; $coordinates[] = $coordinate;
// Marker
$features[] = array( $features[] = array(
'type' => 'Feature', 'type' => 'Feature',
'id' => $station['id'], 'id' => $station['id'],
'geometry' => array(
'type' => 'Point',
'coordinates' => $coordinate
)
);
// Label
$features[] = array(
'type' => 'Feature',
'id' => $station['id'].'-label',
'properties' => array( 'properties' => array(
'name' => $station['title'], 'name' => $station['title'],
), ),

View file

@ -171,6 +171,21 @@
var styles = []; var styles = [];
var geometry = feature.getGeometry(); var geometry = feature.getGeometry();
if(geometry instanceof ol.geom.Point) { if(geometry instanceof ol.geom.Point) {
var name = feature.get('name');
if(name) {
// Label styling
styles.push(
new ol.style.Style({
text: new ol.style.Text({
text: name,
textBaseline: 'Bottom',
offsetY: 14,
scale: 1.2
})
})
);
}
else {
// Point styling // Point styling
styles.push( styles.push(
new ol.style.Style({ new ol.style.Style({
@ -186,6 +201,7 @@
}) })
); );
} }
}
else if(geometry instanceof ol.geom.LineString) { else if(geometry instanceof ol.geom.LineString) {
// Line styling // Line styling
styles.push( styles.push(