Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: show red polygon on 'mouse over' the list #116

Merged
merged 2 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,37 @@ <h2>Content</h2>
style: style
});

var singleFeatureSource = new ol.source.Vector({});

var styleSingleFeature = new ol.style.Style({
stroke : new ol.style.Stroke(
{
color : 'rgba(255, 0, 0, 1)',
width : 3
}),
fill : new ol.style.Fill(
{
color : 'rgba(255, 0, 0, 0.1)'
})
});

var singleFeatureLayer = new ol.layer.Vector({
source: singleFeatureSource,
style: styleSingleFeature
});

function updateSingleFeatureLayer(geometry) {
singleFeatureSource.clear();

if (geometry) {
var json = new ol.format.GeoJSON();
var feature = new ol.Feature({
geometry: json.readGeometry(geometry)
});
singleFeatureSource.addFeature(feature);
}
}

function agencies_selector(checked) {
list_agencies.forEach(function(id){
document.getElementById('id_checkbox_' + id).checked = checked;
Expand Down Expand Up @@ -303,7 +334,8 @@ <h2>Content</h2>
var map = new ol.Map({
layers: [
new ol.layer.Tile({source: new ol.source.OSM()}),
featureLayer],
featureLayer,
singleFeatureLayer],
renderer: 'canvas',
target: 'map',
overlays: [overlay],
Expand Down Expand Up @@ -335,7 +367,11 @@ <h2>Content</h2>
var props = feature.getProperties();

details_innerHTML += '<hr>';
details_innerHTML += '<p><a href="' + props.name + '">' + props.name + '</a>: '
var writer = new ol.format.GeoJSON();
var geoJson = props.geometry ? writer.writeGeometry(props.geometry) : '';
details_innerHTML += '<p onmouseout="updateSingleFeatureLayer()" ';
details_innerHTML += " onmouseover='updateSingleFeatureLayer(" + geoJson + ")'>"; // geoJson contains double quotes
details_innerHTML += '<a href="' + props.name + '">' + props.name + '</a>: '
if( props.area_of_use ) {
details_innerHTML += props.area_of_use + ', ';
}
Expand Down
40 changes: 38 additions & 2 deletions index.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,37 @@ var featureLayer = new ol.layer.Vector({
style: style
});

var singleFeatureSource = new ol.source.Vector({});

var styleSingleFeature = new ol.style.Style({
stroke : new ol.style.Stroke(
{
color : 'rgba(255, 0, 0, 1)',
width : 3
}),
fill : new ol.style.Fill(
{
color : 'rgba(255, 0, 0, 0.1)'
})
});

var singleFeatureLayer = new ol.layer.Vector({
source: singleFeatureSource,
style: styleSingleFeature
});

function updateSingleFeatureLayer(geometry) {
singleFeatureSource.clear();

if (geometry) {
var json = new ol.format.GeoJSON();
var feature = new ol.Feature({
geometry: json.readGeometry(geometry)
});
singleFeatureSource.addFeature(feature);
}
}

function agencies_selector(checked) {
list_agencies.forEach(function(id){
document.getElementById('id_checkbox_' + id).checked = checked;
Expand Down Expand Up @@ -301,7 +332,8 @@ closer.onclick = function() {
var map = new ol.Map({
layers: [
new ol.layer.Tile({source: new ol.source.OSM()}),
featureLayer],
featureLayer,
singleFeatureLayer],
renderer: 'canvas',
target: 'map',
overlays: [overlay],
Expand Down Expand Up @@ -333,7 +365,11 @@ map.on('singleclick', function(evt) {
var props = feature.getProperties();

details_innerHTML += '<hr>';
details_innerHTML += '<p><a href="' + props.name + '">' + props.name + '</a>: '
var writer = new ol.format.GeoJSON();
var geoJson = props.geometry ? writer.writeGeometry(props.geometry) : '';
details_innerHTML += '<p onmouseout="updateSingleFeatureLayer()" ';
details_innerHTML += " onmouseover='updateSingleFeatureLayer(" + geoJson + ")'>"; // geoJson contains double quotes
details_innerHTML += '<a href="' + props.name + '">' + props.name + '</a>: '
if( props.area_of_use ) {
details_innerHTML += props.area_of_use + ', ';
}
Expand Down
Loading