Skip to content

Commit

Permalink
Merge pull request 3liz#4025 from nboisteault/ol8map-ontop
Browse files Browse the repository at this point in the history
Refactor locatelayer to highlightlayer in OpenLayers 8
  • Loading branch information
nboisteault authored Dec 21, 2023
2 parents 6be6622 + a9bf13c commit 125c857
Show file tree
Hide file tree
Showing 20 changed files with 1,091 additions and 816 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ lizmap/www/assets/js/filter.js.map
lizmap/www/assets/js/map.js
lizmap/www/assets/js/map.js.map
lizmap/www/assets/js/map.js.LICENSE.txt
lizmap/www/assets/js/search.js
lizmap/www/assets/js/search.js.map
lizmap/www/assets/js/switcher-layers-actions.js
lizmap/www/assets/js/switcher-layers-actions.js.map
lizmap/www/assets/js/timemanager.js
Expand Down
2 changes: 0 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ build:
- lizmap/www/assets/js/filter.js.map
- lizmap/www/assets/js/map.js
- lizmap/www/assets/js/map.js.map
- lizmap/www/assets/js/search.js
- lizmap/www/assets/js/search.js.map
- lizmap/www/assets/js/switcher-layers-actions.js
- lizmap/www/assets/js/switcher-layers-actions.js.map
- lizmap/www/assets/js/timemanager.js
Expand Down
8 changes: 3 additions & 5 deletions assets/src/components/MousePosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ export default class MousePosition extends HTMLElement {

mainLizmap.center = lonlatInputInMapProj;
// Display point
const centerPoint = new OpenLayers.Geometry.Point(lonlatInputInMapProj[0], lonlatInputInMapProj[1]);
const locateLayer = mainLizmap.lizmap3.map.getLayersByName('locatelayer')[0];
locateLayer.removeAllFeatures();
locateLayer.addFeatures(new OpenLayers.Feature.Vector(centerPoint));
const featureAsWKT = `POINT(${lonlatInputInMapProj[0]} ${lonlatInputInMapProj[1]})`;
mainLizmap.baseLayersMap.setHighlightFeatures(featureAsWKT,"wkt", mainLizmap.projection);
}
}

_removeCenterPoint() {
mainLizmap.lizmap3.map.getLayersByName('locatelayer')[0].removeAllFeatures();
mainLizmap.baseLayersMap.clearHighlightFeatures();
}

/**
Expand Down
10 changes: 3 additions & 7 deletions assets/src/legacy/atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@
});
}


/**
*
* @param feature
Expand Down Expand Up @@ -547,11 +546,8 @@
}

// Draw feature geometry
var getLayer = lizMap.map.getLayersByName('locatelayer');
if (lizAtlasConfig.drawFeatureGeom && getLayer.length > 0) {
const alayer = getLayer[0];
alayer.destroyFeatures();
alayer.addFeatures([f]);
if (lizAtlasConfig.drawFeatureGeom) {
lizMap.mainLizmap.baseLayersMap.setHighlightFeatures(feature,"geojson");
}

// Display popup
Expand Down Expand Up @@ -614,7 +610,7 @@

// Deactivate highlight
if (lizAtlasConfig.drawFeatureGeom) {
lizMap.clearDrawLayer('locatelayer');
lizMap.mainLizmap.baseLayersMap.clearHighlightFeatures();
}

// Deactivate filter
Expand Down
2 changes: 1 addition & 1 deletion assets/src/legacy/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ var lizEdition = function() {
launchEditionOfParent();
} else {
editionLayer.clear();
lizMap.clearDrawLayer('locatelayer');
lizMap.mainLizmap.baseLayersMap.clearHighlightFeatures();
// trigger edition form closed
lizMap.events.triggerEvent(
'lizmapeditionformclosed'
Expand Down
11 changes: 3 additions & 8 deletions assets/src/legacy/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1087,20 +1087,15 @@ var lizLayerFilterTool = function () {

}


// Removes the getFeatureInfo geometry
/**
*
* Removes the getFeatureInfo geometry
*/
function removeFeatureInfoGeometry() {
var layer = lizMap.map.getLayersByName('locatelayer');
if (layer.length == 1)
layer[0].destroyFeatures();
lizMap.mainLizmap.baseLayersMap.clearHighlightFeatures();
}

