Convert long/lat to pixel x/y on a given picture

后端 未结 10 1318
遇见更好的自我
遇见更好的自我 2020-11-29 15:50

I have a city map of Moscow. We modified a Google Maps image with some artistic elements, but the relation between GPS coordinates and pixels remains the same.

10条回答
  •  心在旅途
    2020-11-29 16:20

    Struggled with this - Have both openstreet map and google street map and wanted to project an external graphic image

    var map = new OpenLayers.Map({
                div:"map-id",
                allOverlays: true
        });
        var osm = new OpenLayers.Layer.OSM("OpenStreeMao");
        var gmap = new OpenLayers.Layer.Google("Google Streets", {visibility: false});
    
        map.addLayers([osm,gmap]);
    
        var vectorLayer = new OpenLayers.Layer.Vector("IconLayer");
    
    
        var lonlatObject = new OpenLayers.LonLat(24.938622,60.170421).transform(
                new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()
        );
        console.log(lonlatObject);
    
        var point = new OpenLayers.Geometry.Point(lonlatObject.lon, lonlatObject.lat);
        console.log(point);
    
        var point2 = new OpenLayers.Geometry.Point(lonlatObject.x, lonlatObject.y);
        console.log(point2);
    
        var feature = new OpenLayers.Feature.Vector(point, null, {
            externalGraphic:  "http://cdn1.iconfinder.com/data/icons/SUPERVISTA/networking/png/72/antenna.png",
            graphicWidth: 72,
            graphicHeight: 72,
            fillOpacity: 1
        });
    
    
        vectorLayer.addFeatures(feature);
    
        map.addLayer(vectorLayer);
    
    
        map.setCenter(
                new OpenLayers.LonLat(24.938622,60.170421).transform(
                new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()
                ),
                12);
    
         map.addControl(new OpenLayers.Control.LayerSwitcher());
    

    http://jsfiddle.net/alexcpn/N9dLN/8/

提交回复
热议问题