OpenLayers 2.1x load WMS layers from PHP

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I have been looking to see if it's possible to add WMS layers from a PHP script. I'd like to do this to move a lot of the code from the client side to the server.

Currently I load the layers in the initialize function with:

/*Declare layers + properties:*/
var layer1= new OpenLayers.Layer.WMS("Layer1", "/geoserver/wms", {layers: 'Workspace:Layer1', styles: '', srs: 'EPSG:27700', format: format, tiled: 'true',transparent: 'TRUE'}, {tileSize: new OpenLayers.Size(540,640), buffer: 0, displayOutsideMaxExtent: true,isBaseLayer: false,visibility : false,transitionEffect: 'none' } );
var layer2= new OpenLayers.Layer.WMS("Layer2", "/geoserver/wms", {layers: 'Workspace:Layer2', styles: '', srs: 'EPSG:27700', format: format, tiled: 'true',transparent: 'TRUE'}, {tileSize: new OpenLayers.Size(540,640), buffer: 0, displayOutsideMaxExtent: true,isBaseLayer: false,visibility : false,transitionEffect: 'none' } );

/*Add layers to layer array*/
layerArray.push({key : 'layer1', lyr : layer1});
layerArray.push({key : 'layer2', lyr : layer2});

/*Add layer to the map*/
for(var n =0; n<layerArray.length; n++)
{
    obj = layerArray[n];
    map.addLayer(obj.lyr);
}

Is there a way to move the layer information and layer array population to PHP so the only code in the initialize function is the code to add the layers to the map?

** Edit **

More details as requested:

I have been asked to produce a site that contains an OpenLayers 2.1x map that utilises vector drawing, select, measure, geolocate, CQL filters and all mapping layers are stored in GeoServer 2.33 and are accessed using WMS. GeoServer is run on the web server.

I have completed all of this using JavaScript to populate the layer names (as indicated above) and sketchSymbolizer properties etc. I also use JavaScript to create any calculations and CQL filters.

The client who has asked for the site has expressed concerns with the ease of taking the JavaScript and replicating the site, plus he feels large calculation in JavaScript are affecting the performance of older smart phones.

I have moved calculations to PHP and got them running smoothly (if not a little slower for fast machines, but adding a loader and everyone is happy again), but there is still a want to move all of the OpenLayers initialize items into PHP as well. I can not get OpenLayers to initialize, I have used the code below to create an array, but feel I'm missing the point completely.


php

$al = array(
array
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

Yes, it is possible. But what is the source of layer list? If that information is stored in a some kind of database, then PHP will be the right way. But when you want to load all layers from WMS server/workspace, then AJAX call to GetCapabilities or GeoServer API will be better. Last but not least, if layer list is immutable, this could be done entirely in JavaScript. If you provide some details about the layer list source, I'll post some code examples.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community