Friday, 9 August 2019

javascript - why doesn't show feature on map



this is fiddle Link.Feature doesn't show on map when it has been like this code :


 var featureVectorLayer = new ol.layer.Vector({
source: featureClusterSource,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: 'blue',
width: 2

}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});


But i change source - featureClusterSource to featureVectorSource.it works well but in this time i don't get feature when i click feature on map .


 var featureVectorLayer = new ol.layer.Vector({
source: featureVectorSource,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: 'blue',
width: 2

}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});


How do I show feature on map with featureClusterSource?



Answer



I have updated your code. Take a look here: http://jsfiddle.net/whwjusob/4/


First try to "beautify" your code with tools like http://jsbeautifier.org/ in order that it becomes better readible.


Your problem was that you tried to insert as source a cluster with a vector but no olCollection.


var featureVectorSource = new ol.source.Vector();
var featureClusterSource = new ol.source.Cluster({

source: featureVectorSource,
});

var featureVectorLayer = new ol.layer.Vector({
source: featureClusterSource,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: 'blue',
width: 2
}),

image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});

I changed it to this and now it works:



var features = new ol.Collection();

var featureSource = new ol.source.Vector({
features: features
});

var featureVectorLayer = new ol.layer.Vector({
source: featureSource,
style: new ol.style.Style({
fill: new ol.style.Fill({

color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: 'blue',
width: 2
}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'

})
})
})
});

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...