想出了一個單一的解決方案,並忘了發佈。這使您可以在同一個視圖中使用具有多個數據疊加層的單個OpenLayers地圖塊創建單個視圖,並根據URL設置活動視圖。這種方法的好處在於,對所有顯示內容填充一個字段的更改,並且只需要執行一次即可更改地圖的樣式,行爲等。這簡化了人們的維護和更改。
這是什麼工作: 1.創建你的OpenLayers地圖,圖層定義等,你通常會。 2.使用格式創建新視圖:OpenLayers地圖。像平常一樣配置它。 3.在OpenLayers Map視圖中,爲每個來源添加新的OpenLayers數據覆蓋顯示。 4.編輯OpenLayers地圖。在覆蓋圖層下,爲每個新的數據覆蓋檢查啓用和切換器。在我的情況下,激活的複選框都未選中。 5.實現hook_openlayers_map_preprocess_alter()。這是我的看起來像
function mymoduleortheme_openlayers_map_preprocess_alter(&$map = array()) {
//$displayLayer['URL param'] = "map_data_overlay_machine_name";
$displayLayer = array();
$displayLayer['first-page'] = "openlayers_maps_openlayers_first_page_data";
$displayLayer['another-page'] = "openlayers_maps_openlayers_another_page_data";
$currentURI = array();
$currentURI = explode("/", $_SERVER['REQUEST_URI']);
foreach ($map['layer_switcher'] as $idx => $val) {
//Map data found, activate the correct
if (isset($currentURI[2]) && isset($displayLayer[$currentURI[2]]) && $idx == $displayLayer[$currentURI[2]]) {
$map['layer_activated'][$displayLayer[$currentURI[2]]] = $displayLayer[$currentURI[2]];
}
else
$map['layer_switcher'][$idx] = 0;
}
}
可能有改進的餘地,但它的工作和訣竅。切換臺不在本網站使用,所以它只是CSS'd了。