Giter VIP home page Giter VIP logo

ol-layerswitcher's Introduction

OpenLayers LayerSwitcher

Grouped layer list control for an OpenLayer map.

To be shown in the LayerSwitcher layers should have a title property; base layers should have a type property set to base. Group layers (LayerGroup) can be used to visually group layers together; a group with a fold property set to either open or close will be displayed with a toggle.

See API documentation and Examples for usage.

Compatible with OpenLayers version 3, 4, 5 and 6 (see note in Install - Parcel, Webpack etc. regarding installing the appropriate version of ol-layerswitcher for OpenLayers).

Examples

The examples demonstrate usage and can be viewed online thanks to raw.githack.com:

  • Basic usage
    • Create a layer switcher control. Each layer to be displayed in the layer switcher has a title property as does each Group; each base map layer has a type: 'base' property. See the comments in examples/layerswitcher.js for other layer/ group options including combine and fold.
  • Add layer
    • Add a layer to an existing layer group after the layer switcher has been added to the map.
  • Scrolling
    • Makes the panel scroll vertically, the height of the layer switcher is controlled by setting the max-height style (see examples/scroll.css) and it's position relative to the bottom of the map (see the .layer-switcher.shown selector in dist/ol-layerswitcher.css).
  • Side bar
  • Collapse groups
    • Shows the effect of setting the fold property of a Group to allow the group to be collapsed.
  • Selectable Groups
    • Demonstrates setting the groupSelectStyle option which determines if groups have a checkbox and how toggling a groups visibility affects it's children. The demo includes the ability to change the groupSelectStyle to easily see the effect of the different values.
  • Bundling with ol package (Browserify, Parcel, Webpack...)
  • Activate panel with click
    • Shows setting activationMode: 'click' (default is 'mouseover'). When using this mode the control's button persists in the panel - use collapseLabel to set its text (default is collapseLabel: '»', see the comments in examples/layerswitcher.js for other examples). The close button is positioned to the left of the panel, to move it to the right add the following to your CSS:
