3

Still a little new to QGIS and Openlayers. How would you display QGIS's "Map Tips" into OpenLayers? I am currently using QGIS 2.18 and have the latest update in Openlayers. In QGIS, I have created a display in Map Tips showing a county's information when you hover over the county. Now need display the "Map Tips" into openlayers.

Now I know you can create map pop ups in OpenLayers but thinking that involves alot of code and wanted to see if it is possible that we can do it in QGIS.

OpenLayers basically takes images that get render by QGIS and display them in the map. I have applied the "Map Tips" within the outline layer and can display it in QGIS. I assume that with QGIS, it can render and create the image with the "Map Tips" inside an image. What I need it to do is whenever someone hovers over the county name or the county's area within the map, the "Map Tips" display will pop up and show the user information. I feel that there has to be a way to display the "Map Tips" in OpenLayers.

Here is part of the code from OpenLayers to pull up that particular layer:

<script>
     var projection = new ol.proj.Projection({
            code: 'EPSG:3857',
            extent: [-11822316, 4304590, -9430259, 6360040]
     });

    var  extent = [-11822316, 4304590, -9430259, 6360040];

 var outline_layer = new ol.layer.Image({
        extent: extent,
        label: 'outline_layer',
        visible: true,
         source: new ol.source.ImageWMS({
                url: '/map/qgis_mapserv.fcgi?MAP=mapping.qgs&',
                crossOrigin: 'anonymous',                                           
                params: {
                    'LAYERS': 'Outlines',
                    'FORMAT': 'image/png'
                },
            serverType: 'qgis',                                         
        })
    });
var map = new ol.Map({
    controls: ol.control.defaults().extend([
     new ol.control.ScaleLine()
]),
    layers: [ background_layer,
        outline_layer],
    target: 'map',
    view: new ol.View({
        projection: projection,
            center: [-10597609, 5335488],
            extent: extent,
            zoom: 1.8
    })
});

var changeLayer = function changeLayer(ev) {
    var val = $(this).val();
    var checked = $(this).is(':checked');
    map.getLayers().forEach(function (layer) {
        if (layer.get('label') === val) {
        layer.setVisible(checked);                                              
        } else {
            layer.setVisible(false);                                                                    
            outline_layer.setVisible(true); 
            jurisdiction_names.setVisible(true);
        }
    });

    $('input:checkbox').not($(this)).each(function () {
        $(this).attr('checked', false);                                             
    });
};

$('input').each(function () {
    $(this).on('change', changeLayer);
});

Is there a way to display QGIS "Map Tips" in OpenLayers?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.