4

I am new to leaflet & its geojson features.

I am trying to test leaflet's functionalities and have built a map and its layer:

var map = new L.map('map', {scrollWheelZoom:true, doubleClickZoom:true, boxZoom:true, zoomControl:true});
var osmTiles = new L.TileLayer('http://localhost/googleapi/images/image1/tiles/{z}_{x}_{y}.png', {
maxZoom: 7,     minZoom: 3
}).addTo(map);   

Now i want to draw a second layer (geoJson) upon it with a marker, so following the tutorila (cloudmate):

var geojsonLayer = new L.GeoJSON();
var geojsonFeature = {
"type": "Feature",
"properties": {
    "name": "Coors Field",
    "amenity": "Baseball Stadium",
    "popupContent": "This is where the Rockies play!"
},
"geometry": {
    "type": "Point",
    "coordinates": [83.06877, -156.35742]
}
};
geojsonLayer.addData(geojsonFeature);

I am testing in my local PC (have not installed node + built leaflet) so maybe i am missing something.

2

You have to add the geojsonLayer to your leaflet map like you did with your tile layer with .addTo(map)

  • thanks! i have added geojson layer to map but the problem was wrong coordinates, since geojson uses inverse sequence for declaring coordinates (???) than leaflet... So the points did exist but i could not locate them. – thanili Sep 11 '12 at 13:52
  • I'm fairly new myself and what I do is create all of my features and attributes with QGIS and then save as a geojson file, (EPSG:4326). Havent had a problem yet. – geomajor56 Sep 11 '12 at 14:22
  • Try setting attribute tms: true – Scro Nov 10 '12 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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