[GIS] OpenLayers 3 – Google Maps switch, problem with style

featuresgoogle mapsopenlayers

I use ol3-google-maps and when I switch layer from standard OSM to Google then styles are broken. I have defined styles but Google use self for example: points in OSM are yellow but when is google-map point shows like Google marker.

Google layers:

var GM = new olgm.layer.Google({
         mapTypeId: 'hybrid',
         title: 'Google',
         type: 'base'
    });

var olGM = new olgm.OLGoogleMaps({map: map,mapIconOptions: {useCanvas: true }}); 
    olGM.activate();
    manager['main_google'].setVisible(false);

Style:

function pointStyleFunction(feature) {
return new ol.style.Style({
    fill: new ol.style.Fill({
    color: 'rgba(255, 255, 255, 0.2)'
    }),
    stroke: new ol.style.Stroke({
    color: '#ffcc33',
    width: 2
    }),
    image: new ol.style.Circle({
        radius: 7,
        fill: new ol.style.Fill({
        color: '#ffcc33'
        })
    }),
    text: createTextStyle(feature)
  });
}

Layers of features:

var layer_ambon = new ol.layer.Vector({
                source: new ol.source.Vector({ features: new ol.Collection((new ol.format.GeoJSON()).readFeatures(map_info['layers'][3])) })
            });

Standard OL map:

map = new ol.Map({
        interactions: olgm.interaction.defaults(),
        target: olMapDiv,
        layers: [
          OSM,  
          GM,
        ],
        controls: ol.control.defaults().extend([
            new ol.control.ScaleLine()
        ]),
        view: view
    });

Best Answer

Style Functions in OpenLayers are not compatible with ol3-google-maps. See the LIMITATION.

As an alternative, you can either:

  1. manually set the style directly within each feature instead, which would avoid the use of the style function
  2. keep the style function and turn off the vectors watcher in ol3-google-maps. See the ol3gm Watch Options example to see how to turn it off.

Here's a snippet for (2):

var olGM = new olgm.OLGoogleMaps({
  map: map,
  watch: {
    'vector': false
  }
});
olGM.activate();