question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a simple method for adding a marker to a map

See original GitHub issue

Objective: Currently, it is fairly hard to add a simple marker for a point coordinate to an OL map.

The most simple take on this, I can find goes like:

var layer = new ol.layer.Vector({
  source: new ol.source.Vector({
    features: [new ol.Feature({
      geometry: new ol.geom.Point(ol.proj.fromLonLat([6.937, 50.926]))})]})});
 map.addLayer(layer);

This is obviously quite some things to learn for beginners who just want to try to do a quick “hello world” in openlayers.

The leaflet equivalent for example looks like this:

var marker = L.marker([50.926, 6.937]).addTo(map);

possible solution: Create a method/function like the marker function in leaflet to wrap all the complexity, shown in the example above, to make adding a marker to a map more simple.

From experience I can tell, that beginners chose leaflet over openlayers mostly because of the (unnecessary) complexity for basic things like adding a marker to a map in openlayers.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mike-000commented, Aug 12, 2019

I don’t think it would be useful in real world situations as developers would need to style markers to suit their applications (as in this example https://openlayers.org/en/master/examples/icon-color.html). A downside of greater flexibility is it needs slightly more code, but anyone attempting to use any mapping library should know enough javascript to put code they use repeatedly into a function. Maybe the example should be revised to reflect that? https://codepen.io/mike-000/pen/QeJZKX

1reaction
Siedlerchrcommented, Oct 28, 2019

Have you looked at ol-ext? http://viglino.github.io/ol-ext/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding a Map with a Marker | Maps SDK for Android
This tutorial shows you how to add a Google map to your Android app. The map includes a marker, also called a pin,...
Read more >
6 Ways to Add a Marker in Google Maps - wikiHow
1. Open Google Maps. Tap the Google Maps app icon, which resembles a red location marker on a road map. This will open...
Read more >
How to Add Custom Marker to Google Maps in Android?
For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New >...
Read more >
Adding a Map with a marker on Android - YouTube
Have you ever wanted to add a marker or a pin to your Map to point out a specific location? Developer Relations Engineer...
Read more >
How to add Markers on maps [Google Maps Course #2]
We will learn about markers in #Google # Maps . Now, let's move on how to create markers on google maps and customise...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found