Comments (7)
I don't think there is a "global" event that raises for any layer.
You would need to watch observables on each individual layer. Also, this will trigger if anything changes the visibility; not just mouse clicks on legend checkbox toggles.
e.g.
var myLayer = RAMP.mapById('rv-app-0').layers.allLayers[0];
myLayer.visibilityChanged.subscribe(e => {
console.log('I am visible? : ' + e); // e is boolean
});
You can use the MapAPI.layers.layerAdded
observable if you need to watch for new layers coming in (to add listeners to their observable).
from fgpv-vpgf.
Thanks. Is there a way to check when RAMP
has been added to the DOM?
from fgpv-vpgf.
RAMP.mapAdded.subscribe(map => { do stuff })
but to be honest I rarely use this and am not sure how the timing works. If a map is generated in the page lifetime it should show up on this observable. For maps that are hard-defined in the DOM (e.g. a div with is="rv-map"
), I'm not sure...it might exist before that observable. Might need to test it on your end, but I would hope it fires lol. If not you can check the .mapInstances
array for pre-existing maps before listening.
from fgpv-vpgf.
I came up with this solution but it is firing before RAMP has been added to the DOM
function remove(arr, value) {
return arr.filter(function (ele) {
return ele != value;
});
}
$(".rv-list-item-controls").click(function (checkbox) {
let selectedLayers = [];
RAMP.mapById("rv-app-0").layers.allLayers.forEach(function (e) {
if (e.visibility) {
selectedLayers.push(e.id);
} else {
remove(selectedLayers, e.id);
}
});
localStorage.setItem("selectedLayers", selectedLayers);
});
if (localStorage.getItem("selectedLayers") != null) {
let loadLayers = localStorage.getItem("selectedLayers").split(",");
if (typeof loadLayers != "undefined" && loadLayers.length > 0) {
loadLayers.forEach(function (e) {
RAMP.mapById("rv-app-0").layers.getLayersById(e)[0].visibility = true;
});
}
}
EDIT: Culprit line RAMP.mapById("rv-app-0").layers.getLayersById(e)[0].visibility = true;
from fgpv-vpgf.
I have very little context in what you're trying to do, but am guessing the bottom part
RAMP.mapById("rv-app-0").layers.getLayersById(e)[0].visibility = true;
runs too early. Is this script running before the ramp script? If so, put it after. If it's already after, you may need to do some waiting until your instance appears. I.e. waiting for the instance, and possibly waiting for layers. I don't know how your site starts up or the requirements so you'll need to do what works for you. I love setTimeouts
for glorious busywait hacks.
Alternately, if your setup can work with it, you could consider trying to leverage the bookmarking module.
See this sample page
- This line, notice
data-rv-wait="true"
is set. This does a block to allow any potential bookmark to be consumed before finishing the load. - This line shows how to set a bookmark (you would have stored it in your local storage). Notice it uses the "legacy API"
RV
, you'll need the legacy script if you're not already using it. Also note if you had nothing in your local storage, you'd need to call this with empty parameter to unblock the instance. - This line shows how to grab a bookmark of the current state. So whenever you want to save your state, you'd do this and put in local storage instead of the
document
call this sample does.
The bookmark will track visibility, opacity, map extent, etc. So might not be what you want.
The sample page here isn't great since has no layers but you could add a dummy layer for local testing if you wanted (corresponding config is here)
Might be more trouble than it's worth, up to you.
from fgpv-vpgf.
Also it only works with layers that are in your config file. If you have random layers getting dropped in via API calls, don't bother with the bookmark module
from fgpv-vpgf.
I ended up manipulating the config file using some custom code and it worked. The project I am on uses React so it adds some complexity. Thanks for your guidance
from fgpv-vpgf.
Related Issues (20)
- Broken Safari check in Export HOT 1
- Feature Layer Initial Filter is not working
- Documentation: broken links for samples, sample configs HOT 2
- User selections HOT 4
- Map loads in certain browsers HOT 6
- Basemap accepted endpoints HOT 9
- layers showing as radio button instead of checkboxes in grouped layers HOT 1
- WCAG: Implement alt tags in Help documents HOT 4
- Remove HTTP URL trickery HOT 1
- RAMP load times HOT 15
- RAMP adding/removing scripts to the html document HOT 5
- Update file-saver HOT 1
- Demo Build process is broken HOT 1
- Reporting a vulnerability HOT 1
- Symbol failures when default symbol has no label HOT 1
- Services with reordered indexes fail
- The datatable causes infinite queries for map service having Data operation disabled HOT 1
- Fullscreen service bug with multiple ramps
- Grid accessibility on Storylines
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fgpv-vpgf.