M
M
Maxim2015-01-23 14:30:30
JavaScript
Maxim, 2015-01-23 14:30:30

How to add a label (point, circle, polygon) in OpenLayers 3?

Maybe I'm stupid, because there is a question . But he seems to be for the second version and tried what was written there, it did not work out.
Give an example or where to read.
Now there is this option:

var lonlat = ol.proj.transform([37.6094, 55.739], 'EPSG:4326', 'EPSG:3857');
  var map = new ol.Map({
    target: 'osm-map',
    layers: [
      new ol.layer.Tile({
        source: new ol.source.XYZ({
          url: 'http://127.0.0.1:8080/osm_tiles/{z}/{x}/{y}.png'
        })
      }),
      new ol.layer.Vector({
        source: new ol.source.Vector({}).addFeature(
          new ol.Feature({
            geometry: new ol.geom.Point(lonlat),
            name: 'Null Island ',
            population: 4000,
            rainfall: 500
          })
        ),
        style: new ol.style.Style({
          image: new ol.style.Circle({
            radius: 20,
            fill: new ol.style.Fill({color: 'red'})
          })
        })
      })
    ],
    view: new ol.View({
      center: lonlat,
      zoom: 4
    })
  });

PS If you offer leaflet , then justify why, except that it's easier to get started.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
DeFacto, 2015-01-27
@Masik

openlayers.org/en/v3.1.1/examples/icon.html
here is an example of a map marker

P
Papa, 2017-08-02
Stifflera @PapaStifflera

1. You have an array in JSON. Accordingly, config should be declared as
2. Handle the error and perhaps you will understand what's wrong.

D
Dasha Tsiklauri, 2017-08-02
@dasha_programmist

You have an array of objects in the file, and you are trying to parse the object
var config []Config = make([]Config)
like that you need to declare

R
ryan12, 2017-09-04
@ryan12

var config []Config = make([]Config)
JSON Formatter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question