add labels to Station map
This commit is contained in:
parent
03cc6a475b
commit
f0ea809813
2 changed files with 38 additions and 12 deletions
|
@ -12,9 +12,19 @@
|
|||
floatval($station['latitude'])
|
||||
);
|
||||
$coordinates[] = $coordinate;
|
||||
// Marker
|
||||
$features[] = array(
|
||||
'type' => 'Feature',
|
||||
'id' => $station['id'],
|
||||
'geometry' => array(
|
||||
'type' => 'Point',
|
||||
'coordinates' => $coordinate
|
||||
)
|
||||
);
|
||||
// Label
|
||||
$features[] = array(
|
||||
'type' => 'Feature',
|
||||
'id' => $station['id'].'-label',
|
||||
'properties' => array(
|
||||
'name' => $station['title'],
|
||||
),
|
||||
|
|
|
@ -171,20 +171,36 @@
|
|||
var styles = [];
|
||||
var geometry = feature.getGeometry();
|
||||
if(geometry instanceof ol.geom.Point) {
|
||||
// Point styling
|
||||
styles.push(
|
||||
new ol.style.Style({
|
||||
text: new ol.style.Text({
|
||||
//text: '\uf041',
|
||||
text: '\uf276',
|
||||
font: 'normal 28px FontAwesome',
|
||||
textBaseline: 'Bottom',
|
||||
fill: new ol.style.Fill({
|
||||
color: '#0F373C'
|
||||
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
|
||||
styles.push(
|
||||
new ol.style.Style({
|
||||
text: new ol.style.Text({
|
||||
//text: '\uf041',
|
||||
text: '\uf276',
|
||||
font: 'normal 28px FontAwesome',
|
||||
textBaseline: 'Bottom',
|
||||
fill: new ol.style.Fill({
|
||||
color: '#0F373C'
|
||||
})
|
||||
})
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
else if(geometry instanceof ol.geom.LineString) {
|
||||
// Line styling
|
||||
|
|
Loading…
Add table
Reference in a new issue