简体   繁体   中英

Unable to display the graticule with OpenLayers 3

This issue is more a javascript problem than an OpenLayer one. I guess...

The sample just work fine with my own WMS server : http://openlayers.org/en/v3.0.0/examples/graticule.html

In my project, the 'map' object is set in the map.js file, loaded in the index.html before the graticule.js file. It displays the map, as expected.

var map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        })
    ],
    target: 'map',
});

Now my very simple code in graticule.js

"use Strict";
var graticule = new ol.Graticule();
graticule.setMap(map);
map.getViewPort().style.cursor = 'crosshair';

Ok now the fun part : I can see the crosshair (SO the map object is ok!), but the setMap(map) just throw an error "TypeError : a is null" in the debug console.

I'm not a Javascript expert so it can be a relatively dumb reason.

Please, help, I'm stuck.

Problem solved.

I used ol.proj.Projection in the view property, but I need to use directly the string projection code :

var view = new ol.View({
    center: center,
    zoom: 6,
    projection: 'EPSG:4326'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM