1

I'm trying to use a specific marker with my GeoJSON files. They don't show up despite my readings and Firebug.

Can anyone help ?

var map = new OpenLayers.Map('map');    
var emprise_style = new OpenLayers.Symbolizer.Point({
    externalGraphic: '../symbol/marker.png'
    });

var empriseStyleMap = new OpenLayers.StyleMap({'default': emprise_style});
var emprise_layer = new OpenLayers.Layer.Vector("GeoJSON", {
        projection: "EPSG:3857",
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.HTTP({
            url: "emprise.geojson",
            format: new OpenLayers.Format.GeoJSON()
            }),
        styleMap: empriseStyleMap
    });
map.addLayer(emprise_layer)

1 Answer 1

2

Try Style instead of Symbolizer

var emprise_style = new OpenLayers.Style({
        externalGraphic:"${symbol}"
    },{
    context:{
          symbol:function(feature){

         /*
           with this u can use different symbols for different data values in the "feature" e.g. 
           if feature has property school and hospital

          if (feature.property == 'school') 
          {
              return '../symbol/school_marker'; 
           }
          else if (feature.property == 'hospital'){
                return '../symbol/hospital_marker';
          }
          */


          return '../symbol/marker.png';
       }    
    }
    });
2
  • thx.i m a beginner in openlayers and i d like to learn step by step. Your answer is a bit too complicated for now. I only want a unique symbol..and that s already a challenge for me !
    – Leehan
    Jun 16, 2014 at 14:32
  • if you want unique symbol you can directly use externalGraphic:'../symbol/marker.png' and remove the context part....
    – poshan
    Jun 17, 2014 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.