how to add markers with OpenLayers 3

后端 未结 3 1678
孤独总比滥情好
孤独总比滥情好 2020-12-04 12:42

I\'m trying to add makers on a OpenLayers 3 map.

The only example I have found is this one in the OpenLayers example list.

But the

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 13:26

    var exampleLoc = ol.proj.transform(
        [131.044922, -25.363882], 'EPSG:4326', 'EPSG:3857');
    
    var map = new ol.Map({
      target: 'map',
      renderer: 'canvas',
      view: new ol.View2D({
        projection: 'EPSG:3857',
        zoom: 3,
        center: exampleLoc
      }),
      layers: [
        new ol.layer.Tile({source: new ol.source.MapQuest({layer: 'osm'})})
      ]
    });
    
    map.addOverlay(new ol.Overlay({
      position: exampleLoc,
      element: $('')
          .css({marginTop: '-200%', marginLeft: '-50%', cursor: 'pointer'})
          .tooltip({title: 'Hello, world!', trigger: 'click'})
    }));
    
    map.on('postcompose', function(evt) {
      evt.vectorContext.setFillStrokeStyle(
          new ol.style.Fill({color: 'rgba(255, 0, 0, .1)'}),
          new ol.style.Stroke({color: 'rgba(255, 0, 0, .8)', width: 3}));
      evt.vectorContext.drawCircleGeometry(
          new ol.geom.Circle(exampleLoc, 400000));
    });
    
    var exampleKml = new ol.layer.Vector({
      source: new ol.source.KML({
        projection: 'EPSG:3857',
        url: 'data/example.kml'
      })
    });
    map.addLayer(exampleKml);
    

提交回复
热议问题