// Adapt the size of the dock
/**
*
* Adapt the size of the dock
*/
function adaptLayerFilterSize() {
lizMap.events.on({
Expand Down
130 changes: 31 additions & 99 deletions assets/src/legacy/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,8 @@ window.lizMap = function() {
$('div.locate-layer select').hide();
$('span.custom-combobox').show();
}

}


/**
* PRIVATE function: updateContentSize
* update the content size
Expand Down Expand Up @@ -1191,8 +1189,8 @@ window.lizMap = function() {
* @param aName
*/
function zoomToLocateFeature(aName) {
// clean locate layer
clearDrawLayer('locatelayer');
// clear highlight layer
lizMap.mainLizmap.baseLayersMap.clearHighlightFeatures();

// get locate by layer val
var locate = config.locateByLayer[aName];
Expand All @@ -1219,28 +1217,21 @@ window.lizMap = function() {
feat.geometry.transform(proj, map.getProjection());
// Show geometry if asked
if (locate.displayGeom == 'True') {
var layer = map.getLayersByName('locatelayer')[0];
if( typeof layer === 'undefined' )
return;
var getFeatureUrlData = getVectorLayerWfsUrl( aName, null, null, null );
getFeatureUrlData['options']['PROPERTYNAME'] = ['geometry',locate.fieldName].join(',');
getFeatureUrlData['options']['FEATUREID'] = val;
// Get data
$.post( getFeatureUrlData['url'], getFeatureUrlData['options'], function(data) {
if ( !data.features )
if ( !data.features ){
data = JSON.parse(data);
if( data.features.length != 0) {
feat = format.read(data.features[0])[0];
feat.geometry.transform(proj, map.getProjection());
}
layer.addFeatures([feat]);
lizMap.mainLizmap.baseLayersMap.setHighlightFeatures(data.features[0], "geojson");
}).fail(function(){
layer.addFeatures([feat]);
lizMap.mainLizmap.baseLayersMap.setHighlightFeatures(feat, "geojson");
});
}
//zoom to extent
// zoom to extent
map.zoomToExtent(feat.geometry.getBounds());

}

var fid = val.split('.')[1];
Expand Down Expand Up @@ -1611,16 +1602,6 @@ window.lizMap = function() {
locateContent.push(html);
}
$('#locate .menu-content').html(locateContent.join('<hr/>'));
map.addLayer(new OpenLayers.Layer.Vector('locatelayer',{
styleMap: new OpenLayers.StyleMap({
pointRadius: 6,
fill: false,
stroke: true,
strokeWidth: 3,
strokeColor: 'yellow',
strokeOpacity: 0.8
})
}));

var featureTypes = getVectorLayerFeatureTypes();
if (featureTypes.length == 0 ){
Expand Down Expand Up @@ -1692,7 +1673,7 @@ window.lizMap = function() {
getLocateFeature(lname);
}
$('.btn-locate-clear').click(function() {
clearDrawLayer('locatelayer');
lizMap.mainLizmap.baseLayersMap.clearHighlightFeatures();
$('#locate select').val('-1');
$('div.locate-layer span > input').val('');

Expand Down Expand Up @@ -1956,8 +1937,8 @@ window.lizMap = function() {
$('#overview-box').show();
}

// clean locate layer
clearDrawLayer('locatelayer');
// clear highlight layer
lizMap.mainLizmap.baseLayersMap.clearHighlightFeatures();
return false;
}
);
Expand Down Expand Up @@ -2000,49 +1981,17 @@ window.lizMap = function() {
* @param containerId
*/
function addGeometryFeatureInfo( popup, containerId ) {
// clean locate layer
clearDrawLayer('locatelayer');
var layer = map.getLayersByName('locatelayer')[0];
if( typeof layer === 'undefined' )
return;

// build selector
var selector = 'div.lizmapPopupContent div.lizmapPopupDiv > input.lizmap-popup-layer-feature-geometry';
if ( containerId )
// Build selector
let selector = 'div.lizmapPopupContent div.lizmapPopupDiv > input.lizmap-popup-layer-feature-geometry';
if ( containerId ){
selector = '#'+ containerId +' '+ selector;
// get geometries and crs
var geometries = [];
$(selector).each(function(){
var self = $(this);
var val = self.val();
if ( val == '' )
return;
var crs = self.parent().find('input.lizmap-popup-layer-feature-crs').val();
if ( crs == '' )
return;
var fid = self.parent().find('input.lizmap-popup-layer-feature-id').val();
var minx = self.parent().find('input.lizmap-popup-layer-feature-bbox-minx').val();
var miny = self.parent().find('input.lizmap-popup-layer-feature-bbox-miny').val();
var maxx = self.parent().find('input.lizmap-popup-layer-feature-bbox-maxx').val();
var maxy = self.parent().find('input.lizmap-popup-layer-feature-bbox-maxy').val();
geometries.push( { fid: fid, geom: val, crs: crs, bbox:[minx,miny,maxx,maxy] } );
});

// load proj and build features from popup
var projLoaded = [];
for ( var i=0, len=geometries.length; i<len; i++ ) {
loadProjDefinition(geometries[i].crs, function( aProj ) {
projLoaded.push( aProj );
if ( projLoaded.length == geometries.length ) {
var features = [];
for (const geomInfo of geometries) {
var geometry = OpenLayers.Geometry.fromWKT( geomInfo.geom );
geometry.transform(geomInfo.crs, map.getProjection());
features.push( new OpenLayers.Feature.Vector( geometry ) );
}
layer.addFeatures( features );
}
});
}
// Highlight geometries
const geometriesWKT = [];
document.querySelectorAll(selector).forEach(element => geometriesWKT.push(element.value));
if (geometriesWKT.length) {
const geometryCollectionWKT = `GEOMETRYCOLLECTION(${geometriesWKT.join()})`;
lizMap.mainLizmap.baseLayersMap.setHighlightFeatures(geometryCollectionWKT, "wkt");
}
}

Expand Down Expand Up @@ -2385,8 +2334,8 @@ window.lizMap = function() {
addDock(popupContainerId, 'Popup', config.options.popupLocation, pcontent, 'icon-comment');
$('#button-popupcontent').click(function(){
if($(this).parent().hasClass('active')) {
// clean locate layer
clearDrawLayer('locatelayer');
// clear highlight layer
lizMap.mainLizmap.baseLayersMap.clearHighlightFeatures();
// remove information
$('#popupcontent div.menu-content').html('<div class="lizmapPopupContent"><h4>'+lizDict['popup.msg.start']+'</h4></div>');
}
Expand Down Expand Up @@ -4591,23 +4540,23 @@ window.lizMap = function() {
const wmsCapaData = responses[2].value;
const wmtsCapaData = responses[3].value;
const wfsCapaData = responses[4].value;
let featuresExtent = responses[5].value?.features?.[0]?.bbox;
let startupFeatures = responses[5].value?.features;

if(featuresExtent){
for (const feature of startupFeatures) {
featuresExtent = extend(featuresExtent, feature.bbox);
}
}

self.events.triggerEvent("configsloaded", {
initialConfig: config,
wmsCapabilities: wmsCapaData,
wmtsCapabilities: wmtsCapaData,
wfsCapabilities: wfsCapaData,
startupFeatures: responses[5].value,
});

let featuresExtent = responses[5].value?.features?.[0]?.bbox;
let features = responses[5].value?.features;

if(featuresExtent){
for (const feature of features) {
featuresExtent = extend(featuresExtent, feature.bbox);
}
}


getFeatureInfo = responses[6].value;

const domparser = new DOMParser();
Expand Down Expand Up @@ -4727,26 +4676,9 @@ window.lizMap = function() {

// initialize the map
// Set map extent depending on options
var verifyingVisibility = true;
var hrefParam = OpenLayers.Util.getParameters(window.location.href);
if (!map.getCenter()) {
const zoomToClosest = window.location.hash.substring(1).split('|')[0].split(',').length === 4;
map.zoomToExtent(map.initialExtent, zoomToClosest);
if(featuresExtent){
var format = new OpenLayers.Format.GeoJSON({
ignoreExtraDims: true
});
var locatelayer = map.getLayersByName('locatelayer')[0];
for (const feature of features) {
if( feature.geometry != null){
var feat = format.read(feature)[0];
feat.geometry.transform('EPSG:4326', map.getProjection());
locatelayer.addFeatures([feat]);
locatelayer.setVisibility(true);
}
}
}
verifyingVisibility = false;
}

updateContentSize();
Expand Down
Loading

0 comments on commit 125c857

Please sign in to comment.