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.
Related
I don't see much mention of Cartagen on stackoverflow, so please point me somewhere else if there is a better forum for this question. I am using Cartagen JavaScript library to render a map in the browser. I want to place a location pin on the map. I figure there must be an easy way to do this but I haven't been able to find it in the documentation or code.
I found a way to place a map-pin. I used User.set_loc() to set the location of the default User. Then I used User.mark() to mark that location. I changed the code in User.mark() from drawing a circle for the mark, to using ctx.drawImage() to put my .png of a map-pin on to the map. I might be able to make other pins if I make other instances of User.
This use of User.mark() did not create an object that will be automatically be used on every redraw of the map. For that I think I might have to use something like the User.add_node() and User.toggle_way_drawing() whereby a node is created, tagged with "user_submited", and put on the Geohash.objects array. The Geohash.objects array is used by Gartagen.draw() to add user-submitted objects to the Cartagen.feature_queue which are then rendered on the map.
But I haven't totally figured out the use of User.add_node() yet, so instead I added code to Cartagen.draw() to call User.set_loc() and User.mark() every time the map map is redrawn.
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.
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!
I'm really stuck on this one!
I'm using the WP Tiles plugin (http://wp-tiles.com/) to display custom post types for a new Wordpress project. Everything works fine EXCEPT that the tiles are displayed as squares. HOWEVER, my graphic designer wants the tiles to display as rectangles (see this for an example: http://greensenseweb.info/wptilesproblem.jpg).
There's been no reply from the plugin developer, so I guess I'm on my own on this one. I've already delved into the plugin and have seen it uses Pixellab's tiles.js (http://thinkpixellab.com/tilesjs/).
Unfortunately, my javascript is average at the best of times! How can I adjust the plugin or tiles.js to give me rectangles instead of squares?
Thanks in advance for any help!
Did you ever figure it out? I'm having the same problem.
I've been trying to use a jQuery workaround like this:
jQuery('.wp-tiles-tile').height((jQuery('.wp-tiles-tile').width())*0.8);
but obviously it only works for a static page, as soon as you resize the window its not working anymore (plus its not really a clean solution).
I am working on a project that makes use of a map engine from some private company that I can't mention here.
The system used to be in JQuery, and we recently made some considerable modifications, and the system is now implemented in AngularJS.
On the left side of the screen, we have a slidebar displaying items.
On the right side of the screen, we have the map.
My issue is that when I load the page, the map does not display properly, and the inside overlay is quite small. I have checked their sizes but they are correct.
However, when I resize the window manually, or open the Element Inspector from G. Chrome, the map then gets displayed completely.
I have attempted to redraw the clusterLayer, resize the map, resize the div of the map, but nothing seems to be working.
I found this post Google map does not display properly, it could have solved my problem, but I don't have any power on how the map gets loaded.
Thanks
I had a similar problem with ol3 in conjunction with angular. My workaround was to add:
$(document).ready(function () {map.updateSize()});
With map being my ol3 map object. In this case I did not use the openlayers directive from angular. Which, by the way, when used did not have the displaying problems.
Maybe that helps.
I've had somewhat a similar problem and none of the solutions provided worked for me. So I used timeOut function like this and it worked:
setTimeout(function() {
$scope.$apply(function(){
map.updateSize();
})
});