function ip_geoloc_openlayers_layers in IP Geolocation Views & Maps 8
Same name and namespace in other branches
- 7 ip_geoloc.openlayers.inc \ip_geoloc_openlayers_layers()
Implements hook_openlayers_layers().
Called via ctools in the heart of openlayers_build_map(). This function has no arguments, so layers are added unconditionally, unless globals are used.
File
- ./
ip_geoloc.openlayers.inc, line 60 - ip_geoloc.openlayers.inc
Code
function ip_geoloc_openlayers_layers() {
$layers = [];
$visitor_layer = new stdClass();
$visitor_layer->api_version = 1;
$visitor_layer->name = IP_GEOLOC_VISITOR_MARKER_LAYER;
$visitor_layer->title = 'Current visitor marker';
$visitor_layer->description = "Layer to mark visitor's current position.";
$visitor_layer->weight = -10;
$visitor_layer->data = [
'isBaselayer' => FALSE,
'layer_type' => 'openlayers_layer_type_raw',
'projection' => [
'EPSG:900913',
],
];
// Add the visitor's location as a single feature in its own layer, so
// that it may be separately styled (eg marker colour) and activated on page
// admin/structure/openlayers/maps/<map-name>/edit.
$location = ip_geoloc_get_visitor_location();
if (!empty($location) && isset($location['longitude'])) {
$longitude = $location['longitude'];
$latitude = $location['latitude'];
$visitor_layer->data['features'][] = [
'attributes' => [
'name' => t('Your retrieved location.'),
],
'wkt' => "POINT({$longitude} {$latitude})",
'projection' => 'EPSG:4326',
];
}
$layers[$visitor_layer->name] = $visitor_layer;
$num_marker_layers = \Drupal::state()
->get('ip_geoloc_num_location_marker_layers', IP_GEOLOC_DEF_NUM_MARKER_LAYERS);
for ($layer = 1; $layer <= $num_marker_layers; $layer++) {
$marker_layer = new stdClass();
$marker_layer->api_version = 1;
$marker_layer->name = IP_GEOLOC_MARKER_LAYER . $layer;
$marker_layer->title = "Location markers #{$layer}";
$marker_layer->description = "Layer to map a view's locations.";
$marker_layer->weight = $visitor_layer->weight + $layer;
$marker_layer->data = [
'isBaselayer' => FALSE,
'layer_type' => 'openlayers_layer_type_raw',
'projection' => [
'EPSG:900913',
],
];
// Features, ie. location markers, are added based on the view output, see
// file ip_geoloc_plugin_style_openlaysers.inc.
$layers[$marker_layer->name] = $marker_layer;
}
// cache_set('ip_geoloc_layer_cache', $layers);.
return $layers;
}