OpenLayers5: hitTolerance doesn't seem to work with WMS layer - javascript

I am new to OpenLayers as I just today tried porting over my map from Leaflet to OL since hitTolerance is exactly what I was looking for. Also, I understand v5 is quite new, so the docs are not completely updated in my experience.
I can't seem to get hitTolerance to work with WMS layers.
I understand that since v5 you can now specify hitTolerance in forEachLayerAtPixel, but I still have to hit the layer pretty accurately for it to be picked up by forEachLayerAtPixel.
I also tried forEachFeatureAtPixel, but that gave me nothing, ever. Does WMS layers have features?
I have tried both with TileLayer/TileWMS and ImageLayer/ImageWMS. Both behave the same. Using forEachLayerAtPixel even with a hitTolerance of 100 I still have to be very precise to hit the layer.
Am I doing something wrong? I don't know if this is a bug, or if hitTolerance simply doesn't work with WMS layers. Any help would be appreciated. Thanks.

The hitTolerance applies to vector data. OL takes your click coordinates and searches for nearby features.
When dealing with WMS, OL has no knowledge of the features, it is just displaying an image. It just sends the click coordinates to the map server, which may or not apply a buffer to it, and return the found features info.
So, for WMS, the hit tolerance is a server setting, not a client one.
For example, here is the corresponding doc for Geoserver.

Related

Redraw map on OpenLayers 6?

I'm trying to redraw the Vector Layer in OpenLayers (version 6.1.1, latest is 6.2.1) but any sort of documentation on it is OpenLayers 3. I've tried translating it myself, but either the redraw just isn't working properly or I'm writing the syntax incorrectly. Does anyone have any idea how to go about this?
I haven't been able to get the icons to even flicker to show that they're updating, never mind getting them to update as the database gets filled up. It's really important that I get the icons on my Vector Layer refreshing so anything and everything helps, thank you!
I think that refresh method of the source should do what you want. Give it a try.
OL API - Vector Source refresh
Credits to #viglino-jean-marc, as of ol v6.6.1 using refresh method of the vector source not working as intended, changed method is what do the job.

Is it possible to add a Leaflet Layer Search

Alright so I've been working on a custom version of leaflet and is currently pretty advanced compared to it's stock counterpart. The problem with it is however that some core functionality isn't required in most custom versions of Leaflet. My problem here is, is it possible to add a search algorithm to the layer control to search for specific layers.
I've tried several plugins that don't immediately search for layers and tried to rewrite them so it works for layers. I've also got the plugin that groups all layers in an expandable group. I'm not the best at google searches but I can't find an answer to this problem anywhere.
Since it's part of police software I can't write any code here without permission, due to the dutch laws (even if it doesn't contain crucial code).
I hope someone can help me with this issue, since it's a huge part of this piece of software. I'll have over 200 layers. They might already be grouped but searching is way nicer and faster in some occasions.
Just post some examples or links below that might work. Thanks for helping in advance!
In your place, I would add all layers to layers-control and leave only the most important ones visible on the map.
I would also add input to the layer-control and searchable in the DOM. I would probably approach this problem in this way.

OpenLayers 3 Vector Layer loses styling when map pans or zooms

UPDATE
I tried adding the files into a Snippet or JSFiddle to make it available to people to edit, but JSFiddle is banned and I cannot upload text files into a Snippet. Unless there's a better way to do it, here's the public repo for the files.
Hi, everyone!
I'm working on switching from OpenLayers 2 to OpenLayers 3 and supplementing my reading of by trying some things out on my own. There's a project that I'm building here that should be fairly simple: take form inputs and use them as parameters for building a vector layer. The interface works as intended, save for one problem.
Whenever I pan the map or zoom it, the vector layer seems to disappear. I can't for the life of me imagine what's going on. Anyone able to help me figure out what I can do to keep the layer in place?
Thanks!
Dheeraj
The answer was in line 77 here. It turns out that for whatever reason, I misunderstood falsiness in JavaScript and my style-builder function was erring on undefined styles. Who knew? The rest of the code works, though!!!
Big thanks to #ahocevar for being willing to help!

Google / Bing Maps Show All Cities

Trying to find a way without zooming in real close to tell Google or Bing maps to show all cities. Bing does a good job for the most part but still when you zoom in it shows a whole different set of cities.
I have a large monitor this map is going to be sitting on and really need it to show more than just the cities it shows on for example zoom level 8 or 9 on Google. Right now I load in roughly 2900 different locations and mark them on the map so I am trying to do it via the API no just going to maps.google.com
Has anyone come up against this issue and found a fix? Did some searching here as well on Google and maybe looking it up wrong but haven't found anyone looking for something like this.
Hi you can do that by using the Image Map Type API by implementing the mapType interface. Please refer to this link and implement the code in the way given in the example, replacing details with your specifications.
Hope this will help!!
I couldnt find either enough information to get "mapType" to work how I was wanting or it just doesnt do it. The goal was to be at lets say a zoom level of 8 and see every city in the US. I couldnt get any of the suggestions to do that.
Here is what I found that allowed me to do it my self though:
http://google-maps-utility-library-v3.googlecode.com/
Basically I put in a transparent marker so it didnt show up then put info boxes with the names. This actually worked really well for me because I can zoom out 100% and still see all the names. Although at that level they would be overlapping being able to zoom in and out a few ticks and still see everything is great.

How can I access, then animate an existing leaflet map polyline using Javascript?

Can anyone suggest how I can access then animate the red polyline here using javascript:
http://gymloop.lukem.co.uk (login: User2/pass2, then select 'Challenges')
I want to animate the polyline from the first marker to the end of the red line (think Indiana jones but without the map moving and NOT using google maps). It needs to be dynamic as different users will have travelled different distances.
I need thew solution to work in FF, IE7+ & Chrome
I am using cloudmade's leaflet maps and am keen to avoid using google maps.
There is further information in my related question at gis.stackexchange
I've checked out your code and it seems you're using the leaflet API to draw the lines. Because of that, I've decided to write a somewhat generic function that animated those kinds of lines. (By the way, I'm confused why that API uses path tags instead of line tags, but I've rolled with it.)
Here's the code: http://jsfiddle.net/mihaibirsan/Wzvre/
I'd like to polish it a bit more, but I wanted to put a foot in the door for that bounty. :D (I'll get back to polishing and post an update in a few hours, once I've done some other work.)
I highly recommend jquery_svg plugin. I've been using it and there are plenty of features, including animation, text on path, user interaction.

Categories