.layer-switcher.shown.layer-switcher-activation-mode-click {
  padding-right: 34px;
}
.layer-switcher.shown.layer-switcher-activation-mode-click > button {
  right: 0;
  border-left: 0;
}
  • Start with panel active

    • Example with the layer switcher starting open using startActive: true. Here shown in combination with `activationMode: 'click' which, while not required, is probably the most common scenario.
  • Multiple maps

    • Demonstrates creating two independent maps each with a layer switcher control.
  • To use the layer switcher with the ol package and a module bundler such as Browserify, Parcel, Webpack, TypeScript etc. see ol-layerswitcher-examples.

The source for all examples can be found in examples.

Changelog

See CHANGELOG for details of changes in each release.

Install

Browser

JS

Load ol-layerswitcher.js after OpenLayers. The layerswitcher control is available as LayerSwitcher or ol.control.LayerSwitcher.

<script src="https://unpkg.com/[email protected]"></script>

CSS

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/ol-layerswitcher.css" />

Parcel, Rollup, Webpack, TypeScript etc.

NPM package: ol-layerswitcher.

JS

Install the package via npm

npm install ol-layerswitcher --save

⚠️ If you're using the ol package prior to v5 you'll need to install [email protected].

CSS

The CSS file ol-layerswitcher.css can be found in ./node_modules/ol-layerswitcher/dist

To use the layerswitcher with the ol package and a module bundler such as Parcel, Webpack etc. see ol-layerswitcher-examples.

TypeScript type definition

TypeScript types are shipped with the project in the dist directory and should be automatically used in a TypeScript project. Interfaces are provided for LayerSwitcher Options as well as extend interfaces for BaseLayer and LayerGroup Options that include the LayerSwitcher specific properties such as title, combine etc.

These interfaces can be imported into your project and used to cast object literals passed to layer or group constructors:

import 'ol/ol.css';
import 'ol-layerswitcher/dist/ol-layerswitcher.css';

import Map from 'ol/Map';
import View from 'ol/View';
import LayerGroup from 'ol/layer/Group';
import LayerTile from 'ol/layer/Tile';
import SourceOSM from 'ol/source/OSM';
import SourceStamen from 'ol/source/Stamen';

import LayerSwitcher from 'ol-layerswitcher';
import { BaseLayerOptions, GroupLayerOptions } from 'ol-layerswitcher';

const osm = new LayerTile({
  title: 'OSM',
  type: 'base',
  visible: true,
  source: new SourceOSM()
} as BaseLayerOptions);

const watercolor = new LayerTile({
  title: 'Water color',
  type: 'base',
  visible: false,
  source: new SourceStamen({
    layer: 'watercolor'
  })
} as BaseLayerOptions);

const baseMaps = new LayerGroup({
  title: 'Base maps',
  layers: [osm, watercolor]
} as GroupLayerOptions);

const map = new Map({
  target: 'map',
  layers: [baseMaps]
});

const layerSwitcher = new LayerSwitcher({
  reverse: true,
  groupSelectStyle: 'group'
});
map.addControl(layerSwitcher);

See BaseLayerOptions and GroupLayerOptions.

API

Table of Contents

LayerSwitcher

Extends ol/control/Control~Control

OpenLayers LayerSwitcher Control, displays a list of layers and groups associated with a map which have a title property.

To be shown in the LayerSwitcher panel layers must have a title property; base map layers should have a type property set to base. Group layers (LayerGroup) can be used to visually group layers together; a group with a fold property set to either 'open' or 'close' will be displayed with a toggle.

See BaseLayerOptions for a full list of LayerSwitcher properties for layers (TileLayer, ImageLayer, VectorTile etc.) and GroupLayerOptions for group layer (LayerGroup) LayerSwitcher properties.

Layer and group properties can either be set by adding extra properties to their options when they are created or via their set method.

Specify a title for a Layer by adding a title property to it's options object:

var lyr = new ol.layer.Tile({
  // Specify a title property which will be displayed by the layer switcher
  title: 'OpenStreetMap',
  visible: true,
  source: new ol.source.OSM()
});

Alternatively the properties can be set via the set method after a layer has been created:

var lyr = new ol.layer.Tile({
  visible: true,
  source: new ol.source.OSM()
});
// Specify a title property which will be displayed by the layer switcher
lyr.set('title', 'OpenStreetMap');

To create a LayerSwitcher and add it to a map, create a new instance then pass it to the map's addControl method.

var layerSwitcher = new LayerSwitcher({
  reverse: true,
  groupSelectStyle: 'group'
});
map.addControl(layerSwitcher);

Parameters

setMap

Set the map instance the control is associated with.

Parameters
  • map Map The map instance.

Returns void

showPanel

Show the layer panel. Fires 'show' event.

Returns void

hidePanel

Hide the layer panel. Fires 'hide' event.

Returns void

renderPanel

Re-draw the layer panel to represent the current state of the layers.

Returns void

renderPanel

[static] - Re-draw the layer panel to represent the current state of the layers.

Parameters
  • map Map The OpenLayers Map instance to render layers for
  • panel HTMLElement The DOM Element into which the layer tree will be rendered
  • options RenderOptions Options for panel, group, and layers

Returns void

isBaseGroup

[static] - Determine if a given layer group contains base layers

Parameters

Returns boolean

getGroupsAndLayers

[static] - Get an Array of all layers and groups displayed by the LayerSwitcher (has a 'title' property) contained by the specified map or layer group; optionally filtering via filterFn

Parameters

Returns Array<BaseLayer>

forEachRecursive

[static] - Call the supplied function for each layer in the passed layer group recursing nested groups.

Parameters

Returns void

uuid

[static] - Generate a UUID Adapted from http://stackoverflow.com/a/2117523/526860

Returns String UUID

LayerSwitcher#show

Event triggered after the panel has been shown. Listen to the event via the on or once methods; for example:

var layerSwitcher = new LayerSwitcher();
map.addControl(layerSwitcher);

layerSwitcher.on('show', (evt) => {
  console.log('show', evt);
});

LayerSwitcher#hide

Event triggered after the panel has been hidden.

Options

Extends ControlOptions, RenderOptions

[interface] - LayerSwitcher Options specified when creating a LayerSwitcher instance, extends RenderOptions and Control Options.

Default values:

{
  activationMode: 'mouseover',
  startActive: false,
  label: ''
  collapseLabel: '\u00BB',
  tipLabel: 'Legend',
  collapseTipLabel: 'Collapse legend',
  groupSelectStyle: 'children',
  reverse: false
}

activationMode

Event to use on the button to collapse or expand the panel. Defaults to "mouseover".

Type: ("mouseover" | "click")

startActive

Whether panel is open when created. Defaults to false.

Type: boolean

label

Text label to use for the button that opens the panel. E.g.: '' (default), '«' or '\u00AB', '+'.

Type: string

collapseLabel

Text label to use for the button that closes the panel. E.g.: '»' (default) or '\u00BB', '-' or '\u2212'. Only used when activationMode: 'mouseover'.

Type: string

tipLabel

The button tooltip when the panel is closed.

Type: string

collapseTipLabel

The button tooltip when the panel is open.

Type: string

RenderOptions

[interface] - LayerSwitcher Render Options as passed to LayerSwitcher constructor as part of Options and static LayerSwitcher.renderPanel

groupSelectStyle

How layers and groups behave when a given layer's visibility is set. See GroupSelectStyle type for possible values.

Type: GroupSelectStyle

reverse

Should the order of layers in the panel be reversed?

Type: boolean

GroupSelectStyle

[type] - How layers and groups behave when a given layer's visibility is set, either:

  • 'none' - groups don't get a checkbox,
  • 'children' (default) groups have a checkbox and affect child visibility or
  • 'group' groups have a checkbox but do not alter child visibility (like QGIS).

Type: ("none" | "children" | "group")

BaseLayerOptions

Extends ol/layer/Base~Options

[interface] - Extended BaseLayer Options interface adding properties used by the LayerSwitcher

title

Title of the layer displayed in the LayerSwitcher panel

Type: string

type

Type of the layer, a layer of type: 'base' is treated as a base map layer by the LayerSwitcher and is displayed with a radio button

Type: "base"

GroupLayerOptions

Extends ol/layer/Group~Options, BaseLayerOptions

[interface] - Extended LayerGroup Options interface adding properties used by the LayerSwitcher.

combine

When true child layers are not shown in the Layer Switcher panel

Type: boolean

fold

Fold state of the group, if set then the group will be displayed with a button to allow the user to show/ hide the child layers.

Type: ("open" | "close")

Tests

To run the tests you'll need to install the dependencies via npm. In the root of the repository run:

npm install

Then run the tests by opening test/index.html in a browser.

License

MIT (c) Matt Walker.

Also see

If you find the layer switcher useful you might also like the ol-popup.

Publishing

npm run build
# Open ./tests/ in browser
# Open examples and manually test
# Determine new version number (check current with `git tag --list`, check npm and GitHub)
# Update version number in `package.json` and `README.md`
# Add entry to CHANGELOG.md
git commit package.json CHANGELOG.md README.md
git tag vX.Y.Z
git push origin master --tags
npm publish

Beta release

npm run build
# Tests/ examples
# Beta version should be X.Y.Z-beta.N
# Update version number in `package.json` and `README.md`
# Add entry to CHANGELOG.md
git commit package.json CHANGELOG.md README.md
git tag vX.Y.Z-beta.N
git push --tags
npm publish --tag beta
# To list all version on npm
npm show ol-layerswitcher versions --json

ol-layerswitcher's People

Contributors

adrelino avatar atgardner avatar francbartoli avatar kpurdon avatar mike-000 avatar mstenta avatar neuwenwolf avatar olivierdalang avatar pksorensen avatar robertorthofer avatar thomasg77 avatar tonimc avatar umbe1987 avatar walkermatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ol-layerswitcher's Issues

get radio button event

Hi there,

I started to playing around with openlayers and your ol3-layerswitcher project.
Please excuse my lack of knowledge regariding js i thought i maybe you could give me an answer.
I created a map where beside some dynamically loaded layers 2 base layers are present.
BingMaps Aerial and openstreetmaps are those. Due to the nature of the Aerial imagery i switch it off depending on the zoomlevel. This brings the situation that the user cannot select the basemap if the zoomlevel does not permit it. So i would need to know how to get an event of the layerswitch button to detect user interaction. Can you give me a hint how to do that with ol3/layerswitcher?
Thank you very much in advance.

Event on group label click

I have some nested layer groups.
I need to make visible all layers in subgroup when i click on group label.
I try to use jquery call $('.layer-switcher li.group>label').click(....); but when I click on label than handler wasn't fired.
What wrong?

Feature overlay

If there is a FeatureOverlay active on a layer (for example to represent a selected element), it will stay visible if the layer is turned off, while it should disappear as well.

repo npm sync?

After running, npm install ol3-layerswitcher, the node_modules/ol3-layerswitcher/package.json reads (only the relevant parts are printed here for brevity),

{
  "dependencies": {
    "openlayers": "~3.17.1"
  },
  "keywords": [
    "openlayers",
    "layerswitcher",
    "ol3"
  ],
  "version": "1.1.2"
}

Looks like the version is up-do-date, but the dependencies aren't in sync with the most recent commits (openlayers still points to 3.x.x and the keyword still says ol3 rather than just plain ol. There are other places with discrepancies, I just listed a few here for example. Is there a way to fix/sync this?

-W

Vertical Scrollbar

If we have a lot of layers the layer control's height is more than that of the map and the layer control cannot be scrolled down. Do you maybe have an example of how this can be achieved?

[feature] Visual hint for maps that are not visible because of min/max resolution

Hi !

It is very common to limit a layer to certain resolutions using their min/max resolution settings.

Layerswitcher doesn't take that into account, so that a layer that's not visible because of min/max resolution setting still appears in the layer list. This is very counter-intuitive.

I think that the layers that are not visible due to min/max resolution should either:

  • A. not be displayed at all
  • B. be grayed-out with a disabled checkbox, eventually with an icon making it obvious why the layer is hidden

I quickly implemented A : https://github.com/olivierdalang/ol3-layerswitcher/tree/show_only_if_visible
It's not finished :

  • there's no option to choose between A or B,
  • I didn't think about how this should work with Base Layers
  • I didn't investigate other types of invisibility (eg. outside of layer's bounds)

Thanks !!

More of a trivial issue..

Hey, I was just wondering if you knew how to set overlays to have a default setting of not being displayed on the map until they are selected, as in they are unchecked by default, if you get me.

I have 4 overlays and they display on top of eachother, I'm new to openlayers and there's not a lot of people I can go to for advice, so I looked at your project and it seems to have what id like here but I'm not sure how you did it!

Use with requirejs

@walkermatt Could you please provide an example on how to load this library using requirejs.
I get undefined object when i try to do so:-
require(["./ol3-layerswitcher"],function(layerSwitcher){ }

When I deselect a Layer, it is only hides the CSS, but the layers is in RAM

Hello,

where should I do layersxxxx.clear()?
For selected layers too? selectedlayers.clear();
So in which function do you hide css, there should be the layers cleaning from the ram,
Becouse if I deselect one layer, and I do Dragbox selection that deselceted layers comes in as selection.

With best regards

Example not working due to mixed SSL content

example fails when rawgit is loaded as https. This is due to trying to load openlayers as http.

Unfortunately OpenLayers is not served as https. So I propose to also host the openlayers css and js code as a copy and use a protocol independent URL in the example..

Google layer with ol3-google-maps doesn't get radio button.

Hi! This issue was posted first here: mapgears/ol3-google-maps#37. But after some thought I concluded that this is perhaps more of an ol3-layerswitcher question? Anyone. here it is:

Has anyone here used ol3-layerswitcher together with ol3-google-maps? For some reason the google layer doesn't show correctly in my layer switcher:

screen shot 2016-01-18 at 15 37 02

Relevant pieces of code:

    var map = new ol.Map({
      target: 'map',
    });

    var googleLayer = new olgm.layer.Google({
      title: 'Kart (Google)',
      type: 'base',
    })
    map.addLayer(googleLayer);

    var shadedBing = new ol.layer.Tile({
      title: 'Kart (Bing)',
      type: 'base',
      source: new ol.source.BingMaps({
        key: bingKey,
        imagerySet: 'Road'
      })
    });
    map.addLayer(shadedBing);

    ...

    map.setView(new ol.View({
        projection: 'EPSG:900913',
        center: ol.proj.transform(
          settings.coords,
          'EPSG:4326',
          'EPSG:900913'
        ),
        zoom: 14
    }));

    var layerSwitcher = new ol.control.LayerSwitcher({});
    map.addControl(layerSwitcher);

    var olGM = new olgm.OLGoogleMaps({map: map});
    olGM.activate();

Any thoughts?

add to custom build

Following the doc on custom builds works ok, until I try to include the layerswitcher.

In my custom.json file, I added:

	"js": [
		"../../ol3-layerswitcher/src/ol3-layerswitcher.js"
	],

and in the exports I added "ol.control.LayerSwitcher".

The compile errors:

ERR! No matching symbol found: ol.control.LayerSwitcher

I tried to add ol3-layerswitcher.js to the extern as well as the js, neither work, I get the same error.

If I dont add "ol.control.LayerSwitcher" to the exports, then it compiles fine, but my browser errors with:

TypeError: ol.control.LayerSwitcher is not a constructor

I'd be grateful for any pointers.

input element id at ol.control.LayerSwitcher.prototype.renderLayer_

Currently generated input element id is mangled by idx parameter:
var lyrId = lyr.get('title').replace(/\s+/g, '-') + '_' + idx;

This doesn't work well is there are 2 maps with the same set of layers: in the 2nd map label.htmlFor will refer to the input element of the 1st map as generated input element id is the same for the both maps.

This makes a funny effect: when you click at the label at the 2nd map it actually switches a layer at the 1st map.

A solution for this issue could look something like this:

var lyrId = lyr.get('title').replace(/\s+/g, '-') + '_' + Math.floor(Math.random() * 1000000);

Internet Explorer problem

It seems that layerswitcher does'nt work in MS Internet Explorer !
Do you confirm it ?

Cheers !
Nino

Exclusive overlay layers

I have overlay layers which need to be mutually exclusives, additionally to some base layers.

There is a solution for plain Openlayers, but I can't get it to work using ol3-layerswitcher.

I also tried setting layer.setVisible(false) to false after a "change:visible" event gets triggered. The problem is that this event gets propagated and on the second run all layers get invisible. I did something like that:

ol.control.LayerSwitcher.forEachRecursive(map, function(l, idx, a) {
  l.on("change:visible", function(e, react) {

    exclusiveOverlays.forEach(function(layer, i) {
      if (e.target.get('title') !== layer.getProperties().title) {
        layer.setVisible(false);
      }
    });
  });
});

Button disappears when mouse over

Hi Matt
As I can see in the example your layerswitcher would exactly full fill my needs.
I implement according your example and the source javascript code of ol3-layerswitcher,js and ol3-layerswitcher.css in my website. My layer definition is according your addlayer,js. I wouldlike to have something similar like 'view the example on RawGit'. Unfortunately I get the button on the map but as soon as I move the mouse over the button, the button disappear and I'm not able to choose one of my defined layer. I guess something is missing but after two days of examination I couldn't find anything wrong.
Could help me or anybody else, or have a hint for me what's missing?
Cheers Guido

Safari not working

the layerswitcher does not work in safari.
The radio button (basemaps) as also the layer selection (check box) can not be changed when the map is accessed using safari browser
I do not own an OS device to locate the error

IIS and Geoserver

i want to access published layers through IIS but am facing the problem with REDIRECTING the URL

my domain on IIS is like this http://maps.icrisat.org
and the layers which i have published using http://localhost:8080/geoserver/wms...

when open my website i will be selecting a link which points to geoserver layers using javascript file in that i will be calling all layers but it is not displaying any layers but it is loading the base map.

someone can help me in this issue

Thanks
Ismail

[feature] save layers visibilities

Hi !

In my application, I want the displayed layers to be saved across pages, so that the user doesn't have to repick all layers he wants to see. I guess it's a pretty common scenario.

I quickly implemented it using cookies, see here :

https://github.com/olivierdalang/ol3-layerswitcher/tree/visbility_in_cookie

It's not finished though :

  • saving should be optional,
  • currently there's no namespacing in the cookie, so that all maps of the same domain will share the same settings (conflicts if layers have the same title),
  • another way to save the state is through the window hash, so that you can copy/paste a link

Get and set actual layer type by ID or so

Hi Matt,

I've successfully implemented your layerswitcher.
However I would like to know how to get and set the actual layer using an ID or something else in order to save the actual layer type. I was not able to find anything. How is that possible?

Second question how can I checkmark automatically the overlay when I using sat view and back by select any other layer. Must be done by using visible but for me is not clear how do I implement it.
Thanks in advance for your feedback...
Cheers Guido

My layer definitions looks as follows:

      mapLayers = [
        new ol.layer.Group({
          title: 'Basemaps',
          layers: [
            new ol.layer.Tile({
              title: 'SatelliteView',
              type: 'base',
              visible: false,
              source: new ol.source.OSM({ url:'//server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}'})
              //source: new ol.source.MapQuest({layer: 'sat'})
            }),
            new ol.layer.Tile({
              title: 'Topographic',
              type: 'base',
              visible: false,
              source: new ol.source.XYZ({attributions:[attribution],url:'//server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}'}),
            }),
            new ol.layer.Tile({
              title: 'EsriRoad',
              type: 'base',
              visible: false,
              source: new ol.source.XYZ({attributions:[attribution],url:'//server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}'}),
            }),
            new ol.layer.Tile({
              title: 'MapquestRoad',
              type: 'base',
              visible: true,
              source: new ol.source.MapQuest({layer: 'osm'}),
              //source: new ol.source.OSM({url:'//{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'}),
            }),
          ],
        }), //End of basemaps
        new ol.layer.Group({
          title: 'Overlays',
          layers: [
            new ol.layer.Tile({
              title: 'Themes',
              visible: false,
              source: new ol.source.XYZ({attributions:[attribution],url:'//server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer/tile/{z}/{y}/{x}'}),
            }),
          ],
        }), //End of overlays
      ]; //End of var mapLayers


Grouping base layers

The traditional way to produce a satellite map with roads in MapQuest is to make a sat layer and a road layer.

I can't seem to group these together in a single entry using layer switcher. Either they appear as independent base layers or the roads would become an optional overlay (which makes the hybrid option redundant along side the satellite layer)

WMS GetFeatureInfo (Tile Layer) in Layerswitcher still ON even after unchecking layer in switcher

Hi Matt,

first of all, thanks a lot for this great LayerSwitcher !
Also, sorry for my english, not my mother tongue...
Last, I'my js skills are VERY limited as I started a few month ago.

I'm loading a wms layer in my project, and I trigger WMS GetFeatureInfo requests on click events (in a popup). It works, but when I uncheck the layer in the swicther, it still triggers the GetFeatureInfo, and opens the popup...

I think I have to add an "if LAYER-X in layerswitcher is ON then..." somewhere, but how can I check if a layer is checked in the layerswitcher?

Thanks again,

Panel not rendering with latest ol version (Version: v3.1.0-pre.2-508-g27b5036)

There appears to be a problem where the layer switcher panel no longer rendering with the latest version of OL3 (Version: v3.1.0-pre.2-508-g27b5036 at the time of writing).

It does render with the version of OL3 packaged with ol3-layerswitcher on github.

The cause of the problem is that the render method added to the ol3-layerswitcher prototype is being overwritten by a render method inherited from elsewhere (presumably ol.control.Control).

A simple workaround is to change the name of the ol.control.LayerSwitcher prototype method from "render" to something else (I used "renderNow"). This worked for me.

Hope this helps.

Scoping issue?

Trying the component in a different code context than the demo, I encounter a scope issue. The switcher fails when you encapsulate all the application code in an IIFE.
To reproduce, in layerswitcher.js, add at the beginning (function() { and at the end })();
Then, try to switch back and forth between the two base layers and you will see the behaviour.
This error happens on Google Chrome 39.0.2171.2 dev on Linux 64.

ol3-layerswitcher.js:62 Uncaught TypeError: undefined is not a function

In Firefox 32.0.3, there is the same behaviour but it fails silently in the Firebug console.

List the layers of a WMS

Hi, is it possible to list the "internal" layers of a WMS configuration to switch them separately on and off?
e.g.

var wmsSource = new ol.source.ImageWMS({
  url: 'http://<wms_server>/geoserver/<namespace>/wms',
  params: {'LAYERS': [ 'Layer_001', 'Layer_002', ... 'Layer_xxx' ]}

var wms = new ol.layer.Image({
  title: 'Basemap',
  type: 'base',
  source: wmsSource 
})

Should create

* Basemap
      * Layer_xxx
      ...
      * Layer_002
      * Layer_001

Collapse layer groups

I like your layerswitcher very much. Would it be possible to collapse/uncollapse the groups of layers to have a more clean panel if I use many layers?

run code on switcer shown event

It's possible add handler to execute some code when switcher panel is shown?
I tried with
$('.layer-switcher').mouseover(function () { setTimeout(function () { console.log('shown'); }, 10); });

but it isn't exactly the same thing

Enable and disable parent layers as well as child layers

I have used ol3-layerswitcher,I wan't to enable parent layer checkbox at that time all child layers checkbox get enable and vise versa.If some child layers are disabled and i enable parent layer then all child layers should be enable.I tried little bit code with html check boxes and JS but my code not working properly and code is too big .Please find this [http://uxo.azurewebsites.net/webmap/Index.html] Thanks

Reverse order of layers.

Hello,

Why is the order of group reverted from its declaration ?

In the example you declare the Base maps group, then the Overlays group, but in the rendered map, it's first the Overlays then the Base maps group that are displayed in that order.

Would it be better to display them in the natural order of their declaration ?

Option displayInLayerSwitcher

Thank you for jumping in to implement a layerswitcher.

Is there any possibility to implement the OL2-Option "displayInLayerSwitcher"? If set to false the Layer is visible but not displayed in the layerswitcher.
Or do I perhaps miss something?

[0]

[deleted]

Add title when hovering legend icon

Hovering the legend icon, I've seen a "missing" (IMO) title attribute tag in the element.
I have a branch with the changes but before submitting, I want to get your opinion.

In the library, I use the same convention tipLabel as in this ol3 source code but without the goog stuff.
My main concern is about using or not the tipLabel option in the example.

Add listener on selected layer

Hi,

First, thank you for your plugin, it's very usefull for my application :).
I'm wondering if it's possible to add a feature getting the selected layer. I'm developping a plugin for drawing on a map and i need to know which layer to draw on it.
Is-it possible to add an eventListener when the user select a layer by radio button and return the selected layer ?
Or I can try to develop it for my personnal use (or not ^^) but i'm not sure to do it in right way.

Thanks

(sorry for my bad english)

Nested groups

Are nested groups supported? Apologies if I've asked this before, but I couldn't see it in the issues.